element-{desktop,web-unwrapped}: {fix,modernize} update script (#407741)

authored by Arne Keller and committed by GitHub 635be603 312fbc61

+28 -33
+28 -33
pkgs/by-name/el/element-desktop/update.sh
··· 1 1 #!/usr/bin/env nix-shell 2 - #!nix-shell -i bash -p nix wget prefetch-yarn-deps nix-prefetch-github jq 2 + #!nix-shell -i bash -p nix coreutils prefetch-yarn-deps jq curl 3 3 4 4 if [ "$#" -gt 1 ] || [[ "$1" == -* ]]; then 5 5 echo "Regenerates packaging data for the element packages." ··· 12 12 set -euo pipefail 13 13 14 14 if [ -z "$version" ]; then 15 - version="$(wget -q -O- "https://api.github.com/repos/element-hq/element-desktop/releases?per_page=1" | jq -r '.[0].tag_name')" 15 + version="$(curl -fsSL "https://api.github.com/repos/element-hq/element-desktop/releases/latest" | jq -r '.tag_name')" 16 16 fi 17 17 18 18 # strip leading "v" 19 19 version="${version#v}" 20 - 21 - # Element Web 22 - web_src="https://raw.githubusercontent.com/element-hq/element-web/v$version" 23 - web_src_hash=$(nix-prefetch-github element-hq element-web --rev v${version} | jq -r .hash) 24 20 25 21 cd "$(dirname "${BASH_SOURCE[0]}")" || exit 1 26 22 27 - web_tmpdir=$(mktemp -d) 28 - trap 'rm -rf "$web_tmpdir"' EXIT 23 + nixflags=( 24 + --extra-experimental-features 25 + "nix-command flakes" 26 + ) 29 27 30 - pushd $web_tmpdir 31 - wget -q "$web_src/yarn.lock" 32 - web_yarn_hash=$(prefetch-yarn-deps yarn.lock) 33 - popd 28 + # HACK: prefetch-yarn-deps hashes may output extra clutter on stdout (!) so 29 + # we'll need to get the last line, last word 30 + fixupHash() { 31 + local sorta_yarn_hash="$(tail -n1 <<< "$1")" 32 + local almost_yarn_hash="${sorta_yarn_hash##* }" 33 + local yarn_hash="$(nix "${nixflags[@]}" hash convert --hash-algo sha256 "$almost_yarn_hash")" 34 34 35 - # Element Desktop 36 - desktop_src="https://raw.githubusercontent.com/element-hq/element-desktop/v$version" 37 - desktop_src_hash=$(nix-prefetch-github element-hq element-desktop --rev v${version} | jq -r .hash) 35 + printf "%s" "$yarn_hash" 36 + } 38 37 39 - desktop_tmpdir=$(mktemp -d) 40 - trap 'rm -rf "$desktop_tmpdir"' EXIT 38 + getHashes() { 39 + variant="$1" 40 + output="$2" 41 41 42 - pushd $desktop_tmpdir 43 - wget -q "$desktop_src/yarn.lock" 44 - desktop_yarn_hash=$(prefetch-yarn-deps yarn.lock) 45 - popd 42 + local url="github:element-hq/element-$variant/v$version" 43 + local src="$(nix "${nixflags[@]}" flake prefetch --json "$url")" 44 + local src_hash="$(jq -r ".hash" <<< "$src")" 45 + local src_path="$(jq -r ".storePath" <<< "$src")" 46 + local yarn_hash="$(fixupHash "$(prefetch-yarn-deps "$src_path/yarn.lock")")" 46 47 47 - cat > ../element-web-unwrapped/element-web-pin.nix << EOF 48 + cat > "$output" << EOF 48 49 { 49 50 "version" = "$version"; 50 51 "hashes" = { 51 - "webSrcHash" = "$web_src_hash"; 52 - "webYarnHash" = "$web_yarn_hash"; 52 + "${variant}SrcHash" = "$src_hash"; 53 + "${variant}YarnHash" = "$yarn_hash"; 53 54 }; 54 55 } 55 56 EOF 57 + } 56 58 57 - cat > element-desktop-pin.nix << EOF 58 - { 59 - "version" = "$version"; 60 - "hashes" = { 61 - "desktopSrcHash" = "$desktop_src_hash"; 62 - "desktopYarnHash" = "$desktop_yarn_hash"; 63 - }; 64 - } 65 - EOF 59 + getHashes web ../element-web-unwrapped/element-web-pin.nix 60 + getHashes desktop element-desktop-pin.nix