From 3c42579af9edf267f9a32eb6528bce56a3854e7c Mon Sep 17 00:00:00 2001 From: annalee <150648636+a-n-n-a-l-e-e@users.noreply.github.com> Date: Sat, 16 Mar 2024 03:11:52 +0000 Subject: [PATCH] warp-terminal: don't use nix-prefetch-url in update.sh use fetchurl to calculate hash in update.sh to workaround a bug in nix-prefetch-url. nix-prefetch-url seems to be uncompressing and then calculating the hash when downloading the new warp-terminal. this results in hash mismatch errors as fetchurl calculates the hash using the compressed archive. --- pkgs/by-name/wa/warp-terminal/update.sh | 30 ++++++++++++++++++------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/pkgs/by-name/wa/warp-terminal/update.sh b/pkgs/by-name/wa/warp-terminal/update.sh index d60e0f1f5aa9..1918f34db87e 100755 --- a/pkgs/by-name/wa/warp-terminal/update.sh +++ b/pkgs/by-name/wa/warp-terminal/update.sh @@ -1,5 +1,5 @@ #!/usr/bin/env nix-shell -#!nix-shell -i bash -p curl jq moreutils nix-prefetch +#!nix-shell -i bash -p cacert curl jq nix moreutils --pure #shellcheck shell=bash set -eu -o pipefail @@ -7,6 +7,7 @@ dirname="$(dirname "$0")" err() { echo "$*" >&2 + exit 1 } json_get() { @@ -31,7 +32,6 @@ resolve_url() { ;; *) err "Unexpected download type: $1" - exit 1 ;; esac url="https://app.warp.dev/download?package=${pkg}" @@ -40,7 +40,7 @@ resolve_url() { url=$(curl -s -o /dev/null -w '%{redirect_url}' "${url}") [[ ${url} != *.${sfx} ]] || break done - ((i < max_redirects)) || { err "too many redirects"; exit 1; } + ((i < max_redirects)) || { err "too many redirects"; } echo "${url}" } @@ -48,13 +48,27 @@ get_version() { echo "$1" | grep -oP -m 1 '(?<=/v)[\d.\w]+(?=/)' } +# nix-prefect-url seems to be uncompressing the archive then taking the hash +# so just get the hash from fetchurl +sri_get() { + local ouput sri + output=$(nix-build --expr \ + 'with import {}; + fetchurl { + url = "'"$1"'"; + }' 2>&1 || true) + sri=$(echo "$output" | awk '/^\s+got:\s+/{ print $2 }') + [[ -z "$sri" ]] && err "$output" + echo "$sri" +} + + for sys in darwin linux; do url=$(resolve_url ${sys}) version=$(get_version "${url}") - if [[ ${version} != "$(json_get ".${sys}.version")" ]]; - then - sri=$(nix hash to-sri --type sha256 "$(nix-prefetch-url --type sha256 "${url}")") - json_set ".${sys}.version" "${version}" - json_set ".${sys}.hash" "${sri}" + if [[ ${version} != "$(json_get ".${sys}.version")" ]]; then + sri=$(sri_get "${url}") + json_set ".${sys}.version" "${version}" + json_set ".${sys}.hash" "${sri}" fi done