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
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)
}