Test that an update keeps upgraded packages

The update test upgrades nixpkgs first; the pin and the lock must survive
a rolled-back update, a confirmed one and the rebuild after it. The channel
server moves to the shared test helpers.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AeFqV9dZrK6nipHkPfyM4F
This commit is contained in:
2026-11-18 08:32:13 +01:00
co-authored by Claude Sonnet 5.5
parent 7b3a83ba0b
commit 6e097b7473
3 changed files with 67 additions and 23 deletions
+1 -21
View File
@@ -63,26 +63,6 @@ let
modules = [ "${configDir}/local.nix" ]; modules = [ "${configDir}/local.nix" ];
}).config.system.build.toplevel; }).config.system.build.toplevel;
channelServer = pkgs.writeScript "channels.py" ''
#!${pkgs.python3}/bin/python3
import http.server
class Handler(http.server.SimpleHTTPRequestHandler):
def __init__(self, *args, **kwargs):
super().__init__(*args, directory="/srv/channels", **kwargs)
def do_GET(self):
parts = self.path.strip("/").split("/")
if len(parts) == 2 and parts[1] == "git-revision":
self.send_response(302)
self.send_header("Location", "/files/" + self.path.strip("/"))
self.end_headers()
else:
super().do_GET()
http.server.ThreadingHTTPServer(("0.0.0.0", 8080), Handler).serve_forever()
'';
sharedDisk = { sharedDisk = {
virtualisation.diskImage = "./target.qcow2"; virtualisation.diskImage = "./target.qcow2";
virtualisation.diskSize = 8192; virtualisation.diskSize = 8192;
@@ -121,7 +101,7 @@ pkgs.testers.runNixOSTest {
]; ];
# channels.nixos.org: <branch>/git-revision is a redirect to the file. # channels.nixos.org: <branch>/git-revision is a redirect to the file.
networking.firewall.allowedTCPPorts = [ 8080 ]; networking.firewall.allowedTCPPorts = [ 8080 ];
environment.etc."channels.py".source = channelServer; environment.etc."channels.py".source = common.channelServer pkgs;
}; };
target = { target = {
+24
View File
@@ -15,6 +15,30 @@
]; ];
}; };
# channels.nixos.org as a test sees it: `<branch>/git-revision` is a redirect to
# /files/<branch>/git-revision, served from /srv/channels on port 8080.
channelServer =
pkgs:
pkgs.writeScript "channels.py" ''
#!${pkgs.python3}/bin/python3
import http.server
class Handler(http.server.SimpleHTTPRequestHandler):
def __init__(self, *args, **kwargs):
super().__init__(*args, directory="/srv/channels", **kwargs)
def do_GET(self):
parts = self.path.strip("/").split("/")
if len(parts) == 2 and parts[1] == "git-revision":
self.send_response(302)
self.send_header("Location", "/files/" + self.path.strip("/"))
self.end_headers()
else:
super().do_GET()
http.server.ThreadingHTTPServer(("0.0.0.0", 8080), Handler).serve_forever()
'';
# `driverInteractive` uses the full QEMU, which would open a window per VM; # `driverInteractive` uses the full QEMU, which would open a window per VM;
# `nix run .#lab` wants the consoles in the terminal instead. # `nix run .#lab` wants the consoles in the terminal instead.
interactiveDefaults.virtualisation.qemu.options = [ interactiveDefaults.virtualisation.qemu.options = [
+42 -2
View File
@@ -89,6 +89,7 @@ let
stateVersion = "26.11"; stateVersion = "26.11";
}; };
router = { router = {
update.channel = "26.05";
wan.interface = "eth1"; wan.interface = "eth1";
lans.main = { lans.main = {
interface = "eth2"; interface = "eth2";
@@ -104,12 +105,18 @@ let
); );
# Only so the test driver can talk to the installed system; and a short # Only so the test driver can talk to the installed system; and a short
# rollback timeout, so that an unconfirmed update comes back soon. # rollback timeout, so that an unconfirmed update comes back soon. The
# channel is a server on the builder, and a newer nixpkgs a copy of the
# installed one (see apply.nix): what is tested is that an update keeps it.
local = pkgs.writeText "local.nix" '' local = pkgs.writeText "local.nix" ''
{ modulesPath, pkgs, ... }: { modulesPath, pkgs, ... }:
{ {
imports = [ (modulesPath + "/testing/test-instrumentation.nix") ]; imports = [ (modulesPath + "/testing/test-instrumentation.nix") ];
router.rollback.timeout = "90s"; router.rollback.timeout = "90s";
routerSettings.upgrade = {
channelsUrl = "http://192.168.10.60:8080";
nixpkgsRef = "path:/var/lib/newer-nixpkgs?lastModified=${toString self.inputs.nixpkgs.lastModified}&rev=%rev%";
};
environment.systemPackages = [ pkgs.jq ]; environment.systemPackages = [ pkgs.jq ];
} }
''; '';
@@ -184,12 +191,15 @@ pkgs.testers.runNixOSTest {
release1 release1
release2 release2
]; ];
environment.etc."channels.py".source = common.channelServer pkgs;
environment.etc."keys/good.sec".source = "${keys}/good.sec"; environment.etc."keys/good.sec".source = "${keys}/good.sec";
environment.etc."keys/evil.sec".source = "${keys}/evil.sec"; environment.etc."keys/evil.sec".source = "${keys}/evil.sec";
}; };
}; };
testScript = '' testScript = ''
import json
installer.start() installer.start()
installer.wait_for_unit("multi-user.target") installer.wait_for_unit("multi-user.target")
installer.succeed("mkdir -p /root/secrets && cp -r ${configDir} /root/secrets/config") installer.succeed("mkdir -p /root/secrets && cp -r ${configDir} /root/secrets/config")
@@ -235,6 +245,33 @@ pkgs.testers.runNixOSTest {
assert v1_flake == "path:${v1.src}", v1_flake assert v1_flake == "path:${v1.src}", v1_flake
target.succeed("test -s /etc/router-update-keys") target.succeed("test -s /etc/router-update-keys")
with subtest("the packages are upgraded before any update"):
target.succeed("cp -r ${self.inputs.nixpkgs} /var/lib/newer-nixpkgs")
builder.succeed("mkdir -p /srv/channels/files/nixos-26.05 && printf %s ${self.inputs.nixpkgs.rev} > /srv/channels/files/nixos-26.05/git-revision")
builder.succeed("systemd-run --unit=channels /etc/channels.py")
builder.wait_for_open_port(8080)
# The packages are the same, so there is only something to activate when
# the settings change too (an upgrade applies what is saved).
target.succeed("sed -i 's/192.168.10.199/192.168.10.198/' /var/lib/router/config/settings.json")
target.succeed("router-upgrade preview --force >&2")
target.succeed("router-upgrade apply 5min >&2")
target.succeed("router-confirm >&2")
target.fail("systemctl is-active router-rollback.timer")
assert json.loads(target.succeed("cat /var/lib/router/config/nixpkgs-pin.json"))["rev"] == "${self.inputs.nixpkgs.rev}"
assert "newer-nixpkgs" in target.succeed("cat /var/lib/router/config/flake.lock")
target.succeed("test ! -e /var/lib/router/config.pre-update")
pin = target.succeed("cat /var/lib/router/config/nixpkgs-pin.json")
def pinned():
assert target.succeed("cat /var/lib/router/config/nixpkgs-pin.json") == pin
# The lock names the upgraded nixpkgs, not the one the release brings.
lock = json.loads(target.succeed("cat /var/lib/router/config/flake.lock"))
node = lock["nodes"][lock["nodes"]["root"]["inputs"]["nixos-router"]]["inputs"]["nixpkgs"]
assert lock["nodes"][node]["locked"]["path"] == "/var/lib/newer-nixpkgs", lock["nodes"][node]
pinned()
sign("${tool v2 release2}", "evil", "/root/evil") sign("${tool v2 release2}", "evil", "/root/evil")
serve("/root/evil", 8001) serve("/root/evil", 8001)
sign("${tool v2 release2}", "good", "/root/good") sign("${tool v2 release2}", "good", "/root/good")
@@ -289,6 +326,7 @@ pkgs.testers.runNixOSTest {
unchanged() unchanged()
assert "Berlin" not in target.succeed("cat /var/lib/router/config/settings.json") assert "Berlin" not in target.succeed("cat /var/lib/router/config/settings.json")
assert target.succeed("readlink /etc/localtime").strip().endswith("/UTC") assert target.succeed("readlink /etc/localtime").strip().endswith("/UTC")
pinned()
target.wait_for_unit("router-webui.service") target.wait_for_unit("router-webui.service")
with subtest("the same update, pulled from a server in the web UI, can be confirmed"): with subtest("the same update, pulled from a server in the web UI, can be confirmed"):
@@ -311,7 +349,9 @@ pkgs.testers.runNixOSTest {
assert target.succeed("readlink -f /nix/var/nix/profiles/system").strip() == current() assert target.succeed("readlink -f /nix/var/nix/profiles/system").strip() == current()
assert target.succeed("readlink /etc/localtime").strip().endswith("Europe/Berlin") assert target.succeed("readlink /etc/localtime").strip().endswith("Europe/Berlin")
with subtest("the updated router rebuilds to exactly itself, offline"): with subtest("the updated router keeps the upgraded packages and rebuilds to exactly itself, offline"):
pinned()
assert flake_source() == "path:${v2.src}", flake_source()
out = target.succeed("router-apply 2>&1") out = target.succeed("router-apply 2>&1")
assert "no changes" in out, out assert "no changes" in out, out