-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-hashes.sh
More file actions
executable file
·61 lines (45 loc) · 1.65 KB
/
update-hashes.sh
File metadata and controls
executable file
·61 lines (45 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p coreutils gnused gnugrep findutils nix jq
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
FLAKE_NIX="$SCRIPT_DIR/flake.nix"
# Read the version from the flake using nix eval
VERSION=$(nix eval "$SCRIPT_DIR#version" --raw)
if [[ -z "$VERSION" ]]; then
echo "Error: Could not evaluate version from flake"
exit 1
fi
echo "Found version: $VERSION"
echo ""
update_hash() {
local url_marker="$1"
local hash_marker="$2"
# Extract the URL line and parse out the URL template
local url_line=$(grep "# $url_marker\$" "$FLAKE_NIX")
if [[ -z "$url_line" ]]; then
echo "Warning: Could not find marker # $url_marker"
return
fi
# Extract the URL from the line (it's between quotes after url =)
# The URL contains ${version} which we need to substitute
local url_template=$(echo "$url_line" | sed -E 's/.*= "([^"]+)".*/\1/')
# Substitute ${version} with the actual version
local url=$(echo "$url_template" | sed "s/\${version}/$VERSION/g")
echo "Fetching: $url"
local hash
hash=$(nix store prefetch-file --unpack --json "$url" 2>/dev/null | jq -r .hash)
if [[ -z "$hash" ]]; then
echo "Error: Failed to fetch hash for $url"
return 1
fi
echo " Hash: $hash"
# Update the hash in flake.nix
# Find the line with the hash marker and replace the hash value
sed -i -E "s|(= \")sha256-[^\"]+(\"; # $hash_marker)|\1${hash}\2|" "$FLAKE_NIX"
}
for arch in amd64 arm64; do
echo "Updating $arch tarball hash..."
update_hash "tarball-url-$arch" "tarball-hash-$arch"
echo ""
done
echo "Done!"