From 83343f7a18ee5928a01ed1eead2198719038e4fc Mon Sep 17 00:00:00 2001 From: Nils Stinnesbeck Date: Wed, 25 Nov 2026 10:37:14 +0100 Subject: [PATCH] Tag releases, and name the version on the Overview nix run .#release ends by creating the annotated tag vX.Y.Z on the released commit (the tags routers that update from the repository look for); it refuses a HEAD of another version and does nothing outside a checkout. The System card on the Overview says which nixos-router and NixOS run. Co-Authored-By: Claude Sonnet 5.5 --- SPECS.md | 2 +- flake.nix | 1 + pkgs/router-webui/dashboard.go | 5 ++- pkgs/router-webui/dashboard_test.go | 19 +++++++++++ pkgs/router-webui/templates/dashboard.html | 1 + scripts/release.sh | 38 ++++++++++++++++++++-- 6 files changed, 62 insertions(+), 4 deletions(-) diff --git a/SPECS.md b/SPECS.md index c7c7993..c12a3b6 100644 --- a/SPECS.md +++ b/SPECS.md @@ -292,7 +292,7 @@ Package upgrades (see above) 1. **Done (0.13.2):** one "Updates" page with the parts "Router software" and "Packages", one overlay and one confirmation banner, both logs. Still to do for it: one check, one preview and one apply for both (needs step 3). 2. **Done (0.13.3, fixed in 0.13.4):** the repository is hardcoded: the module option `routerUpdate.repository` (beside `routerUpdate.publicKeys`; not a `router.*` setting, so it is not in the settings, the options listing or the web UI) defaults to `https://git.stinnesbeck.com/nils/nixos-router`, is baked into `router-update` and written to `/etc/router-update-repository` for the web UI, and the page only names it (no field: a fork or a test sets the option in a module; a moved repository needs a bundle update). `router-update check` (daily timer `router-update-check`, and the page's button) lists the repository's tags with `git ls-remote`, takes the newest `vX.Y.Z` (other tags are ignored) and writes `update/check.json` (repository, time, installed, newest tag/version/revision, newer). The Overview and the Updates page show it while it is about this repository and the installed version. 3. **Done (0.13.3), without a preview:** `router-update --git TAG|latest` (the web UI's "Install"): `nix flake prefetch` of `git+?ref=refs/tags/&rev=`, then the steps of a bundle update from the serial guard on (snapshot, flake, nixpkgs pin, migration, `router-apply` with commit-confirm, rollback). The flake is the source's `config-flake.nix` with `@SOURCE@` replaced by that address, so `flake.lock` and `flake.nix` agree and nothing moves by itself (this file is a contract with every updater already installed: change it only compatibly). The release data (version, serial = the commit's time, schema = the number of `migrations/*.jq`) is read from the fetched source. No signature is checked. Still to do: preview (package changes, download and builds of both inputs), and the nixpkgs-pin interplay for a pin chosen later. - 4. Still to do: a release is a tag `vX.Y.Z` on the release commit (`router-release` tags it, still writes a bundle for the installer and offline routers) and refuses a `flake.lock` whose nixpkgs is not a channel revision (`git-revision`), so cache.nixos.org has its packages. + 4. **Tag: done (0.13.5).** A release is a tag `vX.Y.Z` on the release commit: `nix run .#release` (which still writes the bundle for the installer and offline routers) ends by creating the annotated tag, locally (push it with the branch; `--no-tag` skips it). It refuses when HEAD's `VERSION` is another version or the tag is on another commit, does nothing outside a git checkout (the VM tests), and tags last so a failed release leaves no tag. Still to do: refuse a `flake.lock` whose nixpkgs is not a channel revision (`git-revision`), so cache.nixos.org has its packages. 5. **Done:** the `update` VM test serves a repository from the builder (`common.gitServer`: `git http-backend` over HTTP) and covers the check, tags that are no releases, refused tags, install through the web UI with migration, confirm, the rebuild without the server, and "not newer". Bundles and `--url` stay (offline, installer, gitea down). diff --git a/flake.nix b/flake.nix index 4227150..dd91b71 100644 --- a/flake.nix +++ b/flake.nix @@ -222,6 +222,7 @@ name = "router-release"; runtimeInputs = with pkgs; [ nix + git gnutar coreutils jq diff --git a/pkgs/router-webui/dashboard.go b/pkgs/router-webui/dashboard.go index 490e97c..73789e4 100644 --- a/pkgs/router-webui/dashboard.go +++ b/pkgs/router-webui/dashboard.go @@ -319,6 +319,8 @@ type dashboard struct { Events []Event Charts []Chart Prefs Prefs + Version string // the installed release of nixos-router + NixOS string // the NixOS it runs on } func (a *app) dashboardData(rangeName string) dashboard { @@ -326,7 +328,8 @@ func (a *app) dashboardData(rangeName string) dashboard { now := time.Now() s, _ := loadSettings(a.sys.settingsPath()) f := s.form() - d := dashboard{Range: rg.Name, Interval: 5, Snap: a.metrics.Snapshot(), Prefs: a.sys.loadPrefs()} + d := dashboard{Range: rg.Name, Interval: 5, Snap: a.metrics.Snapshot(), Prefs: a.sys.loadPrefs(), + Version: a.sys.installedRelease().Version, NixOS: a.sys.runningVersion()} // Newest first, the last few. ev := d.Snap.Uplink.Events d.Events = make([]Event, 0, 10) diff --git a/pkgs/router-webui/dashboard_test.go b/pkgs/router-webui/dashboard_test.go index 6b2cc8f..f8709ad 100644 --- a/pkgs/router-webui/dashboard_test.go +++ b/pkgs/router-webui/dashboard_test.go @@ -155,6 +155,25 @@ func TestDashboardRenders(t *testing.T) { } } +func TestDashboardNamesTheVersion(t *testing.T) { + a, sys := newTestApp(t) + dir := t.TempDir() + sys.ReleaseFile = filepath.Join(dir, "router-release") + sys.VersionFile = filepath.Join(dir, "nixos-version") + os.WriteFile(sys.ReleaseFile, []byte(`{"version":"4.5.6"}`), 0o600) + os.WriteFile(sys.VersionFile, []byte("26.11.20261113.d5cc683\n"), 0o600) + a.sys = sys + h := a.routes() + cookie := login(t, h) + // The page and the fragment that refreshes it say what runs. + for _, path := range []string{"/", "/dashboard?range=24h"} { + body := do(h, "GET", path, nil, cookie).Body.String() + if !strings.Contains(body, "nixos-router 4.5.6") || !strings.Contains(body, "NixOS 26.11.20261113.d5cc683") { + t.Errorf("%s does not name the version:\n%s", path, body) + } + } +} + func TestBackup(t *testing.T) { a, sys := newTestApp(t) h := a.routes() diff --git a/pkgs/router-webui/templates/dashboard.html b/pkgs/router-webui/templates/dashboard.html index 48bb2be..d30e108 100644 --- a/pkgs/router-webui/templates/dashboard.html +++ b/pkgs/router-webui/templates/dashboard.html @@ -32,6 +32,7 @@

System

+ {{if $d.Version}}
Version
nixos-router {{$d.Version}}{{if $d.NixOS}} on NixOS {{$d.NixOS}}{{end}}
{{end}}
Uptime
{{age $sys.Uptime}}
{{if $sys.Kernel}}
Kernel
{{$sys.Kernel}}{{if $sys.KernelNext}} reboot to run {{$sys.KernelNext}} {{end}}
{{end}} {{if $sys.BootPending}}
Reboot
a new configuration starts at the next reboot
{{end}} diff --git a/scripts/release.sh b/scripts/release.sh index 0fcc09f..0f4ac61 100644 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -1,16 +1,23 @@ # Signs $release (a store path) as a binary cache and writes, into --out: # router-update-.bundle one file to upload in the web UI # latest, cache/ the same, laid out for `router pulls from a URL` -# usage: router-release --key KEYFILE [--out DIR] [--compression zstd|none] +# +# Run in a git checkout it also tags the commit that was released (vX.Y.Z, the +# tags routers that update from the repository look for). The tag is local: it +# has to be pushed with the branch. It is made last, so a release that fails +# leaves no tag. +# usage: router-release --key KEYFILE [--out DIR] [--compression zstd|none] [--no-tag] key="" out=dist compression=zstd +tag=1 while [ $# -gt 0 ]; do case $1 in --key) key=$2; shift ;; --out) out=$2; shift ;; --compression) compression=$2; shift ;; - *) echo "usage: router-release --key KEYFILE [--out DIR] [--compression zstd|none]" >&2; exit 2 ;; + --no-tag) tag=0 ;; + *) echo "usage: router-release --key KEYFILE [--out DIR] [--compression zstd|none] [--no-tag]" >&2; exit 2 ;; esac shift done @@ -28,3 +35,30 @@ tar -C "$out" -cf "$out/router-update-$version.bundle" latest cache echo "release $version ($(du -h "$out/router-update-$version.bundle" | cut -f1)):" echo " upload $out/router-update-$version.bundle in the router's web UI (Update)" echo " or serve $out over HTTP(S) and give the router that URL" + +if [ "$tag" -eq 1 ]; then + if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then + echo " tag none: not in a git repository" + else + head_version=$(git show HEAD:VERSION 2>/dev/null | tr -d '\n' || true) + if [ "$head_version" != "$version" ]; then + echo "router-release: the commit at HEAD is version '$head_version', not $version: not tagged" >&2 + echo " (commit the version, then: git tag -a v$version -m 'Release $version')" >&2 + exit 1 + fi + head=$(git rev-parse HEAD) + if git rev-parse -q --verify "refs/tags/v$version" >/dev/null; then + if [ "$(git rev-parse "v$version^{commit}")" != "$head" ]; then + echo "router-release: v$version is already a tag of another commit" >&2 + exit 1 + fi + echo " tag v$version exists" + else + git tag -a "v$version" -m "Release $version" + echo " tag v$version on ${head:0:7}: push it with the branch (git push origin v$version)" + fi + if [ "$(cat "$release/rev")" != "$head" ]; then + echo " note the release was built from a tree that differs from HEAD (uncommitted changes)" + fi + fi +fi