Allow previewing an older NixOS release with --downgrade

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-09 08:25:36 +01:00
co-authored by Claude Sonnet 5.5
parent 1efa068443
commit b37d8a0961
5 changed files with 26 additions and 14 deletions
+4 -2
View File
@@ -18,8 +18,9 @@
</label>
<button class="secondary">Save</button>
</form>
<p class="hint">The channel only chooses what an upgrade offers; saving it changes nothing on the router. NixOS cannot go back to
an older release.</p>
<p class="hint">The channel only chooses what an upgrade offers; saving it changes nothing on the router. Going back to an older release
(unstable to 26.05) is refused unless you tick "downgrade anyway" when previewing; state written by the newer
release may not work with the older one.</p>
</section>
{{if $d.Updating}}
@@ -54,6 +55,7 @@
<form method="post" action="/upgrade/preview" class="actions">
<input type="hidden" name="csrf" value="{{.CSRF}}">
{{if and $d.Check $d.Check.UpToDate}}<label><input type="checkbox" name="force"> look anyway</label>{{end}}
<label><input type="checkbox" name="downgrade"> downgrade anyway</label>
<button class="secondary"{{if or $d.Run.Running $d.Updating}} disabled{{end}}>Preview</button>
</form>
<p class="hint">Works it out from the new revision's description: no package is downloaded.</p>
+3 -3
View File
@@ -121,8 +121,8 @@ type UpgradeRun = UpdateStatus
func (s System) UpgradeStatus() UpgradeRun { return unitRun("router-upgrade.service") }
// requestUpgrade asks the router-upgrade unit for one step.
func (s System) requestUpgrade(action string, force bool, timeout string) error {
data, _ := json.Marshal(map[string]any{"action": action, "force": force, "timeout": timeout})
func (s System) requestUpgrade(action string, force, downgrade bool, timeout string) error {
data, _ := json.Marshal(map[string]any{"action": action, "force": force, "downgrade": downgrade, "timeout": timeout})
if err := os.MkdirAll(s.upgradeDir(), 0o700); err != nil {
return err
}
@@ -254,7 +254,7 @@ func (a *app) upgradeStep(w http.ResponseWriter, r *http.Request, _ session) {
a.upgradeBack(w, r, "Preview first: it says what would change.")
return
}
if err := a.sys.requestUpgrade(action, r.PostFormValue("force") == "on", ""); err != nil {
if err := a.sys.requestUpgrade(action, r.PostFormValue("force") == "on", r.PostFormValue("downgrade") == "on", ""); err != nil {
a.upgradeBack(w, r, fmt.Sprintf("Could not start it: %v", err))
return
}
+2 -2
View File
@@ -135,8 +135,8 @@ func TestUpgradePage(t *testing.T) {
if r := request(); r["action"] != "check" || started != 1 {
t.Fatalf("%v started %d", r, started)
}
post("/upgrade/preview", url.Values{"force": {"on"}})
if r := request(); r["action"] != "preview" || r["force"] != true {
post("/upgrade/preview", url.Values{"force": {"on"}, "downgrade": {"on"}})
if r := request(); r["action"] != "preview" || r["force"] != true || r["downgrade"] != true {
t.Fatalf("%v", r)
}
if resp := post("/upgrade/format-disk", url.Values{}); resp.StatusCode != http.StatusNotFound {