Say when a newer NixOS release is out

router-upgrade releases asks the channel server which stable releases exist
(daily timer, and on every check). The Overview and Packages pages tell a
router that follows a stable release when a newer one is out, and offer the
newest two releases as channels instead of a fixed list.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-24 22:10:27 +01:00
co-authored by Claude Sonnet 5.5
parent 2e4a596fdc
commit 048b53fe33
9 changed files with 241 additions and 27 deletions
+56 -4
View File
@@ -6,6 +6,8 @@
# flake.lock, so an upgrade is a new lock:
#
# router-upgrade check what the channel's newest revision is, against the running one
# router-upgrade releases which stable releases exist (nixos-26.05, nixos-26.11, ...), so the
# web UI can say when one newer than the followed channel appears
# router-upgrade preview lock a copy of the configuration flake to it and evaluate the
# system: which packages change version, how much would be
# downloaded and built (nothing is downloaded or activated)
@@ -41,8 +43,9 @@ let
];
text = ''
usage() {
echo "usage: router-upgrade check | preview [--force] [--downgrade] | download | apply [timeout] | --request" >&2
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 " 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
@@ -75,9 +78,13 @@ let
config=${cfg.directory}
mkdir -p ${dir}
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
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
fi
running_rev=$(/run/current-system/sw/bin/nixos-version --revision || true)
running_version=$(cat /run/current-system/nixos-version)
@@ -92,7 +99,30 @@ let
echo "$rev"
}
# The stable releases the channel server has (nixos-YY.05 and nixos-YY.11, from last
# year to next year), written to ${dir}/releases.json. A release that is not there yet
# answers 404. If nothing answers (no internet) the list is left as it was.
releases() {
local yy m r code answered=0
local found=()
for yy in $(( 10#$(date +%y) - 1 )) $(( 10#$(date +%y) )) $(( 10#$(date +%y) + 1 )); do
for m in 05 11; do
r="$yy.$m"
code=$(curl -sL --max-time 20 -o /dev/null -w '%{http_code}' "${up.channelsUrl}/nixos-$r/git-revision" || true)
case $code in
200) found+=("$r"); answered=1 ;;
404) answered=1 ;;
esac
done
done
[ "$answered" -eq 1 ] || return 0
jq -n --arg time "$(date -u +%FT%TZ)" '{time: $time, releases: $ARGS.positional}' --args "''${found[@]}" > ${dir}/releases.json.new
mv ${dir}/releases.json.new ${dir}/releases.json
echo "releases on the channel server: ''${found[*]:-none}"
}
check() {
releases || true
newest=$(newest_rev)
if [ "$newest" = "$running_rev" ]; then same=true; else same=false; fi
jq -n --arg channel "$channel" --arg branch "$branch" --arg time "$(date -u +%FT%TZ)" \
@@ -251,6 +281,7 @@ let
case $cmd in
check) check ;;
releases) releases ;;
preview) preview "$@" ;;
download) download ;;
apply) apply "$@" ;;
@@ -279,6 +310,27 @@ 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.
systemd.services.router-upgrade-notice = {
description = "Look for new NixOS releases";
path = [ "/run/current-system/sw" ];
serviceConfig = {
Type = "oneshot";
ExecStart = "${lib.getExe upgrade} releases";
TimeoutStartSec = "5min";
};
};
systemd.timers.router-upgrade-notice = {
wantedBy = [ "timers.target" ];
timerConfig = {
OnCalendar = "daily";
RandomizedDelaySec = "1h";
Persistent = true;
};
};
systemd.services.router-upgrade = {
description = "Look for, prepare or apply a nixpkgs upgrade";
restartIfChanged = false;