tangled
alpha
login
or
join now
pyrox.dev
/
nixpkgs
lol
0
fork
atom
overview
issues
pulls
pipelines
gh-copilot: add auto-updating
PerchunPak
2 years ago
158a3908
8e974549
+45
2 changed files
expand all
collapse all
unified
split
pkgs
by-name
gh
gh-copilot
package.nix
update.sh
+2
pkgs/by-name/gh/gh-copilot/package.nix
···
46
46
runHook postInstall
47
47
'';
48
48
49
49
+
passthru.updateScript = ./update.sh;
50
50
+
49
51
meta = {
50
52
changelog = "https://github.com/github/gh-copilot/releases/tag/v${finalAttrs.version}";
51
53
description = "Ask for assistance right in your terminal.";
+43
pkgs/by-name/gh/gh-copilot/update.sh
···
1
1
+
#!/usr/bin/env nix-shell
2
2
+
#!nix-shell -i bash -p curl jq common-updater-scripts nix-prefetch
3
3
+
4
4
+
set -euo pipefail
5
5
+
set -x
6
6
+
7
7
+
ROOT="$(dirname "$(readlink -f "$0")")"
8
8
+
NIX_DRV="$ROOT/package.nix"
9
9
+
if [ ! -f "$NIX_DRV" ]; then
10
10
+
echo "ERROR: cannot find gh-copilot in $ROOT"
11
11
+
exit 1
12
12
+
fi
13
13
+
14
14
+
fetch_arch() {
15
15
+
VER="$1"; ARCH="$2"
16
16
+
URL="https://github.com/github/gh-copilot/releases/download/v${VER}/${ARCH}";
17
17
+
nix-prefetch "{ stdenv, fetchzip }:
18
18
+
stdenv.mkDerivation rec {
19
19
+
pname = \"vere\"; version = \"${VER}\";
20
20
+
src = fetchurl { url = \"$URL\"; };
21
21
+
}
22
22
+
"
23
23
+
}
24
24
+
25
25
+
replace_sha() {
26
26
+
# https://stackoverflow.com/a/38470458/22235705
27
27
+
sed -rziE "s@($1[^\n]*\n[^\n]*hash = )\"sha256-.{44}\";@\1\"$2\";@" "$NIX_DRV"
28
28
+
}
29
29
+
30
30
+
VERE_VER=$(curl https://api.github.com/repos/github/gh-copilot/releases/latest | jq .tag_name)
31
31
+
VERE_VER=$(echo $VERE_VER | sed -e 's/^"v//' -e 's/"$//') # transform "v1.0.2" into 1.0.2
32
32
+
33
33
+
VERE_LINUX_X64_SHA256=$(fetch_arch "$VERE_VER" "linux-amd64")
34
34
+
VERE_LINUX_AARCH64_SHA256=$(fetch_arch "$VERE_VER" "linux-arm64")
35
35
+
VERE_DARWIN_X64_SHA256=$(fetch_arch "$VERE_VER" "darwin-amd64")
36
36
+
VERE_DARWIN_AARCH64_SHA256=$(fetch_arch "$VERE_VER" "darwin-arm64")
37
37
+
38
38
+
sed -i "s/version = \".*\"/version = \"$VERE_VER\"/" "$NIX_DRV"
39
39
+
40
40
+
replace_sha "linux-amd64" "$VERE_LINUX_X64_SHA256"
41
41
+
replace_sha "linux-arm64" "$VERE_LINUX_AARCH64_SHA256"
42
42
+
replace_sha "darwin-amd64" "$VERE_DARWIN_X64_SHA256"
43
43
+
replace_sha "darwin-arm64" "$VERE_DARWIN_AARCH64_SHA256"