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:
@@ -224,7 +224,9 @@ verity. The image module and its test (`checks.image`) stay as they are for anyo
|
||||
|
||||
## Package upgrades (`router-upgrade`, 2026-11-08)
|
||||
|
||||
Upgrading nixpkgs (the kernel and every package) on the router, without a new release of nixos-router. Step 1 (CLI and setting) and step 2 (web UI page) are done; the notice of a new NixOS release follows.
|
||||
Upgrading nixpkgs (the kernel and every package) on the router, without a new release of nixos-router. Step 1 (CLI and setting) and step 2 (web UI page) and step 3 (the notice of a new NixOS release) are done.
|
||||
|
||||
- **Releases** (`router-upgrade releases`, daily timer `router-upgrade-notice`, and every `check`): asks the channel server whether `nixos-YY.05` and `nixos-YY.11` exist (last year to next year; 200 = exists, 404 = not yet) and writes `/var/lib/router/upgrade/releases.json`. With no answer at all (no internet) the file is left as it was. The web UI offers the newest two as channels (the built-in list until the file exists), says on the Overview and the Packages page when a stable release newer than the followed one is out (only when a stable release is followed: unstable has no newer one), and has a button that follows it (saving the channel changes nothing on the router). Not done: a note that a release is not tested with this version of nixos-router.
|
||||
|
||||
- **Setting** `router.update.channel`: `unstable` or a release like `26.05` (branch `nixos-26.05`); null: the packages that came with the installed release. Read from the saved `settings.json` when upgrading; applying settings does not change nixpkgs.
|
||||
- **`router-upgrade check`**: the branch's newest revision from `<channels.nixos.org>/<branch>/git-revision` (a redirect to releases.nixos.org, so curl follows it; the last revision Hydra's tests passed), against the running one (`nixos-version --revision`). Writes `/var/lib/router/upgrade/check.json`.
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
# flake.lock, so an upgrade is a new lock:
|
||||
#
|
||||
# router-upgrade check what the channel's newest revision is, against the running one
|
||||
# router-upgrade releases which stable releases exist (nixos-26.05, nixos-26.11, ...), so the
|
||||
# web UI can say when one newer than the followed channel appears
|
||||
# router-upgrade preview lock a copy of the configuration flake to it and evaluate the
|
||||
# system: which packages change version, how much would be
|
||||
# downloaded and built (nothing is downloaded or activated)
|
||||
@@ -41,8 +43,9 @@ let
|
||||
];
|
||||
text = ''
|
||||
usage() {
|
||||
echo "usage: router-upgrade check | preview [--force] [--downgrade] | download | apply [timeout] | --request" >&2
|
||||
echo "usage: router-upgrade check | releases | preview [--force] [--downgrade] | download | apply [timeout] | --request" >&2
|
||||
echo " check the newest revision of router.update.channel, against the running one" >&2
|
||||
echo " releases which stable NixOS releases the channel server has (a timer runs it daily)" >&2
|
||||
echo " preview the packages that change and the size of the download (nothing is fetched)" >&2
|
||||
echo " download fetch and build what was previewed, without activating it" >&2
|
||||
echo " apply activate what was previewed (fetching it if need be), with commit-confirm" >&2
|
||||
@@ -75,9 +78,13 @@ let
|
||||
config=${cfg.directory}
|
||||
mkdir -p ${dir}
|
||||
|
||||
channel=""
|
||||
branch=""
|
||||
if [ "$cmd" != releases ]; then
|
||||
channel=$(jq -r '.router.update.channel // empty' "$config/settings.json")
|
||||
[ -n "$channel" ] || die "no channel: set router.update.channel (unstable, or a release like 26.05)"
|
||||
if [ "$channel" = unstable ]; then branch=nixos-unstable; else branch="nixos-$channel"; fi
|
||||
fi
|
||||
|
||||
running_rev=$(/run/current-system/sw/bin/nixos-version --revision || true)
|
||||
running_version=$(cat /run/current-system/nixos-version)
|
||||
@@ -92,7 +99,30 @@ let
|
||||
echo "$rev"
|
||||
}
|
||||
|
||||
# The stable releases the channel server has (nixos-YY.05 and nixos-YY.11, from last
|
||||
# year to next year), written to ${dir}/releases.json. A release that is not there yet
|
||||
# answers 404. If nothing answers (no internet) the list is left as it was.
|
||||
releases() {
|
||||
local yy m r code answered=0
|
||||
local found=()
|
||||
for yy in $(( 10#$(date +%y) - 1 )) $(( 10#$(date +%y) )) $(( 10#$(date +%y) + 1 )); do
|
||||
for m in 05 11; do
|
||||
r="$yy.$m"
|
||||
code=$(curl -sL --max-time 20 -o /dev/null -w '%{http_code}' "${up.channelsUrl}/nixos-$r/git-revision" || true)
|
||||
case $code in
|
||||
200) found+=("$r"); answered=1 ;;
|
||||
404) answered=1 ;;
|
||||
esac
|
||||
done
|
||||
done
|
||||
[ "$answered" -eq 1 ] || return 0
|
||||
jq -n --arg time "$(date -u +%FT%TZ)" '{time: $time, releases: $ARGS.positional}' --args "''${found[@]}" > ${dir}/releases.json.new
|
||||
mv ${dir}/releases.json.new ${dir}/releases.json
|
||||
echo "releases on the channel server: ''${found[*]:-none}"
|
||||
}
|
||||
|
||||
check() {
|
||||
releases || true
|
||||
newest=$(newest_rev)
|
||||
if [ "$newest" = "$running_rev" ]; then same=true; else same=false; fi
|
||||
jq -n --arg channel "$channel" --arg branch "$branch" --arg time "$(date -u +%FT%TZ)" \
|
||||
@@ -251,6 +281,7 @@ let
|
||||
|
||||
case $cmd in
|
||||
check) check ;;
|
||||
releases) releases ;;
|
||||
preview) preview "$@" ;;
|
||||
download) download ;;
|
||||
apply) apply "$@" ;;
|
||||
@@ -279,6 +310,27 @@ in
|
||||
# The web UI starts this rather than running anything itself, so a switch
|
||||
# that restarts the UI does not cut an upgrade short; a switch must not
|
||||
# restart or stop it either (router-apply is what runs the switch).
|
||||
# Which stable releases exist, once a day: the web UI says when a newer one than
|
||||
# the followed channel appears. It only asks the channel server and writes a small
|
||||
# file, so it is a unit of its own that never holds up an upgrade.
|
||||
systemd.services.router-upgrade-notice = {
|
||||
description = "Look for new NixOS releases";
|
||||
path = [ "/run/current-system/sw" ];
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
ExecStart = "${lib.getExe upgrade} releases";
|
||||
TimeoutStartSec = "5min";
|
||||
};
|
||||
};
|
||||
systemd.timers.router-upgrade-notice = {
|
||||
wantedBy = [ "timers.target" ];
|
||||
timerConfig = {
|
||||
OnCalendar = "daily";
|
||||
RandomizedDelaySec = "1h";
|
||||
Persistent = true;
|
||||
};
|
||||
};
|
||||
|
||||
systemd.services.router-upgrade = {
|
||||
description = "Look for, prepare or apply a nixpkgs upgrade";
|
||||
restartIfChanged = false;
|
||||
|
||||
@@ -490,12 +490,13 @@ func (a *app) logout(w http.ResponseWriter, r *http.Request, _ session) {
|
||||
type overviewData struct {
|
||||
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
|
||||
|
||||
@@ -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" .}}
|
||||
|
||||
@@ -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}}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -157,22 +158,99 @@ type upgradeData struct {
|
||||
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 == "" {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -362,6 +362,17 @@ pkgs.testers.runNixOSTest {
|
||||
assert "up to date" in out, out
|
||||
target.succeed("test ! -e /var/lib/router/upgrade/preview.json")
|
||||
|
||||
with subtest("the stable releases the channel server has are listed, and a missing one is not"):
|
||||
client.succeed("mkdir -p /srv/channels/files/nixos-26.11 && printf %s " + running_rev + " > /srv/channels/files/nixos-26.11/git-revision")
|
||||
out = target.succeed("router-upgrade releases 2>&1")
|
||||
listed = json.loads(target.succeed("cat /var/lib/router/upgrade/releases.json"))
|
||||
assert listed["releases"] == ["26.05", "26.11"], (out, listed)
|
||||
client.succeed("rm -r /srv/channels/files/nixos-26.11")
|
||||
target.succeed("router-upgrade check >/dev/null 2>&1") # asks again
|
||||
listed = json.loads(target.succeed("cat /var/lib/router/upgrade/releases.json"))
|
||||
assert listed["releases"] == ["26.05"], listed
|
||||
target.succeed("systemctl cat router-upgrade-notice.timer | grep -q daily")
|
||||
|
||||
with subtest("a preview lists the changes and the download without fetching or touching anything"):
|
||||
before = current()
|
||||
out = target.succeed("router-upgrade preview --force 2>&1")
|
||||
|
||||
Reference in New Issue
Block a user