summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPerchunPak <git@perchun.it>2024-05-10 23:17:07 +0200
committergithub-actions[bot] <github-actions[bot]@users.noreply.github.com>2024-11-20 20:43:10 +0000
commita6b064449ef279e4bfc5b61e6f42a510b8cc1fd9 (patch)
tree61d66deaff720d97aa8acdebfa222ed32566008d
parent[24.05] signal-desktop(aarch64-linux): 7.23.0 -> 7.33.0 (#357583) (diff)
downloadnixpkgs-origin/backport-310681-to-release-24.05.tar.gz
gh-copilot: add auto-updatingorigin/backport-310681-to-release-24.05
(cherry picked from commit 158a39089b46d587f73e049fde7dbf65b9b42af2)
-rw-r--r--pkgs/by-name/gh/gh-copilot/package.nix2
-rwxr-xr-xpkgs/by-name/gh/gh-copilot/update.sh43
2 files changed, 45 insertions, 0 deletions
diff --git a/pkgs/by-name/gh/gh-copilot/package.nix b/pkgs/by-name/gh/gh-copilot/package.nix
index 1059e58cbeb2..a0d3342aa391 100644
--- a/pkgs/by-name/gh/gh-copilot/package.nix
+++ b/pkgs/by-name/gh/gh-copilot/package.nix
@@ -46,6 +46,8 @@ stdenv.mkDerivation (finalAttrs: {
runHook postInstall
'';
+ passthru.updateScript = ./update.sh;
+
meta = {
changelog = "https://github.com/github/gh-copilot/releases/tag/v${finalAttrs.version}";
description = "Ask for assistance right in your terminal.";
diff --git a/pkgs/by-name/gh/gh-copilot/update.sh b/pkgs/by-name/gh/gh-copilot/update.sh
new file mode 100755
index 000000000000..cca77cd367c0
--- /dev/null
+++ b/pkgs/by-name/gh/gh-copilot/update.sh
@@ -0,0 +1,43 @@
+#!/usr/bin/env nix-shell
+#!nix-shell -i bash -p curl jq common-updater-scripts nix-prefetch
+
+set -euo pipefail
+set -x
+
+ROOT="$(dirname "$(readlink -f "$0")")"
+NIX_DRV="$ROOT/package.nix"
+if [ ! -f "$NIX_DRV" ]; then
+ echo "ERROR: cannot find gh-copilot in $ROOT"
+ exit 1
+fi
+
+fetch_arch() {
+ VER="$1"; ARCH="$2"
+ URL="https://github.com/github/gh-copilot/releases/download/v${VER}/${ARCH}";
+ nix-prefetch "{ stdenv, fetchzip }:
+stdenv.mkDerivation rec {
+ pname = \"vere\"; version = \"${VER}\";
+ src = fetchurl { url = \"$URL\"; };
+}
+"
+}
+
+replace_sha() {
+ # https://stackoverflow.com/a/38470458/22235705
+ sed -rziE "s@($1[^\n]*\n[^\n]*hash = )\"sha256-.{44}\";@\1\"$2\";@" "$NIX_DRV"
+}
+
+VERE_VER=$(curl https://api.github.com/repos/github/gh-copilot/releases/latest | jq .tag_name)
+VERE_VER=$(echo $VERE_VER | sed -e 's/^"v//' -e 's/"$//') # transform "v1.0.2" into 1.0.2
+
+VERE_LINUX_X64_SHA256=$(fetch_arch "$VERE_VER" "linux-amd64")
+VERE_LINUX_AARCH64_SHA256=$(fetch_arch "$VERE_VER" "linux-arm64")
+VERE_DARWIN_X64_SHA256=$(fetch_arch "$VERE_VER" "darwin-amd64")
+VERE_DARWIN_AARCH64_SHA256=$(fetch_arch "$VERE_VER" "darwin-arm64")
+
+sed -i "s/version = \".*\"/version = \"$VERE_VER\"/" "$NIX_DRV"
+
+replace_sha "linux-amd64" "$VERE_LINUX_X64_SHA256"
+replace_sha "linux-arm64" "$VERE_LINUX_AARCH64_SHA256"
+replace_sha "darwin-amd64" "$VERE_DARWIN_X64_SHA256"
+replace_sha "darwin-arm64" "$VERE_DARWIN_AARCH64_SHA256"