4 Commits
Author SHA1 Message Date
nilsandClaude Sonnet 5.5 3881c623cf Release 0.13.5
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-25 10:37:14 +01:00
nilsandClaude Sonnet 5.5 83343f7a18 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 <noreply@anthropic.com>
2026-11-25 10:37:14 +01:00
nilsandClaude Sonnet 5.5 3afd7ed4cc Release 0.13.4
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-25 10:05:08 +01:00
nilsandClaude Sonnet 5.5 ad9de15344 Hardcode the repository releases come from
routerUpdate.repository (a module option beside the update keys, not a
router.* setting) defaults to the project's repository; the Updates page names
it but no longer has a field for it. Forks and tests set it in a module.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-25 10:05:08 +01:00
17 changed files with 148 additions and 106 deletions
+2 -2
View File
@@ -290,9 +290,9 @@ Package upgrades (see above)
- **Real package changes in tests**: the upgrade tests use an identical nixpkgs copy, so no real version change is ever exercised. - **Real package changes in tests**: the upgrade tests use an identical nixpkgs copy, so no real version change is ever exercised.
- **Merge the Update and Packages pages, and take releases from git** (decided 2026-11-24, not built). The repository is public, so no key is needed on the router; trusting the git server (TLS and the tag) is enough, so no signatures on this path; the packages come from cache.nixos.org and the small parts of nixos-router are built on the router; gitea has to be reachable to update this way. Plan: - **Merge the Update and Packages pages, and take releases from git** (decided 2026-11-24, not built). The repository is public, so no key is needed on the router; trusting the git server (TLS and the tag) is enough, so no signatures on this path; the packages come from cache.nixos.org and the small parts of nixos-router are built on the router; gitea has to be reachable to update this way. Plan:
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). 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):** `router.update.repository` (an http(s) address, no credentials or query; saved like the channel, in the confirmed settings too, so it is no unapplied change). `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. 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+<repo>?ref=refs/tags/<tag>&rev=<commit>`, 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. 3. **Done (0.13.3), without a preview:** `router-update --git TAG|latest` (the web UI's "Install"): `nix flake prefetch` of `git+<repo>?ref=refs/tags/<tag>&rev=<commit>`, 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". 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). Bundles and `--url` stay (offline, installer, gitea down).
+1 -1
View File
@@ -1 +1 @@
0.13.3 0.13.5
+1 -1
View File
@@ -1,5 +1,5 @@
# The flake.nix of an installed router's configuration directory when its # The flake.nix of an installed router's configuration directory when its
# nixos-router comes from a git repository (router.update.repository). # nixos-router comes from a git repository (routerUpdate.repository).
# `router-update --git` writes it with @SOURCE@ replaced by the address of the # `router-update --git` writes it with @SOURCE@ replaced by the address of the
# release it installs (git+URL?ref=refs/tags/vX.Y.Z&rev=COMMIT), so the lock # release it installs (git+URL?ref=refs/tags/vX.Y.Z&rev=COMMIT), so the lock
# file and this file always agree and nothing moves to a newer commit by itself. # file and this file always agree and nothing moves to a newer commit by itself.
+1
View File
@@ -222,6 +222,7 @@
name = "router-release"; name = "router-release";
runtimeInputs = with pkgs; [ runtimeInputs = with pkgs; [
nix nix
git
gnutar gnutar
coreutils coreutils
jq jq
-14
View File
@@ -440,20 +440,6 @@ in
''; '';
}; };
update.repository = mkOption {
type = types.nullOr (types.strMatching "https?://[A-Za-z0-9.-]+(:[0-9]+)?(/[A-Za-z0-9._~/-]*)?");
default = null;
example = "https://git.example.org/me/nixos-router";
description = ''
A public git repository of nixos-router whose tags `vX.Y.Z` are releases.
`router-update check` (daily, and in the web UI) looks for a newer tag,
and `router-update --git` builds the router from it, like an update from
a bundle: the settings are migrated and the new version must be
confirmed. The repository is trusted (TLS and the tag), nothing is
signed on this path. null: updates come from bundles and update servers.
'';
};
update.channel = mkOption { update.channel = mkOption {
type = types.nullOr (types.strMatching "unstable|[0-9]{2}\\.[0-9]{2}"); type = types.nullOr (types.strMatching "unstable|[0-9]{2}\\.[0-9]{2}");
default = null; default = null;
+22 -6
View File
@@ -63,8 +63,8 @@ let
text = '' text = ''
usage() { usage() {
echo "usage: router-update check | [--force] (--request | --bundle FILE | --url URL | --git TAG|latest) [timeout]" >&2 echo "usage: router-update check | [--force] (--request | --bundle FILE | --url URL | --git TAG|latest) [timeout]" >&2
echo " check the newest release tag of router.update.repository, against the installed version" >&2 echo " check the newest release tag of the repository, against the installed version" >&2
echo " --git TAG build the release from a tag (vX.Y.Z, or latest) of router.update.repository" >&2 echo " --git TAG build the release from a tag (vX.Y.Z, or latest) of the repository" >&2
echo " --bundle FILE a bundle made by router-release" >&2 echo " --bundle FILE a bundle made by router-release" >&2
echo " --url URL a server with the release's latest and cache/ (HTTP or HTTPS)" >&2 echo " --url URL a server with the release's latest and cache/ (HTTP or HTTPS)" >&2
echo " --request what the web UI asked for (${updateDir}/request.json)" >&2 echo " --request what the web UI asked for (${updateDir}/request.json)" >&2
@@ -98,7 +98,7 @@ let
# The release tags of the repository, "TAG REVISION" per line (an # The release tags of the repository, "TAG REVISION" per line (an
# annotated tag counts with the commit it points to). # annotated tag counts with the commit it points to).
repository() { jq -r '.router.update.repository // empty' "$config/settings.json"; } repository() { echo ${lib.escapeShellArg (toString config.routerUpdate.repository)}; }
git_tags() { git_tags() {
git ls-remote --tags "$1" 'refs/tags/v*' | awk ' git ls-remote --tags "$1" 'refs/tags/v*' | awk '
{ n = $2; sub("^refs/tags/", "", n); peeled = (n ~ /\^\{\}$/); sub(/\^\{\}$/, "", n) { n = $2; sub("^refs/tags/", "", n); peeled = (n ~ /\^\{\}$/); sub(/\^\{\}$/, "", n)
@@ -112,7 +112,7 @@ let
# Only looks: no lock, so it runs beside an update. # Only looks: no lock, so it runs beside an update.
repo=$(repository) repo=$(repository)
if [ -z "$repo" ]; then if [ -z "$repo" ]; then
echo "router-update: no repository (router.update.repository): nothing to look at" echo "router-update: this router has no repository: nothing to look at"
exit 0 exit 0
fi fi
tags=$(git_tags "$repo") || die "cannot read the tags of $repo" tags=$(git_tags "$repo") || die "cannot read the tags of $repo"
@@ -170,7 +170,7 @@ let
if [ "$mode" = git ]; then if [ "$mode" = git ]; then
repo=$(repository) repo=$(repository)
[ -n "$repo" ] || die "no repository: set router.update.repository" [ -n "$repo" ] || die "this router has no repository to update from"
tags=$(git_tags "$repo") || die "cannot read the tags of $repo" tags=$(git_tags "$repo") || die "cannot read the tags of $repo"
if [ -z "$arg" ] || [ "$arg" = latest ]; then if [ -z "$arg" ] || [ "$arg" = latest ]; then
found=$(tail -n 1 <<<"$tags") found=$(tail -n 1 <<<"$tags")
@@ -268,6 +268,20 @@ in
default = null; default = null;
description = "Version, serial, revision and settings schema of this nixos-router (`/etc/router-release`)."; description = "Version, serial, revision and settings schema of this nixos-router (`/etc/router-release`).";
}; };
routerUpdate.repository = lib.mkOption {
type = lib.types.nullOr (lib.types.strMatching "https?://[A-Za-z0-9.-]+(:[0-9]+)?(/[A-Za-z0-9._~/-]*)?");
default = "https://git.stinnesbeck.com/nils/nixos-router";
example = "https://git.example.org/me/nixos-router";
description = ''
The public git repository of nixos-router whose tags `vX.Y.Z` are
releases. `router-update check` (daily, and in the web UI) looks for a
newer tag, and `router-update --git` builds the router from it, like an
update from a bundle. The repository is trusted (TLS and the tag),
nothing is signed on this path. It belongs to the installed version, not
to the settings: a fork or a test sets it in a module. null: updates
come from bundles and update servers only.
'';
};
routerUpdate.publicKeys = lib.mkOption { routerUpdate.publicKeys = lib.mkOption {
type = lib.types.listOf lib.types.str; type = lib.types.listOf lib.types.str;
default = [ ]; default = [ ];
@@ -284,6 +298,8 @@ in
if config.routerSettings.release == null then { } else config.routerSettings.release if config.routerSettings.release == null then { } else config.routerSettings.release
); );
environment.etc."router-update-keys".text = lib.concatLines keys; environment.etc."router-update-keys".text = lib.concatLines keys;
# For the web UI.
environment.etc."router-update-repository".text = toString config.routerUpdate.repository;
environment.systemPackages = [ environment.systemPackages = [
update update
restore restore
@@ -305,7 +321,7 @@ in
router.rollback.onRollback = "${restore}/bin/router-update-restore"; router.rollback.onRollback = "${restore}/bin/router-update-restore";
router.rollback.onConfirm = "rm -rf ${snapshot}"; router.rollback.onConfirm = "rm -rf ${snapshot}";
# Is there a newer release in router.update.repository? Once a day, and when # Is there a newer release in the repository? Once a day, and when
# the web UI asks. It only reads the repository's tag list. # the web UI asks. It only reads the repository's tag list.
systemd.services.router-update-check = { systemd.services.router-update-check = {
description = "Look for a newer release of nixos-router"; description = "Look for a newer release of nixos-router";
+4 -1
View File
@@ -319,6 +319,8 @@ type dashboard struct {
Events []Event Events []Event
Charts []Chart Charts []Chart
Prefs Prefs Prefs Prefs
Version string // the installed release of nixos-router
NixOS string // the NixOS it runs on
} }
func (a *app) dashboardData(rangeName string) dashboard { func (a *app) dashboardData(rangeName string) dashboard {
@@ -326,7 +328,8 @@ func (a *app) dashboardData(rangeName string) dashboard {
now := time.Now() now := time.Now()
s, _ := loadSettings(a.sys.settingsPath()) s, _ := loadSettings(a.sys.settingsPath())
f := s.form() 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. // Newest first, the last few.
ev := d.Snap.Uplink.Events ev := d.Snap.Uplink.Events
d.Events = make([]Event, 0, 10) d.Events = make([]Event, 0, 10)
+19
View File
@@ -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) { func TestBackup(t *testing.T) {
a, sys := newTestApp(t) a, sys := newTestApp(t)
h := a.routes() h := a.routes()
+24 -39
View File
@@ -3,21 +3,20 @@ package main
import ( import (
"net/http" "net/http"
"net/url" "net/url"
"os"
"path/filepath" "path/filepath"
"regexp" "regexp"
"strings" "strings"
) )
// Updates from a git repository (router.update.repository): router-update // Updates from a git repository: router-update check looks at the
// check looks at the repository's release tags (vX.Y.Z) once a day and when the // repository's release tags (vX.Y.Z) once a day and when the page asks, and
// page asks, and writes what it found to update/check.json; installing builds // writes what it found to update/check.json; installing builds the router
// the router from a tag, like an update from a bundle. // from a tag, like an update from a bundle. The repository is part of the
// installed version (routerUpdate.repository, written to
// /etc/router-update-repository), not something the page sets.
var ( var releaseTagRe = regexp.MustCompile(`^v[0-9]+\.[0-9]+\.[0-9]+$`)
// The same shape the option accepts: no credentials, no query.
repositoryRe = regexp.MustCompile(`^https?://[A-Za-z0-9.-]+(:[0-9]+)?(/[A-Za-z0-9._~/-]*)?$`)
releaseTagRe = regexp.MustCompile(`^v[0-9]+\.[0-9]+\.[0-9]+$`)
)
// GitCheck is update/check.json: the newest release tag of the repository. // GitCheck is update/check.json: the newest release tag of the repository.
type GitCheck struct { type GitCheck struct {
@@ -32,14 +31,23 @@ type GitCheck struct {
Newer bool `json:"newer"` Newer bool `json:"newer"`
} }
func (s Settings) repository() string { return str(s, "router", "update", "repository") } // repository is where releases come from ("" if the router has none).
func (s System) repository() string {
path := s.RepositoryFile
if path == "" {
path = "/etc/router-update-repository"
}
data, _ := os.ReadFile(path)
return strings.TrimSpace(string(data))
}
const gitCheckUnit = "router-update-check.service" const gitCheckUnit = "router-update-check.service"
// gitCheck is what the last check found, if it is still about this repository // gitCheck is what the last check found, if it is still about this repository
// and this installed version. // and this installed version.
func (a *app) gitCheck(repository string) *GitCheck { func (a *app) gitCheck() *GitCheck {
var c GitCheck var c GitCheck
repository := a.sys.repository()
if repository == "" || !readUpgradeFile(filepath.Join(a.sys.updateDir(), "check.json"), &c) { if repository == "" || !readUpgradeFile(filepath.Join(a.sys.updateDir(), "check.json"), &c) {
return nil return nil
} }
@@ -52,37 +60,15 @@ func (a *app) gitCheck(repository string) *GitCheck {
// newRouterVersion is the version of a release that is out and not installed, // newRouterVersion is the version of a release that is out and not installed,
// for the Overview ("" if there is none or nothing was checked). // for the Overview ("" if there is none or nothing was checked).
func (a *app) newRouterVersion() string { func (a *app) newRouterVersion() string {
s, err := loadSettings(a.sys.settingsPath()) if c := a.gitCheck(); c != nil && c.Newer {
if err != nil {
return ""
}
if c := a.gitCheck(s.repository()); c != nil && c.Newer {
return c.Newest.Version return c.Newest.Version
} }
return "" return ""
} }
func (a *app) updateSaveRepository(w http.ResponseWriter, r *http.Request, _ session) {
v := strings.TrimRight(strings.TrimSpace(r.PostFormValue("repository")), "/")
if !r.PostForm.Has("repository") {
a.updateBack(w, r, "Not saved: no address was sent.")
return
}
if v != "" && !repositoryRe.MatchString(v) {
a.updateBack(w, r, "Not saved: an http:// or https:// address of a public repository, without credentials or a query.")
return
}
if err := a.sys.setUpdateField("repository", v); err != nil {
a.updateBack(w, r, "Not saved: "+err.Error())
return
}
a.updateBack(w, r, "Saved.")
}
func (a *app) updateGitCheck(w http.ResponseWriter, r *http.Request, _ session) { func (a *app) updateGitCheck(w http.ResponseWriter, r *http.Request, _ session) {
s, err := loadSettings(a.sys.settingsPath()) if a.sys.repository() == "" {
if err != nil || s.repository() == "" { a.updateBack(w, r, "This router has no repository to look at.")
a.updateBack(w, r, "Set the repository first.")
return return
} }
if err := startUnit(gitCheckUnit); err != nil { if err := startUnit(gitCheckUnit); err != nil {
@@ -102,9 +88,8 @@ func (a *app) updateGitInstall(w http.ResponseWriter, r *http.Request, _ session
a.updateBack(w, r, "Not a release tag: "+url.QueryEscape(tag)) a.updateBack(w, r, "Not a release tag: "+url.QueryEscape(tag))
return return
} }
s, err := loadSettings(a.sys.settingsPath()) if a.sys.repository() == "" {
if err != nil || s.repository() == "" { a.updateBack(w, r, "This router has no repository to update from.")
a.updateBack(w, r, "Set the repository first.")
return return
} }
if err := a.sys.requestUpdate("git", tag, r.PostFormValue("force") == "on"); err != nil { if err := a.sys.requestUpdate("git", tag, r.PostFormValue("force") == "on"); err != nil {
+21 -22
View File
@@ -9,9 +9,13 @@ import (
"testing" "testing"
) )
const testRepository = "https://git.example.org/me/nixos-router"
func TestUpdatesFromGit(t *testing.T) { func TestUpdatesFromGit(t *testing.T) {
a, sys := newTestApp(t) a, sys := newTestApp(t)
sys.ReleaseFile = filepath.Join(t.TempDir(), "router-release") dir := t.TempDir()
sys.ReleaseFile = filepath.Join(dir, "router-release")
sys.RepositoryFile = filepath.Join(dir, "router-update-repository")
os.WriteFile(sys.ReleaseFile, []byte(`{"version":"1.0.0","serial":1000}`), 0o600) os.WriteFile(sys.ReleaseFile, []byte(`{"version":"1.0.0","serial":1000}`), 0o600)
a.sys = sys a.sys = sys
orig := startUnit orig := startUnit
@@ -26,26 +30,24 @@ func TestUpdatesFromGit(t *testing.T) {
return do(h, "POST", path, form, cookie).Header().Get("Location") return do(h, "POST", path, form, cookie).Header().Get("Location")
} }
// The repository: an address of a public repository, nothing else. // A router without a repository has nothing to look at.
for _, bad := range []string{"git@git.example.org:me/r.git", "https://user:pw@git.example.org/r", "https://git.example.org/r?x=1", "file:///etc", "https://git.example.org/a b"} { if loc := post("/update/gitcheck", url.Values{}); !strings.Contains(loc, "no+repository") || len(started) != 0 {
if loc := post("/update/repository", url.Values{"repository": {bad}}); !strings.Contains(loc, "Not+saved") {
t.Errorf("%q was accepted: %s", bad, loc)
}
}
if loc := post("/update/gitcheck", url.Values{}); !strings.Contains(loc, "Set+the+repository") || len(started) != 0 {
t.Fatalf("a check without a repository: %q %v", loc, started) t.Fatalf("a check without a repository: %q %v", loc, started)
} }
if loc := post("/update/gitinstall", url.Values{"tag": {"v1.1.0"}}); !strings.Contains(loc, "Set+the+repository") { if loc := post("/update/gitinstall", url.Values{"tag": {"v1.1.0"}}); !strings.Contains(loc, "no+repository") {
t.Fatalf("an install without a repository: %q", loc) t.Fatalf("an install without a repository: %q", loc)
} }
post("/update/repository", url.Values{"repository": {"https://git.example.org/me/nixos-router/"}}) if rec := do(h, "POST", "/update/repository", url.Values{"csrf": {token}, "repository": {"https://evil.example.org/r"}}, cookie); rec.Code != 404 && rec.Code != 405 {
s, _ := loadSettings(sys.settingsPath()) t.Fatalf("the repository can be set from the page: %d", rec.Code)
if got := s.repository(); got != "https://git.example.org/me/nixos-router" {
t.Fatalf("repository: %q", got)
} }
// It takes effect when updating, so it is no unapplied change. if body := do(h, "GET", "/update", nil, cookie).Body.String(); strings.Contains(body, `name="repository"`) {
if c, err := loadSettings(sys.confirmedPath()); err == nil && c.repository() != "" { t.Fatalf("the page has a field for the repository:\n%s", body)
t.Logf("confirmed settings carry it: %q", c.repository()) }
// The repository is the installed version's; the page names it.
os.WriteFile(sys.RepositoryFile, []byte(testRepository+"\n"), 0o644)
if body := do(h, "GET", "/update", nil, cookie).Body.String(); !strings.Contains(body, testRepository) || !strings.Contains(body, "Not looked yet") {
t.Fatalf("the page does not say which repository:\n%s", body)
} }
// Looking starts the unit; what it found is shown while it is about this repository and version. // Looking starts the unit; what it found is shown while it is about this repository and version.
@@ -53,9 +55,6 @@ func TestUpdatesFromGit(t *testing.T) {
if len(started) != 1 || started[0] != "router-update-check.service" { if len(started) != 1 || started[0] != "router-update-check.service" {
t.Fatalf("started %v", started) t.Fatalf("started %v", started)
} }
if body := do(h, "GET", "/update", nil, cookie).Body.String(); !strings.Contains(body, "Not looked yet") {
t.Fatalf("a result before any look:\n%s", body)
}
write := func(repo, installed string, newer bool) { write := func(repo, installed string, newer bool) {
os.MkdirAll(sys.updateDir(), 0o755) os.MkdirAll(sys.updateDir(), 0o755)
data, _ := json.Marshal(map[string]any{"repository": repo, "time": "2026-11-26T08:00:00Z", "installed": installed, data, _ := json.Marshal(map[string]any{"repository": repo, "time": "2026-11-26T08:00:00Z", "installed": installed,
@@ -66,17 +65,17 @@ func TestUpdatesFromGit(t *testing.T) {
if body := do(h, "GET", "/", nil, cookie).Body.String(); strings.Contains(body, "is out") { if body := do(h, "GET", "/", nil, cookie).Body.String(); strings.Contains(body, "is out") {
t.Fatalf("a notice from another repository:\n%s", body) t.Fatalf("a notice from another repository:\n%s", body)
} }
write("https://git.example.org/me/nixos-router", "0.9.0", true) write(testRepository, "0.9.0", true)
if body := do(h, "GET", "/", nil, cookie).Body.String(); strings.Contains(body, "is out") { if body := do(h, "GET", "/", nil, cookie).Body.String(); strings.Contains(body, "is out") {
t.Fatalf("a notice from before the last update:\n%s", body) t.Fatalf("a notice from before the last update:\n%s", body)
} }
write("https://git.example.org/me/nixos-router", "1.0.0", true) write(testRepository, "1.0.0", true)
for _, path := range []string{"/", "/update"} { for _, path := range []string{"/", "/update"} {
if body := do(h, "GET", path, nil, cookie).Body.String(); !strings.Contains(body, "1.1.0") || (path == "/" && !strings.Contains(body, "nixos-router 1.1.0 is out")) { if body := do(h, "GET", path, nil, cookie).Body.String(); !strings.Contains(body, "1.1.0") || (path == "/" && !strings.Contains(body, "nixos-router 1.1.0 is out")) {
t.Fatalf("%s lacks the release:\n%s", path, body) t.Fatalf("%s lacks the release:\n%s", path, body)
} }
} }
write("https://git.example.org/me/nixos-router", "1.0.0", false) write(testRepository, "1.0.0", false)
if body := do(h, "GET", "/", nil, cookie).Body.String(); strings.Contains(body, "nixos-router 1.1.0 is out") { if body := do(h, "GET", "/", nil, cookie).Body.String(); strings.Contains(body, "nixos-router 1.1.0 is out") {
t.Fatalf("a notice when up to date") t.Fatalf("a notice when up to date")
} }
-1
View File
@@ -341,7 +341,6 @@ func (a *app) routes() http.Handler {
mux.HandleFunc("POST /update/url", a.auth(a.updateSaveURL)) mux.HandleFunc("POST /update/url", a.auth(a.updateSaveURL))
mux.HandleFunc("POST /update/check", a.auth(a.updateCheck)) mux.HandleFunc("POST /update/check", a.auth(a.updateCheck))
mux.HandleFunc("POST /update/install", a.auth(a.updateInstall)) mux.HandleFunc("POST /update/install", a.auth(a.updateInstall))
mux.HandleFunc("POST /update/repository", a.auth(a.updateSaveRepository))
mux.HandleFunc("POST /update/gitcheck", a.auth(a.updateGitCheck)) mux.HandleFunc("POST /update/gitcheck", a.auth(a.updateGitCheck))
mux.HandleFunc("POST /update/gitinstall", a.auth(a.updateGitInstall)) mux.HandleFunc("POST /update/gitinstall", a.auth(a.updateGitInstall))
mux.HandleFunc("POST /update/upload", a.updateUpload) mux.HandleFunc("POST /update/upload", a.updateUpload)
+2
View File
@@ -21,6 +21,8 @@ type System struct {
StateDir string // /var/lib/router: secrets, UI state StateDir string // /var/lib/router: secrets, UI state
// ReleaseFile describes the installed nixos-router; /etc/router-release if empty. // ReleaseFile describes the installed nixos-router; /etc/router-release if empty.
ReleaseFile string ReleaseFile string
// RepositoryFile holds the git repository releases come from; /etc/router-update-repository if empty.
RepositoryFile string
// VersionFile holds the running NixOS version; /run/current-system/nixos-version if empty. // VersionFile holds the running NixOS version; /run/current-system/nixos-version if empty.
VersionFile string VersionFile string
// LeasesDNSDir is where leases-dns leaves its status; /run/router-leases-dns if empty. // LeasesDNSDir is where leases-dns leaves its status; /run/router-leases-dns if empty.
@@ -32,6 +32,7 @@
<section class="card"> <section class="card">
<h2>System</h2> <h2>System</h2>
<dl> <dl>
{{if $d.Version}}<dt>Version</dt><dd>nixos-router {{$d.Version}}{{if $d.NixOS}} <span class="muted">on NixOS {{$d.NixOS}}</span>{{end}}</dd>{{end}}
<dt>Uptime</dt><dd>{{age $sys.Uptime}}</dd> <dt>Uptime</dt><dd>{{age $sys.Uptime}}</dd>
{{if $sys.Kernel}}<dt>Kernel</dt><dd>{{$sys.Kernel}}{{if $sys.KernelNext}} <span class="bad">reboot to run {{$sys.KernelNext}}</span> <button type="button" class="link" data-dialog="Reboot the router now? Routing stops for a minute or two." data-dialog-ok="Reboot" data-post="/reboot">Reboot</button>{{end}}</dd>{{end}} {{if $sys.Kernel}}<dt>Kernel</dt><dd>{{$sys.Kernel}}{{if $sys.KernelNext}} <span class="bad">reboot to run {{$sys.KernelNext}}</span> <button type="button" class="link" data-dialog="Reboot the router now? Routing stops for a minute or two." data-dialog-ok="Reboot" data-post="/reboot">Reboot</button>{{end}}</dd>{{end}}
{{if $sys.BootPending}}<dt>Reboot</dt><dd><span class="bad">a new configuration starts at the next reboot</span> <button type="button" class="link" data-dialog="Reboot the router now? Routing stops for a minute or two." data-dialog-ok="Reboot" data-post="/reboot">Reboot</button></dd>{{end}} {{if $sys.BootPending}}<dt>Reboot</dt><dd><span class="bad">a new configuration starts at the next reboot</span> <button type="button" class="link" data-dialog="Reboot the router now? Routing stops for a minute or two." data-dialog-ok="Reboot" data-post="/reboot">Reboot</button></dd>{{end}}
+4 -9
View File
@@ -40,15 +40,10 @@
<section> <section>
<h2>Releases from git</h2> <h2>Releases from git</h2>
<p>The router looks once a day at the release tags (<code>vX.Y.Z</code>) of a public repository and says here and on the <p>The router looks once a day at the release tags (<code>vX.Y.Z</code>) of <code>{{or $u.Repository "no repository"}}</code>
Overview when a newer one exists. Installing builds it on the router, like a bundle: the settings are kept (and and says here and on the Overview when a newer one exists. Installing builds it on the router, like a bundle: the
migrated), and the new version must be confirmed afterwards, or the router goes back. The repository is trusted settings are kept (and migrated), and the new version must be confirmed afterwards, or the router goes back. The
as it is: nothing is signed on this path.</p> repository is trusted as it is: nothing is signed on this path.</p>
<form method="post" action="/update/repository" class="actions">
<input type="hidden" name="csrf" value="{{.CSRF}}">
<label>Repository <input name="repository" value="{{$u.Repository}}" size="44" placeholder="https://git.example.org/me/nixos-router"></label>
<button class="secondary">Save</button>
</form>
{{if $u.Repository}} {{if $u.Repository}}
<form method="post" action="/update/gitcheck" class="actions"> <form method="post" action="/update/gitcheck" class="actions">
<input type="hidden" name="csrf" value="{{.CSRF}}"> <input type="hidden" name="csrf" value="{{.CSRF}}">
+3 -5
View File
@@ -277,7 +277,7 @@ type updateData struct {
OfferErr string OfferErr string
Pending bool // an update waits for confirmation Pending bool // an update waits for confirmation
Repository string // router.update.repository Repository string // routerUpdate.repository
Git *GitCheck // what the last look at it found Git *GitCheck // what the last look at it found
GitRun UpdateStatus // the look that is running or ran last GitRun UpdateStatus // the look that is running or ran last
} }
@@ -291,10 +291,8 @@ func (a *app) updateData() updateData {
Pending: st.RollbackIn > 0, Pending: st.RollbackIn > 0,
GitRun: unitRun(gitCheckUnit), GitRun: unitRun(gitCheckUnit),
} }
if s, err := loadSettings(a.sys.settingsPath()); err == nil { d.Repository = a.sys.repository()
d.Repository = s.repository() d.Git = a.gitCheck()
d.Git = a.gitCheck(d.Repository)
}
d.Progress, d.Step = updateProgress(d.Status.Log) d.Progress, d.Step = updateProgress(d.Status.Log)
return d return d
} }
+36 -2
View File
@@ -1,16 +1,23 @@
# Signs $release (a store path) as a binary cache and writes, into --out: # Signs $release (a store path) as a binary cache and writes, into --out:
# router-update-<version>.bundle one file to upload in the web UI # router-update-<version>.bundle one file to upload in the web UI
# latest, cache/ the same, laid out for `router pulls from a URL` # 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="" key=""
out=dist out=dist
compression=zstd compression=zstd
tag=1
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
case $1 in case $1 in
--key) key=$2; shift ;; --key) key=$2; shift ;;
--out) out=$2; shift ;; --out) out=$2; shift ;;
--compression) compression=$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 esac
shift shift
done 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 "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 " 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" 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
+7 -3
View File
@@ -125,6 +125,8 @@ let
{ {
imports = [ (modulesPath + "/testing/test-instrumentation.nix") ]; imports = [ (modulesPath + "/testing/test-instrumentation.nix") ];
router.rollback.timeout = "90s"; router.rollback.timeout = "90s";
# Releases from git: the builder's repository, not the real one.
routerUpdate.repository = "http://${builderIp}:8005/router.git";
routerSettings.upgrade = { routerSettings.upgrade = {
channelsUrl = "http://192.168.10.60:8080"; channelsUrl = "http://192.168.10.60:8080";
nixpkgsRef = "path:/var/lib/newer-nixpkgs?lastModified=${toString self.inputs.nixpkgs.lastModified}&rev=%rev%"; nixpkgsRef = "path:/var/lib/newer-nixpkgs?lastModified=${toString self.inputs.nixpkgs.lastModified}&rev=%rev%";
@@ -390,13 +392,15 @@ pkgs.testers.runNixOSTest {
builder.succeed("systemd-run --unit=git-server /etc/git-server.py /srv/git 8005") builder.succeed("systemd-run --unit=git-server /etc/git-server.py /srv/git 8005")
builder.wait_for_open_port(8005, "${builderIp}") builder.wait_for_open_port(8005, "${builderIp}")
# Nothing to look at until a repository is named. # The repository is part of the installed version; the page names it and has no field for it.
assert "no repository" in target.succeed("router-update check 2>&1") assert target.succeed("cat /etc/router-update-repository").strip() == repo
login() login()
token = csrf("/update") token = csrf("/update")
page = builder.succeed(f"curl -sk -b /tmp/jar {ui}/update")
assert repo in page and 'name="repository"' not in page, page
form = lambda path, data: builder.succeed( form = lambda path, data: builder.succeed(
f"curl -sk -b /tmp/jar -o /tmp/out -w '%{{http_code}}' --data-urlencode csrf={token} {data} {ui}{path}").strip() f"curl -sk -b /tmp/jar -o /tmp/out -w '%{{http_code}}' --data-urlencode csrf={token} {data} {ui}{path}").strip()
assert form("/update/repository", f"--data-urlencode repository={repo}/") == "303" assert form("/update/repository", f"--data-urlencode repository={repo}") in ("404", "405")
assert form("/update/gitcheck", "") == "303" assert form("/update/gitcheck", "") == "303"
target.wait_until_succeeds( target.wait_until_succeeds(
"test $(systemctl show -p ActiveState --value router-update-check.service) = inactive" "test $(systemctl show -p ActiveState --value router-update-check.service) = inactive"