warp-terminal: added passthru update script

This commit is contained in:
imad.nyc 2024-03-02 20:47:40 -05:00
parent 662820bc48
commit aa9b78da89
3 changed files with 79 additions and 6 deletions

View File

@ -17,13 +17,15 @@
let
pname = "warp-terminal";
version = "0.2024.02.20.08.01.stable_01";
versions = lib.importJSON ./versions.json;
passthru.updateScript = ./update.sh;
linux = stdenv.mkDerivation (finalAttrs: {
inherit pname version meta;
inherit pname meta passthru;
inherit (versions.linux) version;
src = fetchurl {
inherit (versions.linux) hash;
url = "https://releases.warp.dev/stable/v${finalAttrs.version}/warp-terminal-v${finalAttrs.version}-1-x86_64.pkg.tar.zst";
hash = "sha256-L8alnqSE4crrDozRfPaAAMkLc+5+8d9XBKd5ddsxmD0=";
};
sourceRoot = ".";
@ -65,10 +67,11 @@ linux = stdenv.mkDerivation (finalAttrs: {
});
darwin = stdenvNoCC.mkDerivation (finalAttrs: {
inherit pname version meta;
inherit pname meta passthru;
inherit (versions.darwin) version;
src = fetchurl {
inherit (versions.darwin) hash;
url = "https://releases.warp.dev/stable/v${finalAttrs.version}/Warp.dmg";
hash = "sha256-tFtoD8URMFfJ3HRkyKStuDStFkoRIV97y9kV4pbDPro=";
};
sourceRoot = ".";
@ -90,7 +93,7 @@ meta = with lib; {
homepage = "https://www.warp.dev";
license = licenses.unfree;
sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
maintainers = with maintainers; [ emilytrau Enzime ];
maintainers = with maintainers; [ emilytrau Enzime imadnyc ];
platforms = platforms.darwin ++ [ "x86_64-linux" ];
};

View File

@ -0,0 +1,60 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p curl jq moreutils nix-prefetch
#shellcheck shell=bash
set -eu -o pipefail
dirname="$(dirname "$0")"
err() {
echo "$*" >&2
}
json_get() {
jq -r "$1" < "$dirname/versions.json"
}
json_set() {
jq --arg x "$2" "$1 = \$x" < "$dirname/versions.json" | sponge "$dirname/versions.json"
}
resolve_url() {
local pkg sfx url
local -i i max_redirects
case "$1" in
darwin)
pkg=macos
sfx=dmg
;;
linux)
pkg=pacman
sfx=pkg.tar.zst
;;
*)
err "Unexpected download type: $1"
exit 1
;;
esac
url="https://app.warp.dev/download?package=${pkg}"
((max_redirects = 15))
for ((i = 0; i < max_redirects; i++)); do
url=$(curl -s -o /dev/null -w '%{redirect_url}' "${url}")
[[ ${url} != *.${sfx} ]] || break
done
((i < max_redirects)) || { err "too many redirects"; exit 1; }
echo "${url}"
}
get_version() {
echo "$1" | grep -oP -m 1 '(?<=/v)[\d.\w]+(?=/)'
}
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}"
fi
done

View File

@ -0,0 +1,10 @@
{
"darwin" : {
"hash" : "sha256-tFtoD8URMFfJ3HRkyKStuDStFkoRIV97y9kV4pbDPro=",
"version" : "0.2024.02.20.08.01.stable_01"
},
"linux" : {
"hash" : "sha256-L8alnqSE4crrDozRfPaAAMkLc+5+8d9XBKd5ddsxmD0=",
"version" : "0.2024.02.20.08.01.stable_01"
}
}