Files
nixos-router/HANDOVER.md
T
2026-11-27 21:00:11 +01:00

7.3 KiB

Handover (state at release 0.14.0, 2026-11-27)

For an agent picking up nixos-router. Read DEVELOPING.md (how to build and test) and SPECS.md (what exists and what is open) first; this file is what is not obvious from them.

State

  • Branch installed-webui, last release commit Release 0.14.0, tag v0.14.0, both pushed. main is the PR base. Releases since the unified upgrade (0.13.7): 0.13.8 (fix below), 0.14.0 (load balancers).
  • Unstaged, deliberately untouched: the mode change of scripts/webui-dev.sh. It makes the release script print "built from a tree that differs from HEAD".
  • dist/router-update-0.14.0.bundle (1.4 GB, signed) is the only bundle; delete the old one after each release.
  • Nothing is half-done. 0.14.0 passed the Go tests, fast, assertions, loadbalancer and webui; apply and update passed on the build just before the last change to the load balancer page (only loadbalancer.go), not on the final one.
  • Not yet tried: the git path against the real gitea (the VM test serves its own repository from the builder), and load balancers on the user's real router (they want one for an API on hv1/hv2; they add it in Advanced).

0.13.8: names that became static (leasesdns.go)

router-webui leases-dns publishes DHCP clients' names in Unbound. When Unbound restarted it removed, by name, what it had published before, which also removed the configuration's record if the name had become a reservation or a dns.hosts entry in that same apply (hv1/hv2). It now stores the Unbound's pid with the status and forgets (does not remove) what an older Unbound had (stillThere). Test: TestNewUnboundForgetsWhatTheOldOneHad.

Load balancers (0.14.0)

router.loadBalancers.<name> (options in modules/router/options.nix, HAProxy config in modules/router/loadbalancer.nix, port opening in firewall.nix as lbInput, assertions in assertions.nix as lbAssertions). The full description is the "Load balancers" section of SPECS.md. Things that were not obvious:

  • IPv4 and IPv6 are bound apart (bind 0.0.0.0:P and bind :::P v6only): a dual-stack socket shows IPv4 clients as ::ffff:a.b.c.d in X-Forwarded-For.
  • NixOS's own services.haproxy assertion forces the whole config text, so the generator must never fail on a bad setting (an unresolved backend is skipped there; our assertion reports it).
  • The addr column of show stat is empty. The web UI (loadbalancer.go) reads addresses from show servers state (srv_addr, srv_port). The loadbalancer VM test checks that the real HAProxy has the columns the page reads; keep it when upgrading HAProxy.
  • The stats socket is the NixOS module's /run/haproxy/haproxy.sock; System.HAProxySocket overrides it in tests.
  • A service's hosts become router.dns.hosts entries (mkDefault) pointing at the router's address in the LANs it listens in; that is how inside and outside use one name.
  • Untested: the PROXY protocol, balance = source, backendTls.verify, shared ports in a VM, the router's own ACME certificate for a service. Open: a settings form (services are edited in Advanced), backend state in /metrics and MCP, UDP, taking a backend out of service from the page.

How an upgrade works now (0.13.7)

nixos-router is an input of the configuration flake next to nixpkgs; one upgrade moves both.

  • modules/settings/upgrade.nix (router-upgrade): check reads the channel's nixpkgs revision and the repository's newest vX.Y.Z tag (git ls-remote) into /var/lib/router/upgrade/check.json. preview fetches the tag (nix flake prefetch), builds a "release dir" from the source (version, serial = commit time, schema = number of migrations/*.jq), writes the flake from config-flake.nix (@SOURCE@ replaced with git+<repo>?ref=refs/tags/vX&rev=<commit>), migrates the settings in a copy, locks it, and diffs packages into preview.json (router: {from,to,tag,rev} when nixos-router changes too). apply snapshots, copies flake + migrated settings + lock, router-apply with commit-confirm; rollback restores config.pre-update. daily is what the timer runs.
  • modules/settings/update.nix (router-update): only signed bundles (--bundle, --url, --request, web upload). The repository option routerUpdate.repository (default the real gitea) is a module option, not a setting; a test or a fork overrides it in local.nix. null disables the repository.
  • Web UI (pkgs/router-webui): upgrade.go (types, /upgrade/{check,preview,download,apply,channel}), update.go (bundle upload, progress), gitupdate.go (repository file, Overview notice), templates/update.html (the one page). Pages are Go templates with a strict CSP: no inline styles or handlers.
  • config-flake.nix is a contract with every installed updater: change it only compatibly.

Rules that cost time before

  • Run VM tests one at a time: nix run .#test -- <name> (webui ~2 min, apply ~16, update ~14, assertions ~5). Parallel runs OOM'd the machine. New files need git add -N first. nix flake check --no-build errors on these tests for unrelated reasons.
  • Edit files with the Edit/Write tools, not sed/python through Bash (the user asked for this).
  • Git commit messages and PR descriptions get no attribution lines (the user's latest instruction).
  • An assertion test (tests/assertions.nix) compares the exact number of failed assertions per case, so a case must trigger only the assertion it is about.
  • Do not commit, release, push or delete bundles until the user says so. The user's phrasing: "commit and release it as X.Y.Z when the tests pass", then "yes push it and delete the old bundle". A release is a feature commit, then a Release X.Y.Z commit bumping VERSION, then nix run .#release -- --key ~/.config/nixos-router/update.sec (builds the bundle and creates the annotated tag; push the tag explicitly: git push origin <branch> vX.Y.Z). The user's git signs tags, so tags need -a -m; the release script does that.
  • Use jq, not bash substitution, to put the source address into the flake (& is special in bash 5.2 replacements).
  • Nix against a git input needs --option flake-registry "", or it tries to download the global registry.
  • Waiting loops in tests must stop at failed and use a short ceiling (300 s); the user objected to 900 s.
  • Transient systemd-run units cannot be restarted: start a new one.

Open items (all in SPECS.md, "Not done yet")

  • Release script: refuse a flake.lock whose nixpkgs is not a channel revision (so cache.nixos.org has the packages).
  • "Reset to the release's nixpkgs" action; signed manifest / "not tested with this version" mark.
  • Real package changes in upgrade tests (they use an identical nixpkgs copy).
  • Web UI polish: folds that may jump, browser confirm dialogs, touch tooltips, word-level diff.
  • Load balancers: a settings form, backend state in /metrics and MCP, UDP, drain/maintenance from the page; tidy the indentation of the generated HAProxy config (cosmetic).
  • API apply scope for tokens, more MCP read tools; WireGuard live status; host-based routing 80/443, IPv6, multi-WAN/QoS; Prometheus alert rules and a Grafana dashboard.
  • The user's own router tasks: apply the saved port 4001 forwards to 192.168.168.254 (tcp+udp) and check, install this release and try the real git path, public ports of antigua, narrow family rules.