List the derivations a package upgrade would build

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AeFqV9dZrK6nipHkPfyM4F
This commit is contained in:
2026-11-18 11:42:10 +01:00
co-authored by Claude Sonnet 5.5
parent 38e7613b34
commit 7b4ecee518
5 changed files with 23 additions and 5 deletions
+8 -2
View File
@@ -189,13 +189,19 @@ let
download=$(grep -o '([0-9.]* [KMGT]iB download, [0-9.]* [KMGT]iB unpacked)' <<<"$dry" | head -1 || true)
builds=$(grep -cE '^ +/nix/store/[^ ]*\.drv$' <<<"$dry" || true)
echo " to fetch: ''${download:-nothing, or no cache reachable}; to build here: $builds"
# What would be built here: the derivations' names (the system's own pieces, mostly).
{ grep -E '^ +/nix/store/[^ ]*\.drv$' <<<"$dry" || true; } | sed 's/^ *//' | names | sort -u > ${dir}/builds.txt
sed 's/^/ /' ${dir}/builds.txt | head -n 60
if [ "$(wc -l < ${dir}/builds.txt)" -gt 60 ]; then echo " ... and $(( $(wc -l < ${dir}/builds.txt) - 60 )) more"; fi
release_version=$(jq -r '.version // ""' /etc/router-release 2>/dev/null || true)
jq -n --arg channel "$channel" --arg release "$release_version" --arg rev "$newest" --arg ref "$pin" --arg version "$new_version" \
--arg time "$(date -u +%FT%TZ)" --arg download "$download" --argjson builds "$builds" \
--argjson reboot "$reboot" --slurpfile changes ${dir}/changes.json \
--argjson reboot "$reboot" --slurpfile changes ${dir}/changes.json --rawfile buildNames ${dir}/builds.txt \
'{channel: $channel, release: $release, rev: $rev, ref: $ref, version: $version, time: $time, download: $download,
builds: $builds, rebootNeeded: $reboot, changes: $changes[0]}' > ${dir}/preview.json
builds: $builds, buildNames: ($buildNames | split("\n") | map(select(. != "")) | .[:300]),
rebootNeeded: $reboot, changes: $changes[0]}' > ${dir}/preview.json
rm -f ${dir}/builds.txt
echo "$new_version$([ "$reboot" = false ] || echo ' (a new kernel runs after a reboot)'): router-upgrade apply activates it"
}
+8
View File
@@ -73,6 +73,14 @@
<dt>Built here</dt><dd>{{.Builds}} derivation{{if ne .Builds 1}}s{{end}}{{if gt .Builds 50}} <span class="muted">(many: the package cache may not have them yet; this takes long)</span>{{end}}</dd>
{{if .RebootNeeded}}<dt>Kernel</dt><dd>A new kernel: it runs after the next reboot.</dd>{{end}}
</dl>
{{if .BuildNames}}
<details>
<summary>What is built here</summary>
<p class="hint">The system's own pieces (they carry the nixpkgs revision) and programs the package cache does not have yet.</p>
<ul>{{range .BuildNames}}<li>{{.}}</li>{{end}}</ul>
{{if .MoreBuilds}}<p class="muted">… and {{.MoreBuilds}} more</p>{{end}}
</details>
{{end}}
<div class="actions">
<form method="post" action="/upgrade/download">
<input type="hidden" name="csrf" value="{{$.CSRF}}">
+4
View File
@@ -73,10 +73,14 @@ type UpgradePreview struct {
Time string `json:"time"`
Download string `json:"download"`
Builds int `json:"builds"`
BuildNames []string `json:"buildNames"` // what would be built here
RebootNeeded bool `json:"rebootNeeded"`
Changes []UpgradeChange `json:"changes"`
}
// MoreBuilds is how many derivations are built that BuildNames does not name.
func (p UpgradePreview) MoreBuilds() int { return max(p.Builds-len(p.BuildNames), 0) }
func readUpgradeFile(path string, v any) bool {
data, err := os.ReadFile(path)
return err == nil && json.Unmarshal(data, v) == nil
+2 -2
View File
@@ -161,9 +161,9 @@ func TestUpgradePage(t *testing.T) {
t.Fatal("the unit was started without a preview")
}
os.MkdirAll(a.sys.upgradeDir(), 0o700)
os.WriteFile(filepath.Join(a.sys.upgradeDir(), "preview.json"), []byte(`{"channel":"26.05","release":"0.12.11","rev":"0123456789abcdef0123456789abcdef01234567","version":"26.11.20261110.0123456","time":"2026-11-10T10:00:00Z","download":"(350.5 MiB download, 1.2 GiB unpacked)","builds":3,"rebootNeeded":true,"changes":[{"name":"frr","from":"10.1","to":"10.2"},{"name":"linux","from":"6.12.5","to":"6.12.8"}]}`), 0o600)
os.WriteFile(filepath.Join(a.sys.upgradeDir(), "preview.json"), []byte(`{"channel":"26.05","release":"0.12.11","rev":"0123456789abcdef0123456789abcdef01234567","version":"26.11.20261110.0123456","time":"2026-11-10T10:00:00Z","download":"(350.5 MiB download, 1.2 GiB unpacked)","builds":3,"buildNames":["etc-1","nixos-system-router-26.11.20261110.0123456"],"rebootNeeded":true,"changes":[{"name":"frr","from":"10.1","to":"10.2"},{"name":"linux","from":"6.12.5","to":"6.12.8"}]}`), 0o600)
body := page()
for _, want := range []string{"frr", "10.1", "10.2", "linux", "350.5 MiB", "3 derivations", "after the next reboot", "Upgrade to 26.11.20261110.0123456"} {
for _, want := range []string{"frr", "10.1", "10.2", "linux", "350.5 MiB", "3 derivations", "What is built here", "<li>etc-1</li>", "1 more", "after the next reboot", "Upgrade to 26.11.20261110.0123456"} {
if !strings.Contains(body, want) {
t.Errorf("the preview does not show %q", want)
}
+1 -1
View File
@@ -369,7 +369,7 @@ pkgs.testers.runNixOSTest {
preview = json.loads(target.succeed("cat /var/lib/router/upgrade/preview.json"))
assert preview["rev"] == running_rev and preview["version"] == running_version and preview["changes"] == [], preview
assert preview["ref"].startswith("path:/var/lib/newer-nixpkgs?") and "rev=" + running_rev in preview["ref"] and "narHash=sha256-" in preview["ref"], preview
assert preview["rebootNeeded"] is False and preview["builds"] == 0, preview
assert preview["rebootNeeded"] is False and preview["builds"] == 0 and preview["buildNames"] == [], preview
target.succeed("test ! -e /var/lib/router/upgrade/result")
assert current() == before
target.succeed("test ! -e /var/lib/router/config/nixpkgs-pin.json")