From 17e2eee82276dc631aef465e799d01a1b1421649 Mon Sep 17 00:00:00 2001 From: a-kenji Date: Wed, 6 May 2026 21:16:30 +0200 Subject: [PATCH 1/7] flake: bump nixpkgs --- flake.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flake.lock b/flake.lock index d98f5a2..9dfdf53 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1773628058, - "narHash": "sha256-hpXH0z3K9xv0fHaje136KY872VT2T5uwxtezlAskQgY=", + "lastModified": 1778036283, + "narHash": "sha256-62EWg6lI0qyzm7oAx5cAnGkLutvJsRBe0KkEW2JDZCE=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "f8573b9c935cfaa162dd62cc9e75ae2db86f85df", + "rev": "ed67bc86e84e51d4a88e73c7fd36006dc876476f", "type": "github" }, "original": { From 8ebce63228c7fe1b622d4256dbf579ae17482054 Mon Sep 17 00:00:00 2001 From: a-kenji Date: Wed, 6 May 2026 21:16:58 +0200 Subject: [PATCH 2/7] tests: register dynamically-created machines with the driver The nixpkgs test driver was refactored: `driver.machines` is now a computed property that returns a fresh sorted list combining `driver.machines_qemu` and `driver.machines_nspawn`. Appending to the property therefore mutates only the temporary returned list, so the machines created via `create_test_machine` are no longer registered with the driver. --- lib/tests.nix | 2 +- tests/disko-install/default.nix | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tests.nix b/lib/tests.nix index 2c75699..fdc79bd 100644 --- a/lib/tests.nix +++ b/lib/tests.nix @@ -342,7 +342,7 @@ let ] ''} machine = create_machine(start_command=" ".join(start_command), **kwargs) - driver.machines.append(machine) + driver.machines_qemu.append(machine) return machine machine.start() diff --git a/tests/disko-install/default.nix b/tests/disko-install/default.nix index 9999ba2..244baa9 100644 --- a/tests/disko-install/default.nix +++ b/tests/disko-install/default.nix @@ -48,7 +48,7 @@ pkgs.testers.nixosTest { "virtio-blk-pci,drive=drive1", ] machine = create_machine(start_command=" ".join(start_command), **kwargs) - driver.machines.append(machine) + driver.machines_qemu.append(machine) return machine machine.succeed("lsblk >&2") From baf057aa5b861c549b9ee92807e43ae49ab50cf6 Mon Sep 17 00:00:00 2001 From: a-kenji Date: Wed, 6 May 2026 21:17:15 +0200 Subject: [PATCH 3/7] lib/tests: stage the test password file under systemd initrd `boot.initrd.preDeviceCommands` only runs in the script-based stage 1 and is gated on `!config.boot.initrd.systemd.enable`. Tests that enable systemd initrd therefore never get `/tmp/secret.key` staged, and disko's encrypted-filesystem mount hooks fail to find the configured `passwordFile`. --- lib/tests.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/tests.nix b/lib/tests.nix index fdc79bd..c169d94 100644 --- a/lib/tests.nix +++ b/lib/tests.nix @@ -142,6 +142,9 @@ let boot.initrd.preDeviceCommands = lib.mkIf (!config.boot.initrd.systemd.enable) '' echo -n 'secretsecret' > /tmp/secret.key ''; + boot.initrd.secrets = lib.mkIf config.boot.initrd.systemd.enable { + "/tmp/secret.key" = pkgs.writeText "secret.key" "secretsecret"; + }; boot.consoleLogLevel = lib.mkForce 100; boot.loader.systemd-boot.enable = lib.mkDefault efi; }; From 21d9daf2552f32c531a6c9fbbc21a9fdfdf82df0 Mon Sep 17 00:00:00 2001 From: a-kenji Date: Wed, 6 May 2026 21:17:28 +0200 Subject: [PATCH 4/7] tests/disko-install: drop default value for oldmachine --- tests/disko-install/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/disko-install/default.nix b/tests/disko-install/default.nix index 244baa9..99b9e99 100644 --- a/tests/disko-install/default.nix +++ b/tests/disko-install/default.nix @@ -32,7 +32,7 @@ pkgs.testers.nixosTest { testScript = '' def create_test_machine( - oldmachine=None, **kwargs + oldmachine, **kwargs ): # taken from start_command = [ "${pkgs.qemu_test}/bin/qemu-kvm", From 403186440c93f52878768bca4602f35e3cafbc5b Mon Sep 17 00:00:00 2001 From: a-kenji Date: Wed, 6 May 2026 21:17:40 +0200 Subject: [PATCH 5/7] lib/types/bcachefs_filesystem: tolerate already-unlocked filesystem --- lib/types/bcachefs_filesystem.nix | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/types/bcachefs_filesystem.nix b/lib/types/bcachefs_filesystem.nix index 8a45367..232f9e1 100644 --- a/lib/types/bcachefs_filesystem.nix +++ b/lib/types/bcachefs_filesystem.nix @@ -191,9 +191,11 @@ ( TEMPDIR="$(mktemp -d)"; MNTPOINT="$(mktemp -d)"; - ${lib.optionalString ( - config.passwordFile != null - ) ''bcachefs unlock -k session "/dev/disk/by-uuid/${config.uuid}" < "${config.passwordFile}";''} + ${lib.optionalString (config.passwordFile != null) '' + if ! bcachefs unlock -k session "/dev/disk/by-uuid/${config.uuid}" < "${config.passwordFile}"; then + test -d "/sys/fs/bcachefs/${config.uuid}"; + fi; + ''} mount \ -t bcachefs \ -o "${lib.concatStringsSep "," (lib.unique ([ "X-mount.mkdir" ] ++ config.mountOptions))}" \ @@ -228,9 +230,11 @@ # @todo Figure out why the "X-mount.mkdir" option here doesn't seem to work, # necessitating running `mkdir` here. mkdir -p "${rootMountPoint}${subvolume.mountpoint}"; - ${lib.optionalString ( - config.passwordFile != null - ) ''bcachefs unlock -k session "/dev/disk/by-uuid/${config.uuid}" < "${config.passwordFile}";''} + ${lib.optionalString (config.passwordFile != null) '' + if ! bcachefs unlock -k session "/dev/disk/by-uuid/${config.uuid}" < "${config.passwordFile}"; then + test -d "/sys/fs/bcachefs/${config.uuid}"; + fi; + ''} mount \ -t bcachefs \ -o "${ @@ -260,9 +264,11 @@ # @todo Figure out why the "X-mount.mkdir" option here doesn't seem to work, # necessitating running `mkdir` here. mkdir -p "${rootMountPoint}${config.mountpoint}"; - ${lib.optionalString ( - config.passwordFile != null - ) ''bcachefs unlock -k session "/dev/disk/by-uuid/${config.uuid}" < "${config.passwordFile}";''} + ${lib.optionalString (config.passwordFile != null) '' + if ! bcachefs unlock -k session "/dev/disk/by-uuid/${config.uuid}" < "${config.passwordFile}"; then + test -d "/sys/fs/bcachefs/${config.uuid}"; + fi; + ''} mount \ -t bcachefs \ -o "${lib.concatStringsSep "," (lib.unique ([ "X-mount.mkdir" ] ++ config.mountOptions))}" \ From e40d944decb3681687534f25fe7e841d5b7cb98b Mon Sep 17 00:00:00 2001 From: a-kenji Date: Wed, 6 May 2026 21:17:56 +0200 Subject: [PATCH 6/7] tests/bcachefs: read filesystem metadata from sysfs `bcachefs-tools`: `v1.33.1` cannot read the superblock from a mounted device. The kernel returns EBUSY whenever the filesystem is already mounted, so every `bcachefs show-super /dev/vd*` assertion in this test now fails on the booted system. --- tests/bcachefs.nix | 62 +++++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/tests/bcachefs.nix b/tests/bcachefs.nix index a6326f3..97cca3b 100644 --- a/tests/bcachefs.nix +++ b/tests/bcachefs.nix @@ -25,12 +25,6 @@ diskoLib.testLib.makeDiskoTest { environment.systemPackages = [ pkgs.jq ]; - boot.initrd.extraUtilsCommands = '' - # Copy tools for bcachefs - copy_bin_and_libs ${pkgs.lib.getOutput "mount" pkgs.util-linux}/bin/mount - copy_bin_and_libs ${pkgs.bcachefs-tools}/bin/bcachefs - copy_bin_and_libs ${pkgs.bcachefs-tools}/bin/mount.bcachefs - ''; }; extraTestScript = '' # Print debug information. @@ -39,13 +33,23 @@ diskoLib.testLib.makeDiskoTest { machine.succeed("lsblk >&2"); machine.succeed("lsblk -f >&2"); machine.succeed("mount >&2"); - # We need to manually unlock /dev/vda2 for some reason - # even though it should already get unlocked by bootCommands - machine.succeed(r'printf "secretsecret" | bcachefs unlock -k session /dev/vda2 >&2'); - machine.succeed("bcachefs show-super /dev/vda2 >&2"); - machine.succeed("bcachefs show-super /dev/vdd1 >&2"); + machine.succeed("ls /sys/fs/bcachefs/ >&2"); machine.succeed("findmnt --json >&2"); + # bcachefs-tools >= 1.33.1 cannot read the superblock from a mounted device + def bcachefs_sysfs(mp): + src = machine.succeed(f"findmnt -no SOURCE {mp}").strip().split(":")[0] + dev = src.rsplit("/", 1)[-1] + path = machine.succeed( + "for d in /sys/fs/bcachefs/*/dev-*/block; do " + f' if [ "$(basename "$(readlink -f "$d")")" = "{dev}" ]; then ' + ' dirname "$(dirname "$d")"; break; ' + " fi; " + "done" + ).strip() + assert path, f"no bcachefs sysfs entry found for {mp} (device {dev})" + return path + # Verify existence of mountpoints. machine.succeed("mountpoint /"); machine.succeed("mountpoint /home"); @@ -53,21 +57,29 @@ diskoLib.testLib.makeDiskoTest { machine.succeed("mountpoint /home/Documents"); machine.fail("mountpoint /non-existent"); - # Verify device membership and labels. - machine.succeed("bcachefs show-super /dev/vda2 | grep 'Devices:' | grep -q '3'"); - machine.succeed("bcachefs show-super /dev/vdd1 | grep 'Devices:' | grep -q '1'"); - machine.succeed(r"bcachefs show-super /dev/vda2 | grep -qE '^[[:space:]]*Label:[[:space:]]+group_a\.vdb2'"); - machine.succeed(r"bcachefs show-super /dev/vda2 | grep -qE '^[[:space:]]*Label:[[:space:]]+group_a\.vdc1'"); - machine.succeed(r"bcachefs show-super /dev/vda2 | grep -qE '^[[:space:]]*Label:[[:space:]]+group_b\.vdd1'"); - machine.succeed(r"bcachefs show-super /dev/vdd1 | grep -qE '^[[:space:]]*Label:[[:space:]]+group_a\.vde1'"); - machine.fail("bcachefs show-super /dev/vda2 | grep 'Label:' | grep -q 'non-existent'"); + multi_sysfs = bcachefs_sysfs("/") + single_sysfs = bcachefs_sysfs("/home/Documents") - # Verify format arguments. - # Test that lza4 compression and background_compression options were set for vda2. - machine.succeed("bcachefs show-super /dev/vda2 | grep -qE '^[[:space:]]*compression:[[:space:]]+lz4'"); - machine.succeed("bcachefs show-super /dev/vda2 | grep -qE '^[[:space:]]*background_compression:[[:space:]]+lz4'"); - # Test that no compression option was set for vdd1. - machine.succeed("bcachefs show-super /dev/vdd1 | grep -qE '^[[:space:]]*compression:[[:space:]]+none'"); + # Verify device membership. + multi_devs = int(machine.succeed(f"ls -d {multi_sysfs}/dev-* | wc -l").strip()) + assert multi_devs == 3, f"Expected 3 devices in {multi_sysfs}, got {multi_devs}" + single_devs = int(machine.succeed(f"ls -d {single_sysfs}/dev-* | wc -l").strip()) + assert single_devs == 1, f"Expected 1 device in {single_sysfs}, got {single_devs}" + + # Verify labels. + multi_labels = set(machine.succeed(f"cat {multi_sysfs}/dev-*/label").split()) + expected_multi = {"group_a.vdb2", "group_a.vdc1", "group_b.vdd1"} + assert multi_labels == expected_multi, f"Expected {expected_multi}, got {multi_labels}" + single_labels = set(machine.succeed(f"cat {single_sysfs}/dev-*/label").split()) + assert single_labels == {"group_a.vde1"}, f"Expected {{'group_a.vde1'}}, got {single_labels}" + + # Verify format arguments via sysfs options. + multi_comp = machine.succeed(f"cat {multi_sysfs}/options/compression").strip() + assert multi_comp == "lz4", f"Expected lz4 compression, got {multi_comp!r}" + multi_bg = machine.succeed(f"cat {multi_sysfs}/options/background_compression").strip() + assert multi_bg == "lz4", f"Expected lz4 background_compression, got {multi_bg!r}" + single_comp = machine.succeed(f"cat {single_sysfs}/options/compression").strip() + assert single_comp == "none", f"Expected no compression, got {single_comp!r}" # Verify mount options from configuration. # Test that verbose option was set for "/". From 6795806dbc34b14235736b19bee78f97c1f4f044 Mon Sep 17 00:00:00 2001 From: Michael Hoang Date: Tue, 19 May 2026 17:19:06 +0200 Subject: [PATCH 7/7] tests/zfs-with-vdevs: fix not all vdevs detected --- lib/tests.nix | 5 ++- tests/zfs-with-vdevs.nix | 93 ++++++++++++++++++++++------------------ 2 files changed, 55 insertions(+), 43 deletions(-) diff --git a/lib/tests.nix b/lib/tests.nix index c169d94..4c7d7ed 100644 --- a/lib/tests.nix +++ b/lib/tests.nix @@ -190,7 +190,10 @@ let "cache=loose" ]; }; - boot.zfs.devNodes = "/dev/disk/by-uuid"; # needed because /dev/disk/by-id is empty in qemu-vms + # /dev/disk-by-id is empty in QEMU VMs, /dev/disk/by-uuid only shows one entry + # per ZFS pool as members use the pool's GUID, /dev/disk/by-partuuid only shows + # partitions so LVM backed members are missed. /dev is the only thing that catches all. + boot.zfs.devNodes = "/dev"; # Silence mdadm warning about missing MAILADDR or PROGRAM boot.swraid.mdadmConf = "PROGRAM ${pkgs.coreutils}/bin/true"; diff --git a/tests/zfs-with-vdevs.nix b/tests/zfs-with-vdevs.nix index 4ac5e98..7961b4b 100644 --- a/tests/zfs-with-vdevs.nix +++ b/tests/zfs-with-vdevs.nix @@ -9,23 +9,22 @@ diskoLib.testLib.makeDiskoTest { extraInstallerConfig.networking.hostId = "8425e349"; extraSystemConfig = { networking.hostId = "8425e349"; - # It looks like the 60s of NixOS is sometimes not enough for our virtio-based zpool. - # This fixes the flakeiness of the test. - boot.initrd.postResumeCommands = '' - for i in $(seq 1 120); do - if zpool list | grep -q zroot || zpool import -N zroot; then - break - fi - done - ''; }; extraTestScript = '' + import json + def assert_property(ds, property, expected_value): out = machine.succeed(f"zfs get -H {property} {ds} -o value").rstrip() assert ( out == expected_value ), f"Expected {property}={expected_value} on {ds}, got: {out}" + def canonical_path(path): + return machine.succeed(f"readlink -f {shlex.quote(path)}").strip() + + def by_partlabel(label): + return canonical_path(f"/dev/disk/by-partlabel/{label}") + # These fields are 0 if l2arc is disabled assert ( machine.succeed( @@ -40,39 +39,49 @@ diskoLib.testLib.makeDiskoTest { assert_property("zroot/zfs_fs", "compression", "zstd") machine.succeed("mountpoint /zfs_fs"); - # Take the status output and flatten it so that each device is on a single line prefixed with with the group (either - # the pool name or a designation like log/cache/spare/dedup/special) and first portion of the vdev name (empty for a - # disk from a single vdev, mirror for devices in a mirror. This makes it easy to verify that the layout is as - # expected. - group = "" - vdev = "" - actual = [] - for line in machine.succeed("zpool status -P zroot").split("\n"): - first_word = line.strip().split(" ", 1)[0] - if line.startswith("\t ") and first_word.startswith("/"): - actual.append(f"{group}{vdev}{first_word}") - elif line.startswith("\t "): - vdev = f"{first_word.split('-', 1)[0]} " - elif line.startswith("\t"): - group = f"{first_word} " - vdev = "" - actual.sort() - expected=sorted([ - 'zroot /dev/disk/by-partlabel/disk-data1-zfs', - 'zroot mirror /dev/disk/by-partlabel/disk-data2-zfs', - 'zroot mirror /dev/disk/by-partlabel/disk-data3-zfs', - 'dedup /dev/disk/by-partlabel/disk-dedup3-zfs', - 'dedup mirror /dev/disk/by-partlabel/disk-dedup1-zfs', - 'dedup mirror /dev/disk/by-partlabel/disk-dedup2-zfs', - 'special /dev/disk/by-partlabel/disk-special3-zfs', - 'special mirror /dev/disk/by-partlabel/disk-special1-zfs', - 'special mirror /dev/disk/by-partlabel/disk-special2-zfs', - 'logs /dev/disk/by-partlabel/disk-log3-zfs', - 'logs mirror /dev/disk/by-partlabel/disk-log1-zfs', - 'logs mirror /dev/disk/by-partlabel/disk-log2-zfs', - 'cache /dev/disk/by-partlabel/disk-cache-zfs', - 'spares /dev/disk/by-partlabel/disk-spare-zfs', + # `zpool status -j` groups vdevs by class at the pool level: `vdevs` (normal data, wrapped under + # the `zroot` root vdev) plus `dedup`, `special`, `logs`, `l2cache`, `spares`. Each entry in a + # group is either a leaf (just a device path) or a mirror vdev with nested `vdevs`. Bucket each + # leaf into (class, in_mirror, canonical path) and diff against the expected layout. + def collect_leaves(class_name, entries): + out = [] + for name, entry in entries.items(): + if entry.get("vdev_type") == "mirror": + out.extend((class_name, "mirror", canonical_path(child)) for child in entry["vdevs"]) + else: + out.append((class_name, "single", canonical_path(name))) + return out + + data = json.loads(machine.succeed("zpool status -P -L -j zroot")) + pool = next(iter(data["pools"].values())) + actual_leaves = sorted( + collect_leaves("normal", pool["vdevs"]["zroot"]["vdevs"]) + + collect_leaves("dedup", pool.get("dedup", {})) + + collect_leaves("special", pool.get("special", {})) + + collect_leaves("log", pool.get("logs", {})) + + collect_leaves("l2cache", pool.get("l2cache", {})) + + collect_leaves("spare", pool.get("spares", {})) + ) + expected_leaves = sorted([ + ("normal", "single", by_partlabel("disk-data1-zfs")), + ("normal", "mirror", by_partlabel("disk-data2-zfs")), + ("normal", "mirror", by_partlabel("disk-data3-zfs")), + ("dedup", "single", by_partlabel("disk-dedup3-zfs")), + ("dedup", "mirror", by_partlabel("disk-dedup1-zfs")), + ("dedup", "mirror", by_partlabel("disk-dedup2-zfs")), + ("special", "single", by_partlabel("disk-special3-zfs")), + ("special", "mirror", by_partlabel("disk-special1-zfs")), + ("special", "mirror", by_partlabel("disk-special2-zfs")), + ("log", "single", by_partlabel("disk-log3-zfs")), + ("log", "mirror", by_partlabel("disk-log1-zfs")), + ("log", "mirror", by_partlabel("disk-log2-zfs")), + ("l2cache", "single", by_partlabel("disk-cache-zfs")), + ("spare", "single", by_partlabel("disk-spare-zfs")), ]) - assert actual == expected, f"Incorrect pool layout. Expected:\n\t{'\n\t'.join(expected)}\nActual:\n\t{'\n\t'.join(actual)}" + assert actual_leaves == expected_leaves, ( + "Incorrect pool layout." + f"\nExpected: {json.dumps(expected_leaves, indent=2)}" + f"\nActual: {json.dumps(actual_leaves, indent=2)}" + ) ''; }