One upgrade for nixos-router and the packages

Check, preview and apply look at the repository's release tags and the
channel together; the new nixos-router is a highlighted row in the
preview table. The update server section and the separate git update
are gone; bundles stay.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 11:49:57 +01:00
co-authored by Claude Sonnet 5.5
parent 3e6eee0b9c
commit 2b7cd86e98
15 changed files with 372 additions and 695 deletions
+20 -131
View File
@@ -55,16 +55,14 @@ let
migrate
pkgs.coreutils
pkgs.curl
pkgs.git
pkgs.gawk
pkgs.jq
pkgs.util-linux
];
text = ''
# (A release from the git repository is not installed here but by
# router-upgrade, with the packages: this is for signed bundles.)
usage() {
echo "usage: router-update check | [--force] (--request | --bundle FILE | --url URL | --git TAG|latest) [timeout]" >&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 the repository" >&2
echo "usage: router-update [--force] (--request | --bundle FILE | --url URL) [timeout]" >&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 " --request what the web UI asked for (${updateDir}/request.json)" >&2
@@ -76,11 +74,9 @@ let
force=0 mode="" arg="" timeout=""
while [ $# -gt 0 ]; do
case $1 in
check) mode=check ;;
--force) force=1 ;;
--bundle) shift; [ $# -gt 0 ] || usage; mode=bundle arg=$1 ;;
--url) shift; [ $# -gt 0 ] || usage; mode=url arg=$1 ;;
--git) shift; [ $# -gt 0 ] || usage; mode=git arg=$1 ;;
--request)
req=${updateDir}/request.json
[ -r "$req" ] || die "no request"
@@ -94,60 +90,12 @@ let
done
[ -n "$mode" ] || usage
[ "$(id -u)" -eq 0 ] || die "must run as root"
config=${cfg.directory}
# The release tags of the repository, "TAG REVISION" per line (an
# annotated tag counts with the commit it points to).
repository() { echo ${lib.escapeShellArg (toString config.routerUpdate.repository)}; }
git_tags() {
git ls-remote --tags "$1" 'refs/tags/v*' | awk '
{ n = $2; sub("^refs/tags/", "", n); peeled = (n ~ /\^\{\}$/); sub(/\^\{\}$/, "", n)
if (n !~ /^v[0-9]+\.[0-9]+\.[0-9]+$/) next
if (peeled) p[n] = $1; else d[n] = $1
seen[n] = 1 }
END { for (n in seen) print n, (n in p ? p[n] : d[n]) }' | sort -V
}
if [ "$mode" = check ]; then
# Only looks: no lock, so it runs beside an update.
repo=$(repository)
if [ -z "$repo" ]; then
echo "router-update: this router has no repository: nothing to look at"
exit 0
fi
tags=$(git_tags "$repo") || die "cannot read the tags of $repo"
[ -n "$tags" ] || die "$repo has no release tags (vX.Y.Z)"
read -r tag rev <<<"$(tail -n 1 <<<"$tags")"
version=''${tag#v}
installed=$(jq -r '.version // "unknown"' /etc/router-release)
newer=false
if [ "$version" != "$installed" ] && [ "$(printf '%s\n%s\n' "$installed" "$version" | sort -V | tail -n 1)" = "$version" ]; then
newer=true
fi
mkdir -p ${updateDir}
jq -n --arg repo "$repo" --arg time "$(date -u +%FT%TZ)" --arg installed "$installed" \
--arg tag "$tag" --arg version "$version" --arg rev "$rev" --argjson newer "$newer" \
'{repository: $repo, time: $time, installed: $installed, newest: {tag: $tag, version: $version, rev: $rev}, newer: $newer}' \
> ${updateDir}/check.json.new
chmod 0644 ${updateDir}/check.json.new
mv ${updateDir}/check.json.new ${updateDir}/check.json
if [ "$newer" = true ]; then
echo "router-update: $version is available (installed: $installed)"
else
echo "router-update: up to date ($installed; the repository's newest is $version)"
fi
exit 0
fi
exec 9>/run/router-update.lock
flock -n 9 || die "another update is running"
# Bundles and servers are signed; a git repository is trusted as it is.
trusted=""
if [ "$mode" != git ]; then
trusted=$(tr '\n' ' ' < /etc/router-update-keys)
[ -n "''${trusted// /}" ] || die "this router has no update key"
fi
trusted=$(tr '\n' ' ' < /etc/router-update-keys)
[ -n "''${trusted// /}" ] || die "this router has no update key"
staged=${updateDir}/staged
case $mode in
@@ -164,56 +112,20 @@ let
base=''${arg%/}
store="$base/cache"
latest=$(curl -fsS --max-time 30 "$base/latest") ;;
git) ;;
*) usage ;;
esac
if [ "$mode" = git ]; then
repo=$(repository)
[ -n "$repo" ] || die "this router has no repository to update from"
tags=$(git_tags "$repo") || die "cannot read the tags of $repo"
if [ -z "$arg" ] || [ "$arg" = latest ]; then
found=$(tail -n 1 <<<"$tags")
else
[[ $arg =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] || die "not a release tag: $arg"
found=$(awk -v t="$arg" '$1 == t' <<<"$tags")
fi
[ -n "$found" ] || die "$repo has no such release tag"
read -r tag rev <<<"$found"
src="git+$repo?ref=refs/tags/$tag&rev=$rev"
echo "router-update: fetching $tag ($rev) from $repo"
# (No registry: the address is complete, and the global one is a download.)
meta=$(nix --option flake-registry "" flake prefetch --json "$src") || die "cannot fetch $src"
tree=$(jq -er .storePath <<<"$meta")
if [ ! -r "$tree/config-flake.nix" ] || [ ! -r "$tree/VERSION" ]; then
die "$tag is not a release this updater can build (no config-flake.nix or VERSION)"
fi
# What a release carries, made from the source: the files that the rest
# of the update reads (the flake that points at the source, its version,
# its commit time, its settings migrations).
release=${updateDir}/git-release
rm -rf "$release"
mkdir -p "$release/migrations"
tr -d '\n' < "$tree/VERSION" > "$release/version"
jq -er .locked.lastModified <<<"$meta" | tr -d '\n' > "$release/serial"
printf %s "$rev" > "$release/rev"
find "$tree/migrations" -name '*.jq' -exec cp {} "$release/migrations/" \;
find "$release/migrations" -name '*.jq' | wc -l | tr -d '\n' > "$release/schema"
# (jq, not a shell substitution: the address has a & in it.)
jq -rRs --arg source "$src" 'gsub("@SOURCE@"; $source)' "$tree/config-flake.nix" > "$release/flake.nix"
else
release=$(jq -er .release <<<"$latest") || die "the update has no release"
[[ $release =~ ^/nix/store/[0-9a-z]{32}-[A-Za-z0-9+._-]+$ ]] || die "not a store path: $release"
release=$(jq -er .release <<<"$latest") || die "the update has no release"
[[ $release =~ ^/nix/store/[0-9a-z]{32}-[A-Za-z0-9+._-]+$ ]] || die "not a store path: $release"
# Nothing is trusted until every path of the closure is signed by our key.
echo "router-update: verifying $release"
nix --option trusted-public-keys "$trusted" store verify \
--store "$store" --no-contents --sigs-needed 1 -r "$release" \
|| die "the update is not signed with this router's update key"
echo "router-update: importing it"
nix --option trusted-public-keys "$trusted" copy --from "$store" "$release"
rm -rf "$staged"
fi
# Nothing is trusted until every path of the closure is signed by our key.
echo "router-update: verifying $release"
nix --option trusted-public-keys "$trusted" store verify \
--store "$store" --no-contents --sigs-needed 1 -r "$release" \
|| die "the update is not signed with this router's update key"
echo "router-update: importing it"
nix --option trusted-public-keys "$trusted" copy --from "$store" "$release"
rm -rf "$staged"
new_version=$(cat "$release/version")
new_serial=$(cat "$release/serial")
@@ -274,12 +186,11 @@ in
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.
releases. `router-upgrade` (daily, and in the web UI) looks for a newer
tag and, with the packages, locks the configuration flake to it. 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 only.
'';
};
routerUpdate.publicKeys = lib.mkOption {
@@ -321,28 +232,6 @@ in
router.rollback.onRollback = "${restore}/bin/router-update-restore";
router.rollback.onConfirm = "rm -rf ${snapshot}";
# 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.
systemd.services.router-update-check = {
description = "Look for a newer release of nixos-router";
restartIfChanged = false;
stopIfChanged = false;
path = [ "/run/current-system/sw" ];
serviceConfig = {
Type = "oneshot";
ExecStart = "${lib.getExe update} check";
TimeoutStartSec = "5min";
};
};
systemd.timers.router-update-check = {
wantedBy = [ "timers.target" ];
timerConfig = {
OnCalendar = "daily";
RandomizedDelaySec = "1h";
Persistent = true;
};
};
systemd.services.router-update = {
description = "Install a router update";
restartIfChanged = false;
+162 -40
View File
@@ -30,23 +30,29 @@ let
up = cfg.upgrade;
snapshot = "${cfg.stateDirectory}/config.pre-update";
dir = "${cfg.stateDirectory}/upgrade";
migrate = pkgs.callPackage ../../pkgs/router-migrate.nix { };
repository = toString config.routerUpdate.repository;
upgrade = pkgs.writeShellApplication {
name = "router-upgrade";
runtimeInputs = [
config.nix.package
config.systemd.package
migrate
pkgs.coreutils
pkgs.curl
pkgs.gawk
pkgs.git
pkgs.jq
pkgs.util-linux
];
text = ''
usage() {
echo "usage: router-upgrade check | releases | preview [--force] [--downgrade] | download | apply [timeout] | --request" >&2
echo " check the newest revision of router.update.channel, against the running one" >&2
echo " releases which stable NixOS releases the channel server has (a timer runs it daily)" >&2
echo " preview the packages that change and the size of the download (nothing is fetched)" >&2
echo "usage: router-upgrade check | daily | releases | preview [--force] [--downgrade] | download | apply [timeout] | --request" >&2
echo " check the newest nixpkgs revision of router.update.channel and the newest release tag of nixos-router, against the running ones" >&2
echo " daily check, quietly (a timer runs it)" >&2
echo " releases which stable NixOS releases the channel server has" >&2
echo " preview the new nixos-router and the packages that change, and the size of the download (nothing is fetched)" >&2
echo " download fetch and build what was previewed, without activating it" >&2
echo " apply activate what was previewed (fetching it if need be), with commit-confirm" >&2
exit 2
@@ -78,12 +84,15 @@ let
config=${cfg.directory}
mkdir -p ${dir}
# nixos-router comes from this repository (its tags vX.Y.Z); the packages
# (nixpkgs) from the channel, if one is followed. Both are inputs of the
# configuration flake, and one lock moves them together.
repository=${lib.escapeShellArg repository}
channel=""
branch=""
if [ "$cmd" != releases ]; then
channel=$(jq -r '.router.update.channel // empty' "$config/settings.json")
[ -n "$channel" ] || die "no channel: set router.update.channel (unstable, or a release like 26.05)"
if [ "$channel" = unstable ]; then branch=nixos-unstable; else branch="nixos-$channel"; fi
if [ "$channel" = unstable ]; then branch=nixos-unstable; elif [ -n "$channel" ]; then branch="nixos-$channel"; fi
fi
running_rev=$(/run/current-system/sw/bin/nixos-version --revision || true)
@@ -121,20 +130,64 @@ let
echo "releases on the channel server: ''${found[*]:-none}"
}
# The release tags of the repository, "TAG REVISION" per line, oldest first (an
# annotated tag counts with the commit it points to).
git_tags() {
git ls-remote --tags "$1" 'refs/tags/v*' | awk '
{ n = $2; sub("^refs/tags/", "", n); peeled = (n ~ /\^\{\}$/); sub(/\^\{\}$/, "", n)
if (n !~ /^v[0-9]+\.[0-9]+\.[0-9]+$/) next
if (peeled) p[n] = $1; else d[n] = $1
seen[n] = 1 }
END { for (n in seen) print n, (n in p ? p[n] : d[n]) }' | sort -V
}
installed_router=$(jq -r '.version // "unknown"' /etc/router-release 2>/dev/null || echo unknown)
r_tag="" r_rev="" r_version="" r_newer=false
check() {
releases || true
newest=$(newest_rev)
if [ "$newest" = "$running_rev" ]; then same=true; else same=false; fi
local packages_same=true router_json=null tags
newest=""
if [ -n "$channel" ]; then
newest=$(newest_rev)
if [ "$newest" != "$running_rev" ]; then packages_same=false; fi
fi
if [ -n "$repository" ]; then
# (Not fatal: the packages can still be looked at.)
if tags=$(git_tags "$repository" 2>/dev/null) && [ -n "$tags" ]; then
read -r r_tag r_rev <<<"$(tail -n 1 <<<"$tags")"
r_version=''${r_tag#v}
if [ "$r_version" != "$installed_router" ] \
&& [ "$(printf '%s\n%s\n' "$installed_router" "$r_version" | sort -V | tail -n 1)" = "$r_version" ]; then
r_newer=true
fi
router_json=$(jq -n --arg repo "$repository" --arg installed "$installed_router" --arg tag "$r_tag" \
--arg version "$r_version" --arg rev "$r_rev" --argjson newer "$r_newer" \
'{repository: $repo, installed: $installed, newest: {tag: $tag, version: $version, rev: $rev}, newer: $newer}')
else
echo "router-upgrade: cannot read the release tags of $repository" >&2
fi
fi
[ -n "$channel" ] || [ "$router_json" != null ] \
|| die "nothing to look at: no channel is set (router.update.channel: unstable, or a release like 26.05) and the repository cannot be read"
if [ "$packages_same" = true ] && [ "$r_newer" = false ]; then same=true; else same=false; fi
jq -n --arg channel "$channel" --arg branch "$branch" --arg time "$(date -u +%FT%TZ)" \
--arg running "$running_rev" --arg version "$running_version" --arg newest "$newest" \
--argjson upToDate "$same" \
--argjson packagesUpToDate "$packages_same" --argjson upToDate "$same" --argjson router "$router_json" \
'{channel: $channel, branch: $branch, time: $time, running: {rev: $running, version: $version},
newest: {rev: $newest}, upToDate: $upToDate}' > ${dir}/check.json.new
newest: {rev: $newest}, packagesUpToDate: $packagesUpToDate, upToDate: $upToDate, router: $router}' > ${dir}/check.json.new
mv ${dir}/check.json.new ${dir}/check.json
echo "channel $channel ($branch)"
echo " running $running_version"
echo " newest $(short "$newest")"
if [ "$same" = true ]; then echo "up to date"; else echo "a newer revision is available"; fi
if [ "$router_json" != null ]; then
echo "nixos-router ($repository)"
echo " installed $installed_router"
echo " newest $r_version"
fi
if [ -n "$channel" ]; then
echo "channel $channel ($branch)"
echo " running $running_version"
echo " newest $(short "$newest")"
fi
if [ "$same" = true ]; then echo "up to date"; else echo "a newer version is available"; fi
}
# The names (with versions) of store paths, one per line.
@@ -171,24 +224,71 @@ let
esac
done
check
rm -rf ${dir}/preview.json ${dir}/flake ${dir}/result
rm -rf ${dir}/preview.json ${dir}/flake ${dir}/base ${dir}/git-release ${dir}/result
if [ "$same" = true ] && [ "$force" -eq 0 ]; then return 0; fi
mkdir ${dir}/flake
mkdir ${dir}/flake ${dir}/base
for f in flake.nix settings.json local.nix flake.lock; do
if [ -e "$config/$f" ]; then cp "$config/$f" ${dir}/flake/; fi
done
ref="${up.nixpkgsRef}"
ref=''${ref//%rev%/$newest}
echo "router-upgrade: locking nixpkgs to $(short "$newest")"
nix flake lock --override-input nixos-router/nixpkgs "$ref" "path:${dir}/flake"
node=$(jq -r '.nodes[.nodes[.root].inputs["nixos-router"]].inputs.nixpkgs' ${dir}/flake/flake.lock)
hash=$(jq -er --arg n "$node" '.nodes[$n].locked.narHash' ${dir}/flake/flake.lock)
case $ref in
*narHash=*) pin=$ref ;;
*\?*) pin="$ref&narHash=$hash" ;;
*) pin="$ref?narHash=$hash" ;;
esac
# What the directory was like: apply refuses to go on when it changed.
cp "$config/flake.nix" "$config/settings.json" ${dir}/base/
# A newer nixos-router is one more input to lock: its source, from the tag, and
# the flake it brings, which names that source (config-flake.nix, with the
# address filled in), and the settings migrated to its schema.
router_new=false
if [ "$r_newer" = true ]; then
src="git+$repository?ref=refs/tags/$r_tag&rev=$r_rev"
echo "router-upgrade: fetching nixos-router $r_version ($(short "$r_rev"))"
# (No registry: the address is complete, and the global one is a download.)
meta=$(nix --option flake-registry "" flake prefetch --json "$src") || die "cannot fetch $src"
tree=$(jq -er .storePath <<<"$meta")
if [ ! -r "$tree/config-flake.nix" ] || [ ! -r "$tree/VERSION" ]; then
die "$r_tag is not a release this updater can build (no config-flake.nix or VERSION)"
fi
# What a release carries, made from the source: what the migration reads.
rel=${dir}/git-release
mkdir -p "$rel/migrations"
tr -d '\n' < "$tree/VERSION" > "$rel/version"
jq -er .locked.lastModified <<<"$meta" | tr -d '\n' > "$rel/serial"
printf %s "$r_rev" > "$rel/rev"
find "$tree/migrations" -name '*.jq' -exec cp {} "$rel/migrations/" \;
find "$rel/migrations" -name '*.jq' | wc -l | tr -d '\n' > "$rel/schema"
# (jq, not a shell substitution: the address has a & in it.)
jq -rRs --arg source "$src" 'gsub("@SOURCE@"; $source)' "$tree/config-flake.nix" > ${dir}/flake/flake.nix
rm -f ${dir}/flake/flake.lock
router-migrate-settings "$rel" ${dir}/flake/settings.json || die "migrating the settings to nixos-router $r_version failed"
router_new=true
fi
# The packages: the channel's revision; without a channel the one an earlier
# upgrade chose stays, else the nixos-router's own.
ref=""
pin=""
if [ -n "$channel" ]; then
ref="${up.nixpkgsRef}"
ref=''${ref//%rev%/$newest}
elif [ -r "$config/nixpkgs-pin.json" ]; then
ref=$(jq -r .ref "$config/nixpkgs-pin.json")
fi
lock=(nix flake lock)
if [ -n "$ref" ]; then lock+=(--override-input nixos-router/nixpkgs "$ref"); fi
if [ "$router_new" = true ]; then
echo "router-upgrade: locking nixos-router $r_version and the packages"
else
echo "router-upgrade: locking the packages''${newest:+ to $(short "$newest")}"
fi
"''${lock[@]}" "path:${dir}/flake"
if [ -n "$channel" ]; then
node=$(jq -r '.nodes[.nodes[.root].inputs["nixos-router"]].inputs.nixpkgs' ${dir}/flake/flake.lock)
hash=$(jq -er --arg n "$node" '.nodes[$n].locked.narHash' ${dir}/flake/flake.lock)
case $ref in
*narHash=*) pin=$ref ;;
*\?*) pin="$ref&narHash=$hash" ;;
*) pin="$ref?narHash=$hash" ;;
esac
fi
attr="path:${dir}/flake#nixosConfigurations.router.config.system"
echo "router-upgrade: evaluating the new system"
@@ -224,13 +324,19 @@ let
sed 's/^/ /' ${dir}/builds.txt | head -n 60
if [ "$(wc -l < ${dir}/builds.txt)" -gt 60 ]; then echo " ... and $(( $(wc -l < ${dir}/builds.txt) - 60 )) more"; fi
release_version=$(jq -r '.version // ""' /etc/router-release 2>/dev/null || true)
jq -n --arg channel "$channel" --arg release "$release_version" --arg rev "$newest" --arg ref "$pin" --arg version "$new_version" \
--arg time "$(date -u +%FT%TZ)" --arg download "$download" --argjson builds "$builds" \
# What changes in nixos-router itself, if it does: shown above the packages.
router_change=null
if [ "$router_new" = true ]; then
router_change=$(jq -n --arg from "$installed_router" --arg to "$r_version" --arg tag "$r_tag" --arg rev "$r_rev" \
'{from: $from, to: $to, tag: $tag, rev: $rev}')
echo " nixos-router: $installed_router -> $r_version"
fi
jq -n --arg channel "$channel" --arg release "$installed_router" --arg rev "$newest" --arg ref "$pin" --arg version "$new_version" \
--arg time "$(date -u +%FT%TZ)" --arg download "$download" --argjson builds "$builds" --argjson router "$router_change" \
--argjson reboot "$reboot" --slurpfile changes ${dir}/changes.json --rawfile buildNames ${dir}/builds.txt \
'{channel: $channel, release: $release, rev: $rev, ref: $ref, version: $version, time: $time, download: $download,
builds: $builds, buildNames: ($buildNames | split("\n") | map(select(. != "")) | .[:300]),
rebootNeeded: $reboot, changes: $changes[0]}' > ${dir}/preview.json
rebootNeeded: $reboot, router: $router, changes: $changes[0]}' > ${dir}/preview.json
rm -f ${dir}/builds.txt
echo "$new_version$([ "$reboot" = false ] || echo ' (a new kernel runs after a reboot)'): router-upgrade apply activates it"
}
@@ -251,18 +357,31 @@ let
exec 9>/run/router-update.lock
flock -n 9 || die "an update or upgrade is running"
[ ! -d ${snapshot} ] || die "an earlier update or upgrade is not confirmed yet"
cmp -s "$config/flake.nix" ${dir}/flake/flake.nix \
cmp -s "$config/flake.nix" ${dir}/base/flake.nix \
|| die "the configuration flake changed since it was previewed: preview again"
# A new nixos-router brings migrated settings: they are taken over whole.
router_to=$(jq -r '.router.to // ""' ${dir}/preview.json)
if [ -n "$router_to" ]; then
cmp -s "$config/settings.json" ${dir}/base/settings.json \
|| die "the settings changed since the upgrade was previewed: preview again"
fi
cp -a "$config" ${snapshot}
fail() {
echo "router-upgrade: $*" >&2
/run/current-system/sw/bin/router-update-restore
exit 1
}
if [ -n "$router_to" ]; then
cp ${dir}/flake/flake.nix "$config/flake.nix"
cp ${dir}/flake/settings.json "$config/settings.json"
fi
cp ${dir}/flake/flake.lock "$config/flake.lock"
jq '{channel, rev, ref}' ${dir}/preview.json > "$config/nixpkgs-pin.json"
# The packages that were chosen stay chosen when nixos-router is updated later.
if [ -n "$(jq -r '.ref // ""' ${dir}/preview.json)" ]; then
jq '{channel, rev, ref}' ${dir}/preview.json > "$config/nixpkgs-pin.json"
fi
echo "router-upgrade: building and activating $(jq -r .version ${dir}/preview.json)"
echo "router-upgrade: building and activating ''${router_to:+nixos-router $router_to on }$(jq -r .version ${dir}/preview.json)"
if ! router-apply ''${timeout:+"$timeout"}; then
if systemctl is-active --quiet router-rollback.timer; then
# Activation failed half way: the rollback restores the configuration.
@@ -271,7 +390,7 @@ let
fi
fail "the upgrade failed; the previous system is back"
fi
rm -rf ${dir}/preview.json ${dir}/flake ${dir}/result
rm -rf ${dir}/preview.json ${dir}/flake ${dir}/base ${dir}/git-release ${dir}/result
if systemctl is-active --quiet router-rollback.timer; then
echo "router-upgrade: active; confirm it (router-confirm, or in the web UI) or the previous system comes back"
else
@@ -281,6 +400,8 @@ let
case $cmd in
check) check ;;
# For the timer: a router with nothing to look at, or no internet, is no failure.
daily) check || echo "router-upgrade: nothing was looked at" >&2 ;;
releases) releases ;;
preview) preview "$@" ;;
download) download ;;
@@ -310,15 +431,16 @@ in
# The web UI starts this rather than running anything itself, so a switch
# that restarts the UI does not cut an upgrade short; a switch must not
# restart or stop it either (router-apply is what runs the switch).
# Which stable releases exist, once a day: the web UI says when a newer one than
# the followed channel appears. It only asks the channel server and writes a small
# file, so it is a unit of its own that never holds up an upgrade.
# Is there something newer (a nixos-router release, a nixpkgs revision of the
# channel, a NixOS release), once a day: the web UI says so on the Overview. It
# only asks the servers and writes small files, so it is a unit of its own that
# never holds up an upgrade.
systemd.services.router-upgrade-notice = {
description = "Look for new NixOS releases";
description = "Look for newer versions of nixos-router and NixOS";
path = [ "/run/current-system/sw" ];
serviceConfig = {
Type = "oneshot";
ExecStart = "${lib.getExe upgrade} releases";
ExecStart = "${lib.getExe upgrade} daily";
TimeoutStartSec = "5min";
};
};