Skip to content

Commit f1e9768

Browse files
authored
Update packages (#30)
* Update package lists * Fix missing ros-dev-tools package * Add update-packages-sha256 script
1 parent 7dd1b1b commit f1e9768

File tree

2 files changed

+223
-9
lines changed

2 files changed

+223
-9
lines changed

OS-image/default.nix

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ let
1212
scripts = pkgs.callPackage ./scripts { inherit files-lite files-full; };
1313

1414
packageLists = let
15-
noble-updates-stamp = "20260105T120000Z";
16-
ros2-stamp = "2025-08-20";
17-
fictionlab-stamp = "2026-01-05";
15+
noble-updates-stamp = "20260126T120000Z";
16+
ros2-stamp = "2025-11-19";
17+
fictionlab-stamp = "2026-01-26";
1818
in [
1919
{
2020
name = "noble-main";
@@ -48,7 +48,7 @@ let
4848
packagesFile = (fetchurl {
4949
url =
5050
"http://snapshot.ubuntu.com/ubuntu/${noble-updates-stamp}/dists/noble-updates/main/binary-arm64/Packages.xz";
51-
sha256 = "sha256-LR+hweEjPcNoGjeqUJvF/+/aRn6XedT2q6uDFXKI5UQ=";
51+
sha256 = "sha256-ueMXJ5UCP5o1vXN0gIvhOQMFWK0lC2Hb1gWiZhtcWkE=";
5252
});
5353
urlPrefix = "http://snapshot.ubuntu.com/ubuntu/${noble-updates-stamp}";
5454
}
@@ -57,7 +57,7 @@ let
5757
packagesFile = (fetchurl {
5858
url =
5959
"http://snapshot.ubuntu.com/ubuntu/${noble-updates-stamp}/dists/noble-updates/universe/binary-arm64/Packages.xz";
60-
sha256 = "sha256-IGC2GixRQ1BWFBDHSoZGlfdIs0r7TmTMMsCnqdvAej8=";
60+
sha256 = "sha256-+7KyZwcgMYioEwbfl70ehs2DjQtb//DJgHxscl4nX1E=";
6161
});
6262
urlPrefix = "http://snapshot.ubuntu.com/ubuntu/${noble-updates-stamp}";
6363
}
@@ -66,7 +66,7 @@ let
6666
packagesFile = (fetchurl {
6767
url =
6868
"http://snapshot.ubuntu.com/ubuntu/${noble-updates-stamp}/dists/noble-updates/restricted/binary-arm64/Packages.xz";
69-
sha256 = "sha256-KGAqpOiH9vLRDxc55bTvvMPR/fT7eijmmW0BROJ0M1E=";
69+
sha256 = "sha256-Y4rWBsy6vhRIlh5+qRr36mLFJUAHyYJqpj4wSDxTTC8=";
7070
});
7171
urlPrefix = "http://snapshot.ubuntu.com/ubuntu/${noble-updates-stamp}";
7272
}
@@ -75,7 +75,7 @@ let
7575
packagesFile = (fetchurl {
7676
url =
7777
"http://snapshots.ros.org/jazzy/${ros2-stamp}/ubuntu/dists/noble/main/binary-arm64/Packages.bz2";
78-
sha256 = "sha256-32TlSnKKQ8AguwjFItC6V4DawkOOtdw0AzeTq/sstRA=";
78+
sha256 = "sha256-vPGyfs43Eo7xR5YnrOj8mSdzwZ8jLA6y0/D18N0WSTg=";
7979
});
8080
urlPrefix = "http://snapshots.ros.org/jazzy/${ros2-stamp}/ubuntu";
8181
}
@@ -84,7 +84,7 @@ let
8484
packagesFile = (fetchurl {
8585
url =
8686
"https://archive.fictionlab.pl/dists/noble/snapshots/${fictionlab-stamp}/main/binary-arm64/Packages.gz";
87-
sha256 = "sha256-fQz7KsJYzvQ7AOLiQj1lGbzbqlkHYaT8iWaCHdQ8cOs=";
87+
sha256 = "sha256-3liq9AhgYbfiIR3ICikCajWGZ/URtofuAm4OVEenPD0=";
8888
});
8989
urlPrefix = "https://archive.fictionlab.pl";
9090
}
@@ -183,7 +183,17 @@ let
183183
"python3-distro"
184184

185185
"ros2-apt-source" # Configures sources for ROS 2 repo
186-
"ros-dev-tools" # ROS development tools (rosdep, colcon, vcs etc.)
186+
# "ros-dev-tools" # ROS development tools (rosdep, colcon, vcs etc.)
187+
# The newest ROS snapshot is missing ros-dev-tools, so we install its dependencies instead
188+
"cmake"
189+
"python3-setuptools"
190+
"python3-bloom"
191+
"python3-colcon-common-extensions"
192+
"python3-colcon-mixin"
193+
"python3-rosdep"
194+
"python3-vcstool"
195+
"wget"
196+
187197
"ros-jazzy-ros-base" # ROS base packages
188198

189199
"---"

scripts/update-packages-sha256.sh

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# WARNING: AI Slop
5+
# Update sha256 values for fetchurl Packages files in a Nix file.
6+
# Default target: OS-image/default.nix
7+
# Requires: nix-prefetch-url, nix (for nix hash convert)
8+
9+
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd)"
10+
target_file="$repo_root/OS-image/default.nix"
11+
dry_run=false
12+
list_only=false
13+
14+
usage() {
15+
cat <<EOF
16+
Usage: $(basename "$0") [-f <nix-file>] [--dry-run] [--list]
17+
18+
Options:
19+
-f, --file <path> Path to Nix file (default: OS-image/default.nix)
20+
--dry-run Show planned replacements, do not modify file
21+
--list List discovered URLs and current sha256s without fetching
22+
23+
Examples:
24+
$(basename "$0") # update all sha256 entries
25+
$(basename "$0") --dry-run # preview changes only
26+
$(basename "$0") --list # list URLs and current hashes
27+
$(basename "$0") -f path/to/file.nix # operate on a custom Nix file
28+
EOF
29+
}
30+
31+
while [[ $# -gt 0 ]]; do
32+
case "$1" in
33+
-f|--file)
34+
shift
35+
[[ $# -gt 0 ]] || { echo "Missing argument for --file" >&2; exit 2; }
36+
target_file="$1"
37+
;;
38+
--dry-run)
39+
dry_run=true
40+
;;
41+
--list)
42+
list_only=true
43+
;;
44+
-h|--help)
45+
usage
46+
exit 0
47+
;;
48+
*)
49+
echo "Unknown argument: $1" >&2
50+
usage
51+
exit 2
52+
;;
53+
esac
54+
shift
55+
done
56+
57+
if [[ ! -f "$target_file" ]]; then
58+
echo "Target file not found: $target_file" >&2
59+
exit 1
60+
fi
61+
62+
if [[ "$list_only" != true ]]; then
63+
command -v nix-prefetch-url >/dev/null 2>&1 || {
64+
echo "nix-prefetch-url is required" >&2
65+
exit 1
66+
}
67+
command -v nix >/dev/null 2>&1 || {
68+
echo "nix (for 'nix hash convert') is required" >&2
69+
exit 1
70+
}
71+
fi
72+
73+
# Extract mapping of sha256 line numbers, current sha256, and URLs from fetchurl blocks
74+
map_file="$(mktemp)"
75+
trap 'rm -f "$map_file"' EXIT
76+
77+
awk '
78+
BEGIN { in_block=0; url=""; sha=""; expect_url=0 }
79+
/packagesFile[[:space:]]*=\s*\(fetchurl[[:space:]]*\{/ { in_block=1; url=""; sha=""; expect_url=0; next }
80+
in_block && /url[[:space:]]*=/ {
81+
# handle url on same or next line
82+
expect_url=1
83+
if (match($0, /"([^"]+)"/, m)) { url=m[1]; expect_url=0 }
84+
next
85+
}
86+
in_block && expect_url==1 {
87+
if (match($0, /"([^"]+)"/, m)) { url=m[1]; expect_url=0 }
88+
}
89+
in_block && /sha256[[:space:]]*=/ {
90+
# capture quoted sha
91+
if (match($0, /sha256[[:space:]]*=\s*"([^"]+)"/, m)) { sha=m[1] }
92+
# output: line_number|current_sha|url
93+
printf "%d|%s|%s\n", NR, sha, url
94+
next
95+
}
96+
in_block && /\}\);/ { in_block=0; url=""; sha=""; expect_url=0; next }
97+
' "$target_file" > "$map_file"
98+
99+
if [[ "$list_only" == true ]]; then
100+
echo "Discovered fetchurl entries in $target_file:" >&2
101+
while IFS='|' read -r lineno cur_sha url; do
102+
printf -- "- line %s: url=%s\n current sha256=%s\n" "$lineno" "$url" "$cur_sha"
103+
done < "$map_file"
104+
exit 0
105+
fi
106+
107+
tmp_out="$(mktemp)"
108+
cp "$target_file" "$tmp_out"
109+
110+
changes=0
111+
errors=0
112+
113+
# Read stamp variables from the Nix file (e.g., noble-updates-stamp, ros2-stamp, fictionlab-stamp)
114+
declare -A stamps
115+
while IFS= read -r line; do
116+
case "$line" in
117+
*-stamp*=*)
118+
key_part="${line%%=*}"
119+
# trim leading/trailing whitespace robustly
120+
key_part="$(printf '%s' "$key_part" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
121+
# extract quoted value
122+
val_part="${line#*\"}"
123+
val_part="${val_part%%\"*}"
124+
if [[ -n "$key_part" && -n "$val_part" ]]; then
125+
stamps["$key_part"]="$val_part"
126+
fi
127+
;;
128+
esac
129+
done < "$target_file"
130+
131+
# Debug: print parsed stamp variables when dry-run or list-only for visibility
132+
if [[ "$dry_run" == true || "$list_only" == true ]]; then
133+
for k in "${!stamps[@]}"; do
134+
echo "Stamp: $k=${stamps[$k]}" >&2
135+
done
136+
fi
137+
138+
exec 3< "$map_file"
139+
set +e
140+
while IFS='|' read -r lineno cur_sha url <&3; do
141+
if [[ -z "$url" ]]; then
142+
echo "Skipping line $lineno: no URL found" >&2
143+
((errors++))
144+
continue
145+
fi
146+
147+
# Resolve any ${var} placeholders using parsed stamp values
148+
resolved_url="$url"
149+
for key in "${!stamps[@]}"; do
150+
pattern="\${$key}"
151+
value="${stamps[$key]}"
152+
echo "Subst: pattern=$pattern value=$value" >&2
153+
resolved_url="${resolved_url//${pattern}/$value}"
154+
done
155+
echo "Resolved URL: $resolved_url" >&2
156+
if [[ "$resolved_url" == *"\${"* ]]; then
157+
echo "Unresolved placeholder in URL: $url" >&2
158+
fi
159+
160+
echo "Prefetching: $resolved_url" >&2
161+
if ! nix32_hash=$(nix-prefetch-url "$resolved_url" 2>/dev/null); then
162+
echo "Failed to prefetch $url" >&2
163+
((errors++))
164+
continue
165+
fi
166+
echo "Prefetched nix32: $nix32_hash" >&2
167+
if ! sri_hash=$(nix hash convert --hash-algo sha256 --from nix32 --to sri "$nix32_hash" 2>/dev/null); then
168+
echo "Failed to convert hash for $url" >&2
169+
((errors++))
170+
continue
171+
fi
172+
echo "Converted SRI: $sri_hash" >&2
173+
174+
if [[ "$dry_run" == true ]]; then
175+
echo "Would update line $lineno: sha256 = \"$cur_sha\"; -> sha256 = \"$sri_hash\";" >&2
176+
else
177+
# Replace the sha256 line at the exact line number
178+
if sed -i "${lineno}s|sha256 = \".*\";|sha256 = \"${sri_hash}\";|" "$tmp_out"; then
179+
echo "Updated line $lineno" >&2
180+
((changes++))
181+
else
182+
echo "Failed to update line $lineno" >&2
183+
((errors++))
184+
fi
185+
fi
186+
done < "$map_file"
187+
set -e
188+
189+
if [[ "$dry_run" == true ]]; then
190+
echo "Dry-run complete. No changes written." >&2
191+
exit 0
192+
fi
193+
194+
if [[ $changes -gt 0 ]]; then
195+
mv "$tmp_out" "$target_file"
196+
echo "Updated $changes sha256 entrie(s) in: $target_file"
197+
else
198+
rm -f "$tmp_out"
199+
echo "No changes made."
200+
fi
201+
202+
if [[ $errors -gt 0 ]]; then
203+
echo "Completed with $errors error(s). Some entries may not have been updated." >&2
204+
fi

0 commit comments

Comments
 (0)