Skip to content

Commit a90364a

Browse files
committed
Fix hashes and update-hashes.sh
1 parent 664b80c commit a90364a

2 files changed

Lines changed: 49 additions & 17 deletions

File tree

flake.nix

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
nixTarballs = {
1818
x86_64-linux = {
1919
url = "https://github.com/codedownio/desktop/releases/download/v${version}/nix-static-2.32.4-x86_64-linux.tar.gz"; # nix-tarball-x86_64-url
20-
hash = "sha256-2cCIQEsvcUcojhPzy731GnpDVTwWrxfa75KvxLLeOk8="; # nix-tarball-x86_64-hash
20+
hash = "sha256-Wh+6GqkmDbRel+Tgzia7eJlIy8xjWKaLRINwuSYvxpo="; # nix-tarball-x86_64-hash
2121
};
2222
aarch64-linux = {
2323
url = "https://github.com/codedownio/desktop/releases/download/v${version}/nix-static-2.32.4-aarch64-linux.tar.gz"; # nix-tarball-aarch64-url
24-
hash = "sha256-qvwDG5lyd1qJw2ADNGhFVS+f6h4d3AKpB82vdUT0oH0="; # nix-tarball-aarch64-hash
24+
hash = "sha256-DFje+EYeYMlx5IKCAnspHjLikuhjFzYljSo6Ac1W9SI="; # nix-tarball-aarch64-hash
2525
};
2626
};
2727

@@ -43,11 +43,11 @@
4343
screenshotterTarballs = {
4444
x86_64-linux = {
4545
url = "https://github.com/codedownio/desktop/releases/download/v${version}/codedown-screenshotter-0.1.1-x86_64-linux.tar.gz"; # screenshotter-tarball-x86_64-url
46-
hash = "sha256-cWjXVhAU48YT1rVfk9epxBVGkIs3QqGBkCqX41RrKp4="; # screenshotter-tarball-x86_64-hash
46+
hash = "sha256-MJrYoEjcW5pAsiUV5Zmq6K8M4hZK5t3ETkYHCmvl/w0="; # screenshotter-tarball-x86_64-hash
4747
};
4848
aarch64-linux = {
4949
url = "https://github.com/codedownio/desktop/releases/download/v${version}/codedown-screenshotter-0.1.1-aarch64-linux.tar.gz"; # screenshotter-tarball-aarch64-url
50-
hash = "sha256-AdQwie5JWqaHUHDW46uG39nRmFF3WlwyLoDDNRp2R+Q="; # screenshotter-tarball-aarch64-hash
50+
hash = "sha256-j/IspnxxnzWBKj4nkg4NU1tqKQ5JMo47IqVdEPWLBbM="; # screenshotter-tarball-aarch64-hash
5151
};
5252
};
5353

update-hashes.sh

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env nix-shell
2-
#!nix-shell -i bash -p coreutils gnused gnugrep findutils nix
2+
#!nix-shell -i bash -p coreutils gnused gnugrep findutils nix jq
33

44
set -euo pipefail
55

@@ -17,10 +17,37 @@ fi
1717
echo "Found version: $VERSION"
1818
echo ""
1919

20-
# Function to update a hash for a given URL comment marker
20+
# Compute hash for fetchzip with stripRoot=true (the default).
21+
# nix store prefetch-file --unpack strips root, matching fetchzip's default.
22+
prefetch_hash_strip_root() {
23+
local url="$1"
24+
nix store prefetch-file --unpack --json "$url" 2>/dev/null | jq -r .hash
25+
}
26+
27+
# Compute hash for fetchzip with stripRoot=false.
28+
# Neither nix-prefetch-url --unpack nor nix store prefetch-file --unpack can
29+
# disable root stripping, so we ask Nix to evaluate the actual fetchzip
30+
# derivation with a fake hash and extract the correct hash from the error.
31+
prefetch_hash_no_strip_root() {
32+
local url="$1"
33+
local output
34+
output=$(nix-build --no-out-link --expr "
35+
with import <nixpkgs> {};
36+
fetchzip {
37+
url = \"$url\";
38+
sha256 = \"sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=\";
39+
stripRoot = false;
40+
}
41+
" 2>&1 || true)
42+
echo "$output" | grep -oP 'got:\s+\Ksha256-[A-Za-z0-9+/=]+'
43+
}
44+
45+
# Function to update a hash for a given URL comment marker.
46+
# Pass "no-strip" as $3 for fetchzip entries with stripRoot = false.
2147
update_hash() {
2248
local url_marker="$1"
2349
local hash_marker="$2"
50+
local strip_mode="${3:-strip}"
2451

2552
# Extract the URL line and parse out the URL template
2653
local url_line=$(grep "# $url_marker\$" "$FLAKE_NIX")
@@ -38,8 +65,12 @@ update_hash() {
3865

3966
echo "Fetching: $url"
4067

41-
# Use nix-prefetch-url to get the hash (--unpack for tarballs used with fetchzip)
42-
local hash=$(nix-prefetch-url --unpack "$url" 2>/dev/null | xargs nix hash convert --hash-algo sha256 --to sri)
68+
local hash
69+
if [[ "$strip_mode" == "no-strip" ]]; then
70+
hash=$(prefetch_hash_no_strip_root "$url")
71+
else
72+
hash=$(prefetch_hash_strip_root "$url")
73+
fi
4374

4475
if [[ -z "$hash" ]]; then
4576
echo "Error: Failed to fetch hash for $url"
@@ -54,28 +85,29 @@ update_hash() {
5485
}
5586

5687
# Update all hashes
88+
# Pass "no-strip" for fetchzip entries that use stripRoot = false
5789
echo "Updating nix-tarball hashes..."
58-
update_hash "nix-tarball-x86_64-url" "nix-tarball-x86_64-hash"
59-
update_hash "nix-tarball-aarch64-url" "nix-tarball-aarch64-hash"
90+
update_hash "nix-tarball-x86_64-url" "nix-tarball-x86_64-hash" no-strip
91+
update_hash "nix-tarball-aarch64-url" "nix-tarball-aarch64-hash" no-strip
6092

6193
echo ""
6294
echo "Updating server-tarball hashes..."
63-
update_hash "server-tarball-x86_64-url" "server-tarball-x86_64-hash"
64-
update_hash "server-tarball-aarch64-url" "server-tarball-aarch64-hash"
95+
update_hash "server-tarball-x86_64-url" "server-tarball-x86_64-hash" strip
96+
update_hash "server-tarball-aarch64-url" "server-tarball-aarch64-hash" no-strip
6597

6698
echo ""
6799
echo "Updating screenshotter-tarball hashes..."
68-
update_hash "screenshotter-tarball-x86_64-url" "screenshotter-tarball-x86_64-hash"
69-
update_hash "screenshotter-tarball-aarch64-url" "screenshotter-tarball-aarch64-hash"
100+
update_hash "screenshotter-tarball-x86_64-url" "screenshotter-tarball-x86_64-hash" no-strip
101+
update_hash "screenshotter-tarball-aarch64-url" "screenshotter-tarball-aarch64-hash" no-strip
70102

71103
echo ""
72104
echo "Updating runner-bin-dir hashes..."
73-
update_hash "runner-bin-dir-x86_64-url" "runner-bin-dir-x86_64-hash"
74-
update_hash "runner-bin-dir-aarch64-url" "runner-bin-dir-aarch64-hash"
105+
update_hash "runner-bin-dir-x86_64-url" "runner-bin-dir-x86_64-hash" no-strip
106+
update_hash "runner-bin-dir-aarch64-url" "runner-bin-dir-aarch64-hash" no-strip
75107

76108
echo ""
77109
echo "Updating frontend hash..."
78-
update_hash "frontend-url" "frontend-hash"
110+
update_hash "frontend-url" "frontend-hash" no-strip
79111

80112
echo ""
81113
echo "Done!"

0 commit comments

Comments
 (0)