Unverified Commit 34de1a91 authored by a-n-n-a-l-e-e's avatar a-n-n-a-l-e-e Committed by GitHub
Browse files

Merge pull request #292928 from imadnyc/warp-terminal-initial-linux

warp-terminal: added passthru update script
parents bbc8b74b aa9b78da
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -8231,6 +8231,13 @@
    github = "ilyakooo0";
    githubId = 6209627;
  };
  imadnyc = {
    email = "me@imad.nyc";
    github = "imadnyc";
    githubId = 113966166;
    name = "Abdullah Imad";
    matrix = "@dre:imad.nyc";
  };
  imalison = {
    email = "IvanMalison@gmail.com";
    github = "colonelpanic8";
+9 −6
Original line number Diff line number Diff line
@@ -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" ];
};

+60 −0
Original line number Diff line number Diff line
#!/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
+10 −0
Original line number Diff line number Diff line
{
  "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"
  }
}