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
44set -euo pipefail
55
1717echo " Found version: $VERSION "
1818echo " "
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.
2147update_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
5789echo " 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
6193echo " "
6294echo " 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
6698echo " "
6799echo " 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
71103echo " "
72104echo " 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
76108echo " "
77109echo " Updating frontend hash..."
78- update_hash " frontend-url" " frontend-hash"
110+ update_hash " frontend-url" " frontend-hash" no-strip
79111
80112echo " "
81113echo " Done!"
0 commit comments