From e8a2671a3e1a1ad71e9cdf79311ca0acf649088d Mon Sep 17 00:00:00 2001 From: Joseph Hanson Date: Sun, 30 Jun 2024 22:49:28 -0500 Subject: [PATCH 1/4] Add overlay to control the versions myself. --- nixos/modules/nixos/system/systempackages.nix | 11 ++- nixos/overlays/default.nix | 11 ++- nixos/overlays/warp-terminal/config.nix | 15 ++++ nixos/overlays/warp-terminal/update.sh | 75 +++++++++++++++++++ nixos/overlays/warp-terminal/versions.json | 10 +++ .../overlays/warp-terminal/warp-terminal.nix | 13 ++++ nixos/profiles/hw-legion-15arh05h.nix | 3 +- 7 files changed, 128 insertions(+), 10 deletions(-) create mode 100644 nixos/overlays/warp-terminal/config.nix create mode 100755 nixos/overlays/warp-terminal/update.sh create mode 100644 nixos/overlays/warp-terminal/versions.json create mode 100644 nixos/overlays/warp-terminal/warp-terminal.nix diff --git a/nixos/modules/nixos/system/systempackages.nix b/nixos/modules/nixos/system/systempackages.nix index bfa6f37..ba05893 100644 --- a/nixos/modules/nixos/system/systempackages.nix +++ b/nixos/modules/nixos/system/systempackages.nix @@ -5,12 +5,11 @@ let in { options.mySystem.system = { - packages = mkOption - { - type = with types; listOf package; - description = "List of system level package installs"; - default = [ ]; - }; + packages = mkOption { + type = with types; listOf package; + description = "List of system level package installs"; + default = [ ]; + }; }; # System packages deployed globally. # This is NixOS so lets keep this liiight? diff --git a/nixos/overlays/default.nix b/nixos/overlays/default.nix index 8d4634d..88e52b1 100644 --- a/nixos/overlays/default.nix +++ b/nixos/overlays/default.nix @@ -1,8 +1,13 @@ -{ inputs -, ... -}: +{ inputs, ... }: +let + warpTerminal = import ./warp-terminal/warp-terminal.nix { + inherit (inputs.nixpkgs) lib; + }; +in { nur = inputs.nur.overlay; + warp-terminal = warpTerminal; + # The unstable nixpkgs set (declared in the flake inputs) will # be accessible through 'pkgs.unstable' # great idea if I wasn't using unstable as my base. diff --git a/nixos/overlays/warp-terminal/config.nix b/nixos/overlays/warp-terminal/config.nix new file mode 100644 index 0000000..f6baea5 --- /dev/null +++ b/nixos/overlays/warp-terminal/config.nix @@ -0,0 +1,15 @@ +{ lib, ... }: +let + versions = lib.importJSON ./versions.json; +in +{ + packageOverrides = pkgs: { + warp-terminal = pkgs.warp-terminal.override { + version = "0.2024.06.25.08.02.stable_01"; + src = lib.fetchurl { + hash = "sha256-Fc48bZzFBw9p636Mr8R+W/d1B3kIcOAu/Gd17nbzNfI="; + url = "https://releases.warp.dev/stable/v0.2024.06.25.08.02.stable_01/warp-terminal-v0.2024.06.25.08.02.stable_01-1-x86_64.pkg.tar.zst"; + }; + }; + }; +} diff --git a/nixos/overlays/warp-terminal/update.sh b/nixos/overlays/warp-terminal/update.sh new file mode 100755 index 0000000..d1dcb06 --- /dev/null +++ b/nixos/overlays/warp-terminal/update.sh @@ -0,0 +1,75 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i bash -p cacert curl jq nix moreutils --pure +#shellcheck shell=bash +set -eu -o pipefail + +cd "$(dirname "$0")" +nixpkgs=$(nix-instantiate --eval -E '' --impure) + +err() { + echo "$*" >&2 + exit 1 +} + +json_get() { + jq -r "$1" < "./versions.json" +} + +json_set() { + jq --arg x "$2" "$1 = \$x" < "./versions.json" | sponge "./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" + ;; + 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"; } + echo "${url}" +} + +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 $nixpkgs {}; + 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=$(sri_get "${url}") + json_set ".${sys}.version" "${version}" + json_set ".${sys}.hash" "${sri}" + fi +done \ No newline at end of file diff --git a/nixos/overlays/warp-terminal/versions.json b/nixos/overlays/warp-terminal/versions.json new file mode 100644 index 0000000..1890475 --- /dev/null +++ b/nixos/overlays/warp-terminal/versions.json @@ -0,0 +1,10 @@ +{ + "darwin": { + "hash": "sha256-vogQAVbtiw2/U3oJrTj8SUexkEsEfYvmGq50nzy5aYo=", + "version": "0.2024.06.25.08.02.stable_01" + }, + "linux": { + "hash": "sha256-Fc48bZzFBw9p636Mr8R+W/d1B3kIcOAu/Gd17nbzNfI=", + "version": "0.2024.06.25.08.02.stable_01" + } +} diff --git a/nixos/overlays/warp-terminal/warp-terminal.nix b/nixos/overlays/warp-terminal/warp-terminal.nix new file mode 100644 index 0000000..aec7d96 --- /dev/null +++ b/nixos/overlays/warp-terminal/warp-terminal.nix @@ -0,0 +1,13 @@ +{ lib, ...}: +let + versions = lib.importJSON ./versions.json; +in +(final: prev: { + warp-terminal = prev.warp-terminal.overrideAttrs (oldAttrs: { + version = versions.linux.version; + src = builtins.fetchurl { + url = "https://releases.warp.dev/stable/v${versions.linux.version}/warp-terminal-v${versions.linux.version}-1-x86_64.pkg.tar.zst"; + sha256 = versions.linux.hash; + }; + }); +}) \ No newline at end of file diff --git a/nixos/profiles/hw-legion-15arh05h.nix b/nixos/profiles/hw-legion-15arh05h.nix index 5281387..b28df24 100644 --- a/nixos/profiles/hw-legion-15arh05h.nix +++ b/nixos/profiles/hw-legion-15arh05h.nix @@ -1,10 +1,11 @@ -{ config, lib, pkgs, ... }: +{ lib, pkgs, ... }: { # Support windows partition mySystem = { security.wheelNeedsSudoPassword = false; system.packages = with pkgs; [ ntfs3g + warp-terminal ]; }; From 3f4e24449bd506d2449a168b4219bd9f39bf107d Mon Sep 17 00:00:00 2001 From: Joseph Hanson Date: Sun, 30 Jun 2024 23:28:19 -0500 Subject: [PATCH 2/4] Removing leftovers. --- nixos/overlays/warp-terminal/config.nix | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 nixos/overlays/warp-terminal/config.nix diff --git a/nixos/overlays/warp-terminal/config.nix b/nixos/overlays/warp-terminal/config.nix deleted file mode 100644 index f6baea5..0000000 --- a/nixos/overlays/warp-terminal/config.nix +++ /dev/null @@ -1,15 +0,0 @@ -{ lib, ... }: -let - versions = lib.importJSON ./versions.json; -in -{ - packageOverrides = pkgs: { - warp-terminal = pkgs.warp-terminal.override { - version = "0.2024.06.25.08.02.stable_01"; - src = lib.fetchurl { - hash = "sha256-Fc48bZzFBw9p636Mr8R+W/d1B3kIcOAu/Gd17nbzNfI="; - url = "https://releases.warp.dev/stable/v0.2024.06.25.08.02.stable_01/warp-terminal-v0.2024.06.25.08.02.stable_01-1-x86_64.pkg.tar.zst"; - }; - }; - }; -} From 290c7d44fc00417a9621f8d0f453ebbcaccf264e Mon Sep 17 00:00:00 2001 From: Joseph Hanson Date: Sun, 30 Jun 2024 23:33:01 -0500 Subject: [PATCH 3/4] Tidy --- nixos/overlays/warp-terminal/update.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/nixos/overlays/warp-terminal/update.sh b/nixos/overlays/warp-terminal/update.sh index d1dcb06..f9bcec2 100755 --- a/nixos/overlays/warp-terminal/update.sh +++ b/nixos/overlays/warp-terminal/update.sh @@ -49,7 +49,7 @@ get_version() { echo "$1" | grep -oP -m 1 '(?<=/v)[\d.\w]+(?=/)' } -# nix-prefect-url seems to be uncompressing the archive then taking the hash +# nix-prefetch-url seems to be uncompressing the archive then taking the hash # so just get the hash from fetchurl sri_get() { local ouput sri @@ -63,7 +63,6 @@ sri_get() { echo "$sri" } - for sys in darwin linux; do url=$(resolve_url ${sys}) version=$(get_version "${url}") From 4a81e56111fc767fd8e5b3a098d10a175aafaa36 Mon Sep 17 00:00:00 2001 From: Joseph Hanson Date: Mon, 1 Jul 2024 08:47:45 -0500 Subject: [PATCH 4/4] use nixpkgs fetchurl --- nixos/overlays/warp-terminal/warp-terminal.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nixos/overlays/warp-terminal/warp-terminal.nix b/nixos/overlays/warp-terminal/warp-terminal.nix index aec7d96..e9b4665 100644 --- a/nixos/overlays/warp-terminal/warp-terminal.nix +++ b/nixos/overlays/warp-terminal/warp-terminal.nix @@ -5,9 +5,9 @@ in (final: prev: { warp-terminal = prev.warp-terminal.overrideAttrs (oldAttrs: { version = versions.linux.version; - src = builtins.fetchurl { + src = prev.fetchurl { url = "https://releases.warp.dev/stable/v${versions.linux.version}/warp-terminal-v${versions.linux.version}-1-x86_64.pkg.tar.zst"; - sha256 = versions.linux.hash; + hash = versions.linux.hash; }; }); }) \ No newline at end of file