Put the Update and Packages pages on one Updates page
Router software and packages are two parts of one page, with one overlay, one confirmation banner and both logs. /upgrade redirects to it; the actions keep their addresses. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -234,7 +234,7 @@ Upgrading nixpkgs (the kernel and every package) on the router, without a new re
|
||||
- **`download`**: fetches and builds it (needs 3 GiB free), so a flaky uplink does not matter at `apply`.
|
||||
- **`apply [timeout]`**: takes the previewed lock into the configuration directory and runs `router-apply` (commit-confirm). The directory as it was is kept in `config.pre-update` like for updates: a rollback or a failed build puts the lock back. Refused if the configuration flake changed since the preview.
|
||||
- **Pin**: `nixpkgs-pin.json` in the configuration directory (channel, revision, flake reference with `narHash`). `router-update` locks it again after it installs a new release of nixos-router, so a release does not undo an upgrade; the reference is found in the store by its hash, offline.
|
||||
- **Web UI page** `/upgrade` ("Packages", under System): the channel as a select (none, `unstable`, and the stable releases in `stableChannels` in `upgrade.go`, 26.05 for now, until the router can ask the channel server which exist: the running release says nothing, since nixos-unstable already calls itself the next one; a configured channel that is none of these stays listed; saved to `settings.json` and the confirmed settings, so it never shows as unapplied), buttons Check, Preview (with "look anyway" when up to date), Download now and Upgrade. The preview shows the version table, download size, local builds (a warning above 50) and a reboot note for a new kernel. The page asks for a step in `upgrade/request.json` and starts `router-upgrade.service`, which runs `router-upgrade --request` (not restarted or stopped by a switch, like `router-apply`); it shows `check.json`/`preview.json` (not those of another channel, nor a check from before the last upgrade) and `upgrade/last.log`, which the unit tees (a finished one-shot unit has no journal to find). Download and Upgrade need a preview and no change waiting for confirmation; a request without a `channel` field is refused rather than clearing it.
|
||||
- **Web UI page** (since 0.13.2 the "Updates" page `/update`, the packages part at `#packages`; `GET /upgrade` redirects there, the `POST /upgrade/*` actions are unchanged; before, "Packages" was a page of its own): the channel as a select (none, `unstable`, and the stable releases in `stableChannels` in `upgrade.go`, 26.05 for now, until the router can ask the channel server which exist: the running release says nothing, since nixos-unstable already calls itself the next one; a configured channel that is none of these stays listed; saved to `settings.json` and the confirmed settings, so it never shows as unapplied), buttons Check, Preview (with "look anyway" when up to date), Download now and Upgrade. The preview shows the version table, download size, local builds (a warning above 50) and a reboot note for a new kernel. The page asks for a step in `upgrade/request.json` and starts `router-upgrade.service`, which runs `router-upgrade --request` (not restarted or stopped by a switch, like `router-apply`); it shows `check.json`/`preview.json` (not those of another channel, nor a check from before the last upgrade) and `upgrade/last.log`, which the unit tees (a finished one-shot unit has no journal to find). Download and Upgrade need a preview and no change waiting for confirmation; a request without a `channel` field is refused rather than clearing it.
|
||||
- **Module options** (for tests): `routerSettings.upgrade.channelsUrl`, `routerSettings.upgrade.nixpkgsRef` (`%rev%`).
|
||||
- **Test** (`apply`): the channel is a small HTTP server on the client that redirects like channels.nixos.org, and the "newer" nixpkgs is the installed one under a `path:` reference with the same `lastModified` and `rev`: a really different nixpkgs cannot be built offline (any version change rebuilds the NixOS tools). Covers check, preview (including the package-list rules), download, an unconfirmed upgrade rolled back with its lock and pin, a confirmed one, and a failing build.
|
||||
|
||||
@@ -284,6 +284,24 @@ On the user's own router (settings and infrastructure, not code)
|
||||
5. **Web UI and remote access** — pages for every setting, themes, MCP server, REST API. *Done* (0.12.0); see "Not done yet".
|
||||
|
||||
Package upgrades (see above)
|
||||
- **New NixOS release**: look for newer `nixos-YY.MM` branches and say so; mark releases the installed nixos-router was not tested with.
|
||||
- **Tested revisions**: a signed manifest in the release naming the nixpkgs revisions the tests passed on, as a gate in front of the channel's tip.
|
||||
- **New NixOS release**: *done in 0.13.1* (the notice and the channel list). Still open: mark releases the installed nixos-router was not tested with.
|
||||
- **Tested revisions**: a signed manifest in the release naming the nixpkgs revisions the tests passed on, as a gate in front of the channel's tip (the "not tested" mark depends on it).
|
||||
- **Reset**: go back to the nixpkgs that came with the release (`channel = null` and remove the pin).
|
||||
- **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:
|
||||
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. `router.update.repository` (a git URL). A daily check (`git ls-remote --tags`, newest `vX.Y.Z`) shows "0.x.y is available" on the Overview, like the release notice.
|
||||
3. Preview and apply lock the configuration flake to the tag (`--override-input nixos-router git+<url>?rev=…`) next to the nixpkgs pin, evaluate once and show the package changes, download and builds of both together; the serial guard and the settings migration run as for bundles.
|
||||
4. A release is a tag on the commit (`router-release` can still write a bundle for offline routers and the installer). The nixpkgs in the repository's `flake.lock` must be a revision of a channel (`git-revision`), so cache.nixos.org has its packages.
|
||||
5. VM test with a git server in the client VM (`git+http://`), as `channelServer` stands in for channels.nixos.org.
|
||||
Bundles and `--url` stay (offline, installer, gitea down).
|
||||
|
||||
Web UI polish (list of 2026-11-24)
|
||||
- Folds inside panels (Packages "What is built here", WireGuard) may jump like the certificate log did.
|
||||
- Other confirmations still use the browser's dialog, not the in-page box; tooltips (firewall headers) do not work on touch; the diff does not mark changed words.
|
||||
|
||||
Monitoring
|
||||
- Alert rules and a Grafana dashboard for the Prometheus metrics; per-LAN traffic.
|
||||
|
||||
On the user's own router
|
||||
- Apply the saved port 4001 forwards (to 192.168.168.254, tcp+udp) and check them end to end (a NodePort 30401 would need `toPort`); install 0.13.1 and look at the Prometheus page and the release notice.
|
||||
|
||||
@@ -270,7 +270,7 @@ func newApp(sys System, metrics *Collector, dev bool) *app {
|
||||
func (a *app) parseTemplates() (map[string]*template.Template, error) {
|
||||
files := map[string][]string{"overview": {"templates/dashboard.html"}}
|
||||
pages := map[string]*template.Template{}
|
||||
for _, page := range []string{"login", "overview", "network", "dhcp", "dns", "wireguard", "firewall", "ddns", "dnsproviders", "certificate", "exporter", "advanced", "update", "upgrade", "tokens", "changes"} {
|
||||
for _, page := range []string{"login", "overview", "network", "dhcp", "dns", "wireguard", "firewall", "ddns", "dnsproviders", "certificate", "exporter", "advanced", "update", "tokens", "changes"} {
|
||||
t, err := template.New("layout.html").Funcs(a.funcs).
|
||||
ParseFS(assets, append([]string{"templates/layout.html", "templates/" + page + ".html"}, files[page]...)...)
|
||||
if err != nil {
|
||||
@@ -342,7 +342,7 @@ func (a *app) routes() http.Handler {
|
||||
mux.HandleFunc("POST /update/check", a.auth(a.updateCheck))
|
||||
mux.HandleFunc("POST /update/install", a.auth(a.updateInstall))
|
||||
mux.HandleFunc("POST /update/upload", a.updateUpload)
|
||||
mux.HandleFunc("GET /upgrade", a.auth(a.upgradePage))
|
||||
mux.HandleFunc("GET /upgrade", a.auth(upgradeRedirect))
|
||||
mux.HandleFunc("POST /upgrade/channel", a.auth(a.upgradeChannel))
|
||||
mux.HandleFunc("POST /upgrade/{step}", a.auth(a.upgradeStep))
|
||||
mux.HandleFunc("/mcp", a.mcp)
|
||||
|
||||
@@ -52,6 +52,8 @@ main { padding: 1.5rem clamp(1rem, 3vw, 3rem) 3rem; }
|
||||
.cols { columns: 38rem 3; column-gap: 1.5rem; }
|
||||
.cols > section, .cols > fieldset, .cols > form > fieldset { break-inside: avoid; }
|
||||
.cols > section.busy, .cols > section.pending, .cols > section.notice { column-span: all; }
|
||||
.cols > h2.part { column-span: all; margin: 1rem 0 .2rem; padding-bottom: .3rem; border-bottom: 1px solid var(--line); font-size: 1.1rem; }
|
||||
.cols > h2.part:first-child { margin-top: 0; }
|
||||
/* 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; }
|
||||
|
||||
@@ -29,8 +29,7 @@
|
||||
<a href="/prometheus"{{if eq .Title "Prometheus"}} aria-current="page"{{end}}>Prometheus</a>
|
||||
</div>
|
||||
<div class="group"><span>System</span>
|
||||
<a href="/update"{{if eq .Title "Update"}} aria-current="page"{{end}}>Update</a>
|
||||
<a href="/upgrade"{{if eq .Title "Packages"}} aria-current="page"{{end}}>Packages</a>
|
||||
<a href="/update"{{if eq .Title "Updates"}} aria-current="page"{{end}}>Updates</a>
|
||||
<a href="/tokens"{{if eq .Title "API access"}} aria-current="page"{{end}}>API access</a>
|
||||
<a href="/advanced"{{if eq .Title "Advanced"}} aria-current="page"{{end}}>Advanced</a>
|
||||
</div>
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
</section>
|
||||
{{end}}
|
||||
{{with .Data.NewRelease}}
|
||||
<section class="notice"><p>NixOS {{.}} is out. <a href="/upgrade">See what it would change</a>.</p></section>
|
||||
<section class="notice"><p>NixOS {{.}} is out. <a href="/update#packages">See what it would change</a>.</p></section>
|
||||
{{end}}
|
||||
|
||||
<div id="dashboard" data-range="{{.Data.Dashboard.Range}}" data-interval="{{.Data.Dashboard.Interval}}">
|
||||
|
||||
@@ -1,31 +1,43 @@
|
||||
{{define "content"}}
|
||||
<div class="cols">
|
||||
{{$d := .Data}}
|
||||
<section>
|
||||
<h2>Installed</h2>
|
||||
<dl>
|
||||
<dt>Version</dt><dd>{{or $d.Installed.Version "unknown"}}{{if $d.Installed.Rev}} <span class="muted">{{$d.Installed.Rev}}</span>{{end}}</dd>
|
||||
<dt>Settings schema</dt><dd>{{$d.Installed.Schema}}</dd>
|
||||
</dl>
|
||||
</section>
|
||||
{{$u := .Data.Update}}{{$g := .Data.Upgrade}}
|
||||
|
||||
{{if $d.Status.Running}}
|
||||
{{if $u.Status.Running}}
|
||||
<div class="upload-overlay" role="dialog" aria-modal="true">
|
||||
<div class="upload-card wide">
|
||||
<h2>Updating…</h2>
|
||||
<progress max="100" value="{{$d.Progress}}"></progress>
|
||||
<p>{{$d.Step}}</p>
|
||||
{{if $d.Status.Log}}<pre class="log">{{$d.Status.Log}}</pre>{{end}}
|
||||
<progress max="100" value="{{$u.Progress}}"></progress>
|
||||
<p>{{$u.Step}}</p>
|
||||
{{if $u.Status.Log}}<pre class="log">{{$u.Status.Log}}</pre>{{end}}
|
||||
<p class="muted">This takes a few minutes. The page reloads when it is done; the web UI restarts when the new
|
||||
version is switched on, and you log in again.</p>
|
||||
</div>
|
||||
</div>
|
||||
{{else if $d.Pending}}
|
||||
{{else if $g.Run.Running}}
|
||||
<div class="upload-overlay" role="dialog" aria-modal="true">
|
||||
<div class="upload-card wide">
|
||||
<h2>{{$g.Title}}</h2>
|
||||
<progress max="100"></progress>
|
||||
{{if $g.Run.Log}}<pre class="log">{{$g.Run.Log}}</pre>{{end}}
|
||||
<p class="muted">The page reloads when it is done. The web UI restarts when an upgrade is switched on, and you log in again.</p>
|
||||
</div>
|
||||
</div>
|
||||
{{else if $u.Pending}}
|
||||
<section class="pending"><h2>Waiting for confirmation</h2>
|
||||
<p>A new configuration is active and not confirmed yet. Confirm it on the <a href="/">Overview</a>, or the router
|
||||
goes back to the previous version.</p></section>
|
||||
<p>A new system is active and not confirmed yet. Confirm it on the <a href="/">Overview</a>, or the router goes back to the
|
||||
previous one.</p></section>
|
||||
{{end}}
|
||||
|
||||
<h2 class="part">Router software</h2>
|
||||
|
||||
<section>
|
||||
<h2>Installed</h2>
|
||||
<dl>
|
||||
<dt>Version</dt><dd>{{or $u.Installed.Version "unknown"}}{{if $u.Installed.Rev}} <span class="muted">{{$u.Installed.Rev}}</span>{{end}}</dd>
|
||||
<dt>Settings schema</dt><dd>{{$u.Installed.Schema}}</dd>
|
||||
</dl>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2>Install a bundle</h2>
|
||||
<p>A <code>.bundle</code> file made with <code>nix run .#release</code>. It is installed only if it is signed with
|
||||
@@ -41,17 +53,17 @@
|
||||
<h2>Update server</h2>
|
||||
<form method="post" action="/update/url" class="actions">
|
||||
<input type="hidden" name="csrf" value="{{.CSRF}}">
|
||||
<label>Address <input name="url" value="{{$d.URL}}" size="40" placeholder="https://updates.example.com/router"></label>
|
||||
<label>Address <input name="url" value="{{$u.URL}}" size="40" placeholder="https://updates.example.com/router"></label>
|
||||
<button class="secondary">Save</button>
|
||||
</form>
|
||||
{{if $d.URL}}
|
||||
{{if $u.URL}}
|
||||
<form method="post" action="/update/check" class="actions">
|
||||
<input type="hidden" name="csrf" value="{{.CSRF}}">
|
||||
<button class="secondary">Check for updates</button>
|
||||
</form>
|
||||
{{end}}
|
||||
{{if $d.OfferErr}}<p class="error">Could not check: {{$d.OfferErr}}</p>{{end}}
|
||||
{{with $d.Offer}}
|
||||
{{if $u.OfferErr}}<p class="error">Could not check: {{$u.OfferErr}}</p>{{end}}
|
||||
{{with $u.Offer}}
|
||||
<p>{{if .Newer}}Available: <strong>{{.Version}}</strong>{{if .Rev}} <span class="muted">{{.Rev}}</span>{{end}}.{{else}}Nothing newer: the server has {{.Version}}.{{end}}</p>
|
||||
<form method="post" action="/update/install">
|
||||
<input type="hidden" name="csrf" value="{{$.CSRF}}">
|
||||
@@ -63,10 +75,121 @@
|
||||
<code>nix run .#release</code> writes. The data is signed, so plain HTTP works too.</p>
|
||||
</section>
|
||||
|
||||
{{if and $d.Status.Log (not $d.Status.Running)}}
|
||||
<h2 class="part" id="packages">Packages</h2>
|
||||
|
||||
{{with $g.NewerRelease}}
|
||||
<section class="notice">
|
||||
<h2>NixOS {{.}} is out</h2>
|
||||
<p>You follow {{$g.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}}
|
||||
|
||||
<section>
|
||||
<h2>Last update{{if $d.Status.Result}} — {{if eq $d.Status.Result "success"}}succeeded{{else}}failed ({{$d.Status.Result}}){{end}}{{end}}</h2>
|
||||
<pre class="log">{{$d.Status.Log}}</pre>
|
||||
<h2>Channel</h2>
|
||||
<p>Upgrades the kernel and all programs (NixOS) without a new release of nixos-router. Nothing is downloaded until
|
||||
you ask for it, and an upgrade is activated like a settings change: unless you confirm it in time, the router
|
||||
goes back to the previous system.</p>
|
||||
<dl>
|
||||
<dt>Running</dt><dd>{{or $g.Version "unknown"}}</dd>
|
||||
</dl>
|
||||
<form method="post" action="/upgrade/channel" class="actions">
|
||||
<input type="hidden" name="csrf" value="{{.CSRF}}">
|
||||
<label>Follow
|
||||
<select name="channel">
|
||||
{{range $g.Choices}}<option value="{{.Value}}"{{if eq .Value $g.Channel}} selected{{end}}>{{.Label}}</option>{{end}}
|
||||
</select>
|
||||
</label>
|
||||
<button class="secondary">Save</button>
|
||||
</form>
|
||||
{{if $g.ReleasesSeen}}<p class="hint">Stable releases as the channel server listed them on {{$g.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>
|
||||
|
||||
{{if $g.Channel}}
|
||||
<section>
|
||||
<h2>Check</h2>
|
||||
<form method="post" action="/upgrade/check" class="actions">
|
||||
<input type="hidden" name="csrf" value="{{.CSRF}}">
|
||||
<button class="secondary"{{if or $g.Run.Running $g.Updating}} disabled{{end}}>Check for upgrades</button>
|
||||
</form>
|
||||
{{with $g.Check}}
|
||||
<dl>
|
||||
<dt>Channel</dt><dd>{{.Branch}}</dd>
|
||||
<dt>Running</dt><dd>{{.Running.Version}}</dd>
|
||||
<dt>Newest</dt><dd>{{printf "%.7s" .Newest.Rev}} <span class="muted">checked {{.Time}}</span></dd>
|
||||
</dl>
|
||||
{{if .UpToDate}}<p>Up to date.</p>{{else}}<p>A newer revision is available.</p>{{end}}
|
||||
{{end}}
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2>What would change</h2>
|
||||
<form method="post" action="/upgrade/preview" class="actions">
|
||||
<input type="hidden" name="csrf" value="{{.CSRF}}">
|
||||
{{if and $g.Check $g.Check.UpToDate}}<label><input type="checkbox" name="force"> look anyway</label>{{end}}
|
||||
<label><input type="checkbox" name="downgrade"> downgrade anyway</label>
|
||||
<button class="secondary"{{if or $g.Run.Running $g.Updating}} disabled{{end}}>Preview</button>
|
||||
</form>
|
||||
<p class="hint">Works it out from the new revision's description: no package is downloaded.</p>
|
||||
{{with $g.Preview}}
|
||||
<p>{{$g.Version}} → <strong>{{.Version}}</strong> <span class="muted">{{printf "%.7s" .Rev}}, previewed {{.Time}}</span></p>
|
||||
{{if .Changes}}
|
||||
<table>
|
||||
<thead><tr><th>Package</th><th>Now</th><th></th><th>New</th></tr></thead>
|
||||
<tbody>{{range .Changes}}<tr><td>{{.Name}}</td><td>{{.From}}</td><td>→</td><td>{{.To}}</td></tr>{{end}}</tbody>
|
||||
</table>
|
||||
{{else}}<p>No package changes.</p>{{end}}
|
||||
<p class="hint">The list shows the versions of programs the router runs; a program that is only rebuilt does not appear.</p>
|
||||
<dl>
|
||||
<dt>To download</dt><dd>{{or .Download "nothing, or the package cache cannot be reached"}}</dd>
|
||||
<dt>Built here</dt><dd>{{.Builds}} derivation{{if ne .Builds 1}}s{{end}}{{if gt .Builds 50}} <span class="muted">(many: the package cache may not have them yet; this takes long)</span>{{end}}</dd>
|
||||
{{if .RebootNeeded}}<dt>Kernel</dt><dd>A new kernel: it runs after the next reboot.</dd>{{end}}
|
||||
</dl>
|
||||
{{if .BuildNames}}
|
||||
<details>
|
||||
<summary>What is built here</summary>
|
||||
<p class="hint">The system's own pieces (they carry the nixpkgs revision) and programs the package cache does not have yet.</p>
|
||||
<ul>{{range .BuildNames}}<li>{{.}}</li>{{end}}</ul>
|
||||
{{if .MoreBuilds}}<p class="muted">… and {{.MoreBuilds}} more</p>{{end}}
|
||||
</details>
|
||||
{{end}}
|
||||
<div class="actions">
|
||||
<form method="post" action="/upgrade/download">
|
||||
<input type="hidden" name="csrf" value="{{$.CSRF}}">
|
||||
<button class="secondary"{{if or $g.Run.Running $g.Updating $g.Pending}} disabled{{end}}>Download now</button>
|
||||
</form>
|
||||
<form method="post" action="/upgrade/apply">
|
||||
<input type="hidden" name="csrf" value="{{$.CSRF}}">
|
||||
<button{{if or $g.Run.Running $g.Updating $g.Pending}} disabled{{end}}>Upgrade to {{.Version}}</button>
|
||||
</form>
|
||||
</div>
|
||||
<p class="hint">Downloading first lets you start the upgrade later without needing the internet. Upgrading
|
||||
downloads what is missing, builds the system and switches to it; confirm it on the Overview.</p>
|
||||
{{end}}
|
||||
</section>
|
||||
{{else}}
|
||||
<section><p>Choose a channel to look for upgrades.</p></section>
|
||||
{{end}}
|
||||
|
||||
{{if and $u.Status.Log (not $u.Status.Running)}}
|
||||
<section>
|
||||
<h2>Last update{{if $u.Status.Result}} — {{if eq $u.Status.Result "success"}}succeeded{{else}}failed ({{$u.Status.Result}}){{end}}{{end}}</h2>
|
||||
<pre class="log">{{$u.Status.Log}}</pre>
|
||||
</section>
|
||||
{{end}}
|
||||
|
||||
{{if and $g.Run.Log (not $g.Run.Running)}}
|
||||
<section>
|
||||
<h2>Last package run{{if $g.Run.Result}} — {{if eq $g.Run.Result "success"}}succeeded{{else}}failed ({{$g.Run.Result}}){{end}}{{end}}</h2>
|
||||
<pre class="log">{{$g.Run.Log}}</pre>
|
||||
</section>
|
||||
{{end}}
|
||||
</div>
|
||||
|
||||
@@ -1,130 +0,0 @@
|
||||
{{define "content"}}
|
||||
<div class="cols">
|
||||
{{$d := .Data}}
|
||||
<section>
|
||||
<h2>Packages</h2>
|
||||
<p>Upgrades the kernel and all programs (NixOS) without a new release of nixos-router. Nothing is downloaded until
|
||||
you ask for it, and an upgrade is activated like a settings change: unless you confirm it in time, the router
|
||||
goes back to the previous system.</p>
|
||||
<dl>
|
||||
<dt>Running</dt><dd>{{or $d.Version "unknown"}}</dd>
|
||||
</dl>
|
||||
<form method="post" action="/upgrade/channel" class="actions">
|
||||
<input type="hidden" name="csrf" value="{{.CSRF}}">
|
||||
<label>Follow
|
||||
<select name="channel">
|
||||
{{range $d.Choices}}<option value="{{.Value}}"{{if eq .Value $d.Channel}} selected{{end}}>{{.Label}}</option>{{end}}
|
||||
</select>
|
||||
</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}}
|
||||
<div class="upload-overlay" role="dialog" aria-modal="true">
|
||||
<div class="upload-card wide">
|
||||
<h2>{{$d.Title}}</h2>
|
||||
<progress max="100"></progress>
|
||||
{{if $d.Run.Log}}<pre class="log">{{$d.Run.Log}}</pre>{{end}}
|
||||
<p class="muted">The page reloads when it is done. The web UI restarts when an upgrade is switched on, and you log in again.</p>
|
||||
</div>
|
||||
</div>
|
||||
{{else if $d.Pending}}
|
||||
<section class="pending"><h2>Waiting for confirmation</h2>
|
||||
<p>A new system is active and not confirmed yet. Confirm it on the <a href="/">Overview</a>, or the router goes back to the
|
||||
previous one.</p></section>
|
||||
{{end}}
|
||||
|
||||
{{if $d.Channel}}
|
||||
<section>
|
||||
<h2>Check</h2>
|
||||
<form method="post" action="/upgrade/check" class="actions">
|
||||
<input type="hidden" name="csrf" value="{{.CSRF}}">
|
||||
<button class="secondary"{{if or $d.Run.Running $d.Updating}} disabled{{end}}>Check for upgrades</button>
|
||||
</form>
|
||||
{{with $d.Check}}
|
||||
<dl>
|
||||
<dt>Channel</dt><dd>{{.Branch}}</dd>
|
||||
<dt>Running</dt><dd>{{.Running.Version}}</dd>
|
||||
<dt>Newest</dt><dd>{{printf "%.7s" .Newest.Rev}} <span class="muted">checked {{.Time}}</span></dd>
|
||||
</dl>
|
||||
{{if .UpToDate}}<p>Up to date.</p>{{else}}<p>A newer revision is available.</p>{{end}}
|
||||
{{end}}
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2>What would change</h2>
|
||||
<form method="post" action="/upgrade/preview" class="actions">
|
||||
<input type="hidden" name="csrf" value="{{.CSRF}}">
|
||||
{{if and $d.Check $d.Check.UpToDate}}<label><input type="checkbox" name="force"> look anyway</label>{{end}}
|
||||
<label><input type="checkbox" name="downgrade"> downgrade anyway</label>
|
||||
<button class="secondary"{{if or $d.Run.Running $d.Updating}} disabled{{end}}>Preview</button>
|
||||
</form>
|
||||
<p class="hint">Works it out from the new revision's description: no package is downloaded.</p>
|
||||
{{with $d.Preview}}
|
||||
<p>{{$d.Version}} → <strong>{{.Version}}</strong> <span class="muted">{{printf "%.7s" .Rev}}, previewed {{.Time}}</span></p>
|
||||
{{if .Changes}}
|
||||
<table>
|
||||
<thead><tr><th>Package</th><th>Now</th><th></th><th>New</th></tr></thead>
|
||||
<tbody>{{range .Changes}}<tr><td>{{.Name}}</td><td>{{.From}}</td><td>→</td><td>{{.To}}</td></tr>{{end}}</tbody>
|
||||
</table>
|
||||
{{else}}<p>No package changes.</p>{{end}}
|
||||
<p class="hint">The list shows the versions of programs the router runs; a program that is only rebuilt does not appear.</p>
|
||||
<dl>
|
||||
<dt>To download</dt><dd>{{or .Download "nothing, or the package cache cannot be reached"}}</dd>
|
||||
<dt>Built here</dt><dd>{{.Builds}} derivation{{if ne .Builds 1}}s{{end}}{{if gt .Builds 50}} <span class="muted">(many: the package cache may not have them yet; this takes long)</span>{{end}}</dd>
|
||||
{{if .RebootNeeded}}<dt>Kernel</dt><dd>A new kernel: it runs after the next reboot.</dd>{{end}}
|
||||
</dl>
|
||||
{{if .BuildNames}}
|
||||
<details>
|
||||
<summary>What is built here</summary>
|
||||
<p class="hint">The system's own pieces (they carry the nixpkgs revision) and programs the package cache does not have yet.</p>
|
||||
<ul>{{range .BuildNames}}<li>{{.}}</li>{{end}}</ul>
|
||||
{{if .MoreBuilds}}<p class="muted">… and {{.MoreBuilds}} more</p>{{end}}
|
||||
</details>
|
||||
{{end}}
|
||||
<div class="actions">
|
||||
<form method="post" action="/upgrade/download">
|
||||
<input type="hidden" name="csrf" value="{{$.CSRF}}">
|
||||
<button class="secondary"{{if or $d.Run.Running $d.Updating $d.Pending}} disabled{{end}}>Download now</button>
|
||||
</form>
|
||||
<form method="post" action="/upgrade/apply">
|
||||
<input type="hidden" name="csrf" value="{{$.CSRF}}">
|
||||
<button{{if or $d.Run.Running $d.Updating $d.Pending}} disabled{{end}}>Upgrade to {{.Version}}</button>
|
||||
</form>
|
||||
</div>
|
||||
<p class="hint">Downloading first lets you start the upgrade later without needing the internet. Upgrading
|
||||
downloads what is missing, builds the system and switches to it; confirm it on the Overview.</p>
|
||||
{{end}}
|
||||
</section>
|
||||
{{else}}
|
||||
<section><p>Choose a channel to look for upgrades.</p></section>
|
||||
{{end}}
|
||||
|
||||
{{if and $d.Run.Log (not $d.Run.Running)}}
|
||||
<section>
|
||||
<h2>Last run{{if $d.Run.Result}} — {{if eq $d.Run.Result "success"}}succeeded{{else}}failed ({{$d.Run.Result}}){{end}}{{end}}</h2>
|
||||
<pre class="log">{{$d.Run.Log}}</pre>
|
||||
</section>
|
||||
{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
@@ -289,15 +289,31 @@ func (a *app) updateData() updateData {
|
||||
return d
|
||||
}
|
||||
|
||||
// updatesData is the Updates page: the router software (a release of
|
||||
// nixos-router) and the packages (nixpkgs) on one page.
|
||||
type updatesData struct {
|
||||
Update updateData
|
||||
Upgrade upgradeData
|
||||
}
|
||||
|
||||
func (a *app) updatesData() updatesData {
|
||||
return updatesData{Update: a.updateData(), Upgrade: a.upgradeData()}
|
||||
}
|
||||
|
||||
func (a *app) updatePage(w http.ResponseWriter, r *http.Request, sess session) {
|
||||
d := a.updateData()
|
||||
p := page{Title: "Update", CSRF: sess.csrf, LoggedIn: true, Data: d, Flash: r.URL.Query().Get("msg")}
|
||||
if d.Status.Running {
|
||||
d := a.updatesData()
|
||||
p := page{Title: "Updates", CSRF: sess.csrf, LoggedIn: true, Data: d, Flash: r.URL.Query().Get("msg")}
|
||||
if d.Update.Status.Running || d.Upgrade.Run.Running {
|
||||
p.Live = 3
|
||||
}
|
||||
a.render(w, "update", p)
|
||||
}
|
||||
|
||||
// upgradeRedirect sends the old address of the packages part to the page.
|
||||
func upgradeRedirect(w http.ResponseWriter, r *http.Request, _ session) {
|
||||
http.Redirect(w, r, "/update#packages", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func (a *app) updateBack(w http.ResponseWriter, r *http.Request, msg string) {
|
||||
http.Redirect(w, r, "/update?msg="+url.QueryEscape(msg), http.StatusSeeOther)
|
||||
}
|
||||
@@ -324,17 +340,17 @@ func (a *app) updateSaveURL(w http.ResponseWriter, r *http.Request, _ session) {
|
||||
}
|
||||
|
||||
func (a *app) updateCheck(w http.ResponseWriter, r *http.Request, sess session) {
|
||||
d := a.updateData()
|
||||
p := page{Title: "Update", CSRF: sess.csrf, LoggedIn: true}
|
||||
if d.URL == "" {
|
||||
d := a.updatesData()
|
||||
p := page{Title: "Updates", CSRF: sess.csrf, LoggedIn: true}
|
||||
if d.Update.URL == "" {
|
||||
a.updateBack(w, r, "Set the update server first.")
|
||||
return
|
||||
}
|
||||
offer, err := a.sys.checkUpdate(d.URL)
|
||||
offer, err := a.sys.checkUpdate(d.Update.URL)
|
||||
if err != nil {
|
||||
d.OfferErr = err.Error()
|
||||
d.Update.OfferErr = err.Error()
|
||||
} else {
|
||||
d.Offer = &offer
|
||||
d.Update.Offer = &offer
|
||||
}
|
||||
p.Data = d
|
||||
a.render(w, "update", p)
|
||||
|
||||
@@ -294,17 +294,8 @@ func (a *app) upgradeData() upgradeData {
|
||||
return d
|
||||
}
|
||||
|
||||
func (a *app) upgradePage(w http.ResponseWriter, r *http.Request, sess session) {
|
||||
d := a.upgradeData()
|
||||
p := page{Title: "Packages", CSRF: sess.csrf, LoggedIn: true, Data: d, Flash: r.URL.Query().Get("msg")}
|
||||
if d.Run.Running {
|
||||
p.Live = 3
|
||||
}
|
||||
a.render(w, "upgrade", p)
|
||||
}
|
||||
|
||||
func (a *app) upgradeBack(w http.ResponseWriter, r *http.Request, msg string) {
|
||||
http.Redirect(w, r, "/upgrade?msg="+url.QueryEscape(msg), http.StatusSeeOther)
|
||||
http.Redirect(w, r, "/update?msg="+url.QueryEscape(msg)+"#packages", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func (a *app) upgradeChannel(w http.ResponseWriter, r *http.Request, _ session) {
|
||||
|
||||
@@ -37,6 +37,25 @@ func TestReleaseOfAndChannelChoices(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestOneUpdatesPage(t *testing.T) {
|
||||
a, _ := newTestApp(t)
|
||||
h := a.routes()
|
||||
cookie := login(t, h)
|
||||
// The old address of the packages leads to the page that has both parts.
|
||||
if rec := do(h, "GET", "/upgrade", nil, cookie); rec.Code != http.StatusSeeOther || rec.Header().Get("Location") != "/update#packages" {
|
||||
t.Fatalf("/upgrade: %d %q", rec.Code, rec.Header().Get("Location"))
|
||||
}
|
||||
body := do(h, "GET", "/update", nil, cookie).Body.String()
|
||||
for _, want := range []string{"Router software", "Install a bundle", "Update server", `id="packages"`, "Choose a channel", `aria-current="page">Updates`} {
|
||||
if !strings.Contains(body, want) {
|
||||
t.Errorf("the page lacks %q", want)
|
||||
}
|
||||
}
|
||||
if strings.Contains(body, `href="/upgrade"`) {
|
||||
t.Error("the menu still links /upgrade")
|
||||
}
|
||||
}
|
||||
|
||||
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" {
|
||||
@@ -69,16 +88,16 @@ func TestReleaseNoticeShows(t *testing.T) {
|
||||
}
|
||||
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") {
|
||||
if body := do(h, "GET", "/update", 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"} {
|
||||
for _, path := range []string{"/", "/update"} {
|
||||
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"`) {
|
||||
if body := do(h, "GET", "/update", nil, cookie).Body.String(); !strings.Contains(body, `<option value="26.11"`) {
|
||||
t.Errorf("26.11 is not offered:\n%s", body)
|
||||
}
|
||||
}
|
||||
@@ -128,7 +147,7 @@ func TestUpgradePage(t *testing.T) {
|
||||
defer func() { startUnit = orig }()
|
||||
h := a.routes()
|
||||
cookie := login(t, h)
|
||||
page := func() string { return do(h, "GET", "/upgrade", nil, cookie).Body.String() }
|
||||
page := func() string { return do(h, "GET", "/update", nil, cookie).Body.String() }
|
||||
post := func(path string, form url.Values) *http.Response {
|
||||
form.Set("csrf", csrfFrom(t, page()))
|
||||
return do(h, "POST", path, form, cookie).Result()
|
||||
@@ -226,7 +245,7 @@ func TestUpgradePage(t *testing.T) {
|
||||
|
||||
t.Run("the last run's output is shown", func(t *testing.T) {
|
||||
os.WriteFile(filepath.Join(a.sys.upgradeDir(), "last.log"), []byte("channel 26.11 (nixos-26.11)\nup to date\n"), 0o600)
|
||||
if body := page(); !strings.Contains(body, "Last run") || !strings.Contains(body, "nixos-26.11)") {
|
||||
if body := page(); !strings.Contains(body, "Last package run") || !strings.Contains(body, "nixos-26.11)") {
|
||||
t.Fatalf("no log:\n%s", body)
|
||||
}
|
||||
if got := tail("a\nbb\nccc\n", 6); got != "ccc\n" {
|
||||
|
||||
+9
-8
@@ -442,24 +442,25 @@ pkgs.testers.runNixOSTest {
|
||||
f" && test $(systemctl show -p Result --value {unit}) = success", timeout=300)
|
||||
|
||||
def step(name, extra=""):
|
||||
code = curl(f"-o /dev/null -w '%{{http_code}}' -d csrf={csrf('/upgrade')} {extra} {ui}/upgrade/{name}")
|
||||
code = curl(f"-o /dev/null -w '%{{http_code}}' -d csrf={csrf('/update')} {extra} {ui}/upgrade/{name}")
|
||||
assert code == "303", (name, code)
|
||||
unit_done("router-upgrade.service")
|
||||
|
||||
page = curl(f"{ui}/upgrade")
|
||||
assert "Packages" in page and 'value="26.05" selected' in page and target.succeed("cat /run/current-system/nixos-version").strip() in page, page
|
||||
assert curl(f"-o /dev/null -w '%{{http_code}}' -d csrf={csrf('/upgrade')} -d 'channel=nixos-26.05%3Bx' {ui}/upgrade/channel") == "303"
|
||||
assert curl(f"-o /dev/null -w '%{{redirect_url}}' {ui}/upgrade").endswith("/update#packages")
|
||||
page = curl(f"{ui}/update")
|
||||
assert "Packages" in page and "Router software" in page and 'value="26.05" selected' in page and target.succeed("cat /run/current-system/nixos-version").strip() in page, page
|
||||
assert curl(f"-o /dev/null -w '%{{http_code}}' -d csrf={csrf('/update')} -d 'channel=nixos-26.05%3Bx' {ui}/upgrade/channel") == "303"
|
||||
assert "26.05" in target.succeed("jq -r .router.update.channel /var/lib/router/config/settings.json")
|
||||
assert curl(f"-o /dev/null -w '%{{http_code}}' -d csrf=wrong {ui}/upgrade/check") == "403"
|
||||
step("check")
|
||||
assert "Up to date." in curl(f"{ui}/upgrade")
|
||||
assert "Up to date." in curl(f"{ui}/update")
|
||||
step("preview", "-d force=on")
|
||||
page = curl(f"{ui}/upgrade")
|
||||
page = curl(f"{ui}/update")
|
||||
assert "No package changes" in page and "Upgrade to" in page, page
|
||||
step("download")
|
||||
step("apply")
|
||||
assert "Upgrade to" not in curl(f"{ui}/upgrade")
|
||||
assert "Upgrade to" not in curl(f"{ui}/update")
|
||||
assert json.loads(target.succeed("cat /var/lib/router/config/nixpkgs-pin.json"))["rev"] == running_rev
|
||||
assert "Last run" in curl(f"{ui}/upgrade")
|
||||
assert "Last package run" in curl(f"{ui}/update")
|
||||
'';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user