Say when a newer NixOS release is out

router-upgrade releases asks the channel server which stable releases exist
(daily timer, and on every check). The Overview and Packages pages tell a
router that follows a stable release when a newer one is out, and offer the
newest two releases as channels instead of a fixed list.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-24 22:10:27 +01:00
co-authored by Claude Sonnet 5.5
parent 2e4a596fdc
commit 048b53fe33
9 changed files with 241 additions and 27 deletions
+4 -3
View File
@@ -488,14 +488,15 @@ func (a *app) logout(w http.ResponseWriter, r *http.Request, _ session) {
}
type overviewData struct {
Status Status
Dashboard dashboard
Status Status
Dashboard dashboard
NewRelease string // a stable NixOS release newer than the followed channel exists
}
func (a *app) overview(w http.ResponseWriter, r *http.Request, sess session) {
st := a.sys.Status()
p := page{Title: "Overview", CSRF: sess.csrf, LoggedIn: true, Flash: r.URL.Query().Get("msg"),
Data: overviewData{Status: st, Dashboard: a.dashboardData(r.URL.Query().Get("range"))}}
Data: overviewData{Status: st, Dashboard: a.dashboardData(r.URL.Query().Get("range")), NewRelease: a.releaseNotice()}}
switch {
case st.Applying || st.ConfirmRunning:
p.Live = 2
+4 -1
View File
@@ -51,7 +51,7 @@ main { padding: 1.5rem clamp(1rem, 3vw, 3rem) 3rem; }
/* Pages of independent panels flow into up to three columns on wide screens */
.cols { columns: 38rem 3; column-gap: 1.5rem; }
.cols > section, .cols > fieldset, .cols > form > fieldset { break-inside: avoid; }
.cols > section.busy, .cols > section.pending { column-span: all; }
.cols > section.busy, .cols > section.pending, .cols > section.notice { column-span: all; }
/* A fold of its own (a log) sits below the columns: opening it must not make them balance again. */
.cols > details { column-span: all; break-inside: avoid; margin-top: 1rem; }
.menu-toggle { position: absolute; opacity: 0; pointer-events: none; }
@@ -60,6 +60,9 @@ h1 { font-size: 1.45rem; font-weight: 600; letter-spacing: -.01em; margin: .25re
h2 { font-size: .95rem; font-weight: 600; margin: 0 0 .6rem; }
section { margin: 0 0 1.5rem; }
section.busy, section.pending { padding: .75rem 1rem; border-radius: var(--radius); background: var(--warn); }
section.notice { padding: .75rem 1rem; border-radius: var(--radius); border-left: 4px solid var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
section.notice h2 { margin-top: 0; }
section.notice p { margin: .4rem 0; }
.upload-overlay { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; background: rgba(0, 0, 0, .55); padding: 1rem; }
.upload-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 32px rgba(0, 0, 0, .35); padding: 1.25rem 1.5rem; width: min(30rem, 100%); }
/* A heading that explains itself when the mouse rests on it. */
@@ -22,6 +22,9 @@
</div>
</section>
{{end}}
{{with .Data.NewRelease}}
<section class="notice"><p>NixOS {{.}} is out. <a href="/upgrade">See what it would change</a>.</p></section>
{{end}}
<div id="dashboard" data-range="{{.Data.Dashboard.Range}}" data-interval="{{.Data.Dashboard.Interval}}">
{{template "dashboard" .}}
+14
View File
@@ -18,11 +18,25 @@
</label>
<button class="secondary">Save</button>
</form>
{{if $d.ReleasesSeen}}<p class="hint">Stable releases as the channel server listed them on {{$d.ReleasesSeen}}; Check for upgrades asks again.</p>{{end}}
<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>
{{with $d.NewerRelease}}
<section class="notice">
<h2>NixOS {{.}} is out</h2>
<p>You follow {{$d.Channel}}. {{.}} is the newer stable release: switch the channel to it, then look for upgrades and
preview what would change. Nothing is installed until you upgrade, and NixOS cannot go back to the older release afterwards.</p>
<form method="post" action="/upgrade/channel" class="actions">
<input type="hidden" name="csrf" value="{{$.CSRF}}">
<input type="hidden" name="channel" value="{{.}}">
<button class="secondary">Follow {{.}}</button>
</form>
</section>
{{end}}
{{if $d.Updating}}
<section class="busy"><h2>Updating…</h2><p>The router is installing a new version of nixos-router.</p></section>
{{else if $d.Run.Running}}
+96 -15
View File
@@ -9,6 +9,7 @@ import (
"path/filepath"
"regexp"
"slices"
"strconv"
"strings"
)
@@ -150,29 +151,106 @@ var upgradeTitles = map[string]string{
type channelChoice struct{ Value, Label string }
type upgradeData struct {
Version string // the running NixOS version
Channel string
Choices []channelChoice
Check *UpgradeCheck
Preview *UpgradePreview
Run UpgradeRun
Title string // what the running step does
Updating bool // router-update is running
Pending bool // a system waits for confirmation
Version string // the running NixOS version
Channel string
Choices []channelChoice
Check *UpgradeCheck
Preview *UpgradePreview
Run UpgradeRun
Title string // what the running step does
NewerRelease string // a stable release newer than the followed channel exists
ReleasesSeen string // when the channel server was last asked which exist
Updating bool // router-update is running
Pending bool // a system waits for confirmation
}
// stableChannels are the stable NixOS releases the page offers (the branch
// nixos-26.05 and so on). They are listed here until the router can ask the
// channel server which exist; the release a router runs says nothing about it:
// nixos-unstable already calls itself the release that comes next.
// nixos-26.05 and so on) until the router has asked the channel server which
// exist (router-upgrade releases, daily); the release a router runs says
// nothing about it: nixos-unstable already calls itself the release that comes
// next.
var stableChannels = []string{"26.05"}
// ReleaseList is releases.json: the stable releases the channel server had.
type ReleaseList struct {
Time string `json:"time"`
Releases []string `json:"releases"`
}
var releaseNameRe = regexp.MustCompile(`^[0-9]{2}\.[0-9]{2}$`)
// releaseCmp orders releases like 25.11 and 26.05 (and 100.05) by number.
func releaseCmp(a, b string) int {
pa, pb := strings.SplitN(a, ".", 2), strings.SplitN(b, ".", 2)
for i := range pa {
if i >= len(pb) {
return 1
}
x, _ := strconv.Atoi(pa[i])
y, _ := strconv.Atoi(pb[i])
if x != y {
return x - y
}
}
if len(pb) > len(pa) {
return -1
}
return 0
}
// seenReleases are the stable releases the channel server last answered with,
// oldest first; none if it has not been asked yet.
func (s System) seenReleases() ReleaseList {
var l ReleaseList
readUpgradeFile(filepath.Join(s.upgradeDir(), "releases.json"), &l)
var ok []string
for _, r := range l.Releases {
if releaseNameRe.MatchString(r) {
ok = append(ok, r)
}
}
slices.SortFunc(ok, releaseCmp)
l.Releases = slices.Compact(ok)
return l
}
// supportedReleases are the stable releases worth following: NixOS supports the
// newest two. Before the router has asked, the ones built in.
func supportedReleases(seen []string) []string {
if len(seen) == 0 {
return stableChannels
}
return seen[max(len(seen)-2, 0):]
}
// newerRelease is the newest stable release that is newer than the one the
// router follows, "" if it follows unstable (or nothing) or is up to date.
func newerRelease(current string, seen []string) string {
if !releaseNameRe.MatchString(current) || len(seen) == 0 {
return ""
}
if newest := seen[len(seen)-1]; releaseCmp(newest, current) > 0 {
return newest
}
return ""
}
// releaseNotice says which newer release exists than the channel being followed.
func (a *app) releaseNotice() string {
s, err := loadSettings(a.sys.settingsPath())
if err != nil {
return ""
}
return newerRelease(s.channel(), a.sys.seenReleases().Releases)
}
// channelChoices are the branches worth offering: none (the packages that came
// with the release), unstable and the stable releases. A configured channel
// that is none of these stays listed.
func channelChoices(current string) []channelChoice {
func channelChoices(current string, stable []string) []channelChoice {
choices := []channelChoice{{"", "None: the packages that came with this release of nixos-router"}, {"unstable", "unstable (newest, may break)"}}
for _, r := range stableChannels {
for _, r := range stable {
choices = append(choices, channelChoice{r, r + " (stable)"})
}
if current != "" && !slices.ContainsFunc(choices, func(c channelChoice) bool { return c.Value == current }) {
@@ -188,7 +266,10 @@ func (a *app) upgradeData() upgradeData {
if s, err := loadSettings(a.sys.settingsPath()); err == nil {
d.Channel = s.channel()
}
d.Choices = channelChoices(d.Channel)
seen := a.sys.seenReleases()
d.Choices = channelChoices(d.Channel, supportedReleases(seen.Releases))
d.NewerRelease = newerRelease(d.Channel, seen.Releases)
d.ReleasesSeen = seen.Time
if d.Run.Running {
data, _ := os.ReadFile(filepath.Join(a.sys.upgradeDir(), "action"))
if d.Title = upgradeTitles[strings.TrimSpace(string(data))]; d.Title == "" {
+50 -3
View File
@@ -24,18 +24,65 @@ func TestReleaseOfAndChannelChoices(t *testing.T) {
}
return strings.Join(v, ",")
}
if got := values(channelChoices("")); got != ",unstable,26.05" {
stable := supportedReleases(nil)
if got := values(channelChoices("", stable)); got != ",unstable,26.05" {
t.Fatalf("choices: %q", got)
}
// A configured channel that is not offered (a release that is gone) is not lost.
if got := values(channelChoices("25.11")); got != ",unstable,26.05,25.11" {
if got := values(channelChoices("25.11", stable)); got != ",unstable,26.05,25.11" {
t.Fatalf("choices: %q", got)
}
if got := values(channelChoices("unstable")); got != ",unstable,26.05" {
if got := values(channelChoices("unstable", stable)); got != ",unstable,26.05" {
t.Fatalf("choices: %q", got)
}
}
func TestReleaseNotice(t *testing.T) {
seen := []string{"25.05", "25.11", "26.05", "26.11"}
if got := supportedReleases(seen); strings.Join(got, ",") != "26.05,26.11" {
t.Fatalf("supported: %v", got)
}
for _, c := range []struct{ current, want string }{
{"26.05", "26.11"}, {"25.11", "26.11"}, {"26.11", ""}, {"unstable", ""}, {"", ""},
} {
if got := newerRelease(c.current, seen); got != c.want {
t.Errorf("following %q: %q, want %q", c.current, got, c.want)
}
}
if got := newerRelease("26.05", nil); got != "" {
t.Errorf("nothing seen: %q", got)
}
if releaseCmp("9.05", "10.05") >= 0 || releaseCmp("26.11", "26.05") <= 0 || releaseCmp("26.05", "26.05") != 0 {
t.Error("releaseCmp")
}
}
func TestReleaseNoticeShows(t *testing.T) {
a, sys := newTestApp(t)
s, _ := loadSettings(sys.settingsPath())
obj(obj(s, "router"), "update")["channel"] = "26.05"
if err := s.save(sys.settingsPath()); err != nil {
t.Fatal(err)
}
if err := os.MkdirAll(sys.upgradeDir(), 0o755); err != nil {
t.Fatal(err)
}
h := a.routes()
cookie := do(h, "POST", "/login", url.Values{"password": {"hunter2hunter2"}}, nil).Result().Cookies()[0]
if body := do(h, "GET", "/upgrade", nil, cookie).Body.String(); strings.Contains(body, "is out") {
t.Fatalf("a notice before the channel server was asked:\n%s", body)
}
os.WriteFile(filepath.Join(sys.upgradeDir(), "releases.json"), []byte(`{"time":"2026-11-19T00:00:00Z","releases":["26.05","26.11"]}`), 0o644)
for _, path := range []string{"/", "/upgrade"} {
if body := do(h, "GET", path, nil, cookie).Body.String(); !strings.Contains(body, "NixOS 26.11 is out") {
t.Errorf("%s has no notice:\n%s", path, body)
}
}
if body := do(h, "GET", "/upgrade", nil, cookie).Body.String(); !strings.Contains(body, `<option value="26.11"`) {
t.Errorf("26.11 is not offered:\n%s", body)
}
}
func TestSetChannelKeepsTheRest(t *testing.T) {
a, sys := newTestApp(t)
os.WriteFile(sys.confirmedPath(), []byte(sample), 0o600)