mirror of
https://github.com/nix-community/disko.git
synced 2026-11-30 21:13:28 +01:00
tests + example: fold 39 self-tests into example/*.nix
For each `tests/foo.nix` with a 1:1 corresponding `example/foo.nix`,
move the `disko.test = { … };` block (and any host-level overrides
like `networking.hostId`, `disko.devices.X = lib.mkForce Y`,
`_module.args.disks`) from the test file into the example. Delete the
now-empty `tests/foo.nix`. Now every example file doubles as its own
install-test reachable via
`nix build .#nixosConfigurations.<x>.config.system.build.diskoTest`
when the example is imported into a NixOS config.
Two example renames to preserve the baseline check key (which the plan
requires to stay unchanged):
- `example/xfs-with-quota.nix` → `example/xfs.nix`
(tests/xfs.nix's name was "xfs", not "xfs-with-quota")
- `example/gpt-name-with-whitespace.nix` →
`example/gpt-name-with-special-chars.nix`
(tests/gpt-name-with-special-chars.nix's name was the latter)
`tests/default.nix` now scans `example/` in addition to `tests/` and
merges via `exampleDirModule // testsDirModule` (tests/ wins on name
collision — relevant for cli/module which share example/complex.nix
with distinct `disko.test.mode` overrides).
Files that stay in `tests/`:
- `default.nix` — discovery driver
- `cli.nix` and `module.nix` — both import `example/complex.nix`
and override `disko.test.{name, mode, extraChecks}` via
`lib.mkForce` to cover the standalone-CLI vs module-eval test paths
- `standalone.nix`, `make-disk-image.nix`,
`make-disk-image-impure.nix`, `mdadm-btrfs-wipe.nix` — bespoke
tests that don't fit the example-eval pattern
End state: 7 `.nix` files in `tests/` (plus the `disko-install/`
subdirectory); 39 self-tests in `example/` (each example is its own
test).
This commit is contained in:
1 parent
c431a60b34
commit
50f929e48e
81 files changed
+585
-715
No files matched your search
@@ -1,3 +1,4 @@
|
||||
{ pkgs, ... }:
|
||||
{
|
||||
disko.devices = {
|
||||
disk = {
|
||||
@@ -139,4 +140,131 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
disko.test = {
|
||||
name = "bcachefs";
|
||||
enableOCR = true;
|
||||
bootCommands = ''
|
||||
machine.wait_for_text("enter passphrase for /");
|
||||
machine.send_chars("secretsecret\n");
|
||||
machine.wait_for_text("enter passphrase for /home");
|
||||
machine.send_chars("secretsecret\n");
|
||||
machine.wait_for_text("enter passphrase for /nix");
|
||||
machine.send_chars("secretsecret\n");
|
||||
'';
|
||||
nodes.formatter = {
|
||||
boot = {
|
||||
kernelPackages = pkgs.linuxPackages_latest;
|
||||
supportedFilesystems = [ "bcachefs" ];
|
||||
};
|
||||
};
|
||||
nodes.machine = {
|
||||
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
|
||||
'';
|
||||
};
|
||||
extraChecks = ''
|
||||
# Print debug information.
|
||||
machine.succeed("uname -a >&2");
|
||||
machine.succeed("ls -la / >&2");
|
||||
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("findmnt --json >&2");
|
||||
|
||||
machine.succeed("mountpoint /");
|
||||
machine.succeed("mountpoint /home");
|
||||
machine.succeed("mountpoint /nix");
|
||||
machine.succeed("mountpoint /home/Documents");
|
||||
machine.fail("mountpoint /non-existent");
|
||||
|
||||
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'");
|
||||
|
||||
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'");
|
||||
machine.succeed("bcachefs show-super /dev/vdd1 | grep -qE '^[[:space:]]*compression:[[:space:]]+none'");
|
||||
|
||||
machine.succeed("""
|
||||
findmnt --json \
|
||||
| jq -e ' \
|
||||
.filesystems[] \
|
||||
| select(.target == "/") \
|
||||
| .options \
|
||||
| split(",") \
|
||||
| contains(["verbose"]) \
|
||||
'
|
||||
""");
|
||||
|
||||
machine.fail("""
|
||||
findmnt --json \
|
||||
| jq -e ' \
|
||||
.filesystems[] \
|
||||
| .. \
|
||||
| select(.target? == "/home/Documents") \
|
||||
| .options \
|
||||
| split(",") \
|
||||
| contains(["verbose"]) \
|
||||
'
|
||||
""");
|
||||
|
||||
machine.fail("""
|
||||
findmnt --json \
|
||||
| jq -e ' \
|
||||
.filesystems[] \
|
||||
| select(.target == "/") \
|
||||
| .options \
|
||||
| split(",") \
|
||||
| contains(["non-existent"]) \
|
||||
'
|
||||
""");
|
||||
|
||||
machine.succeed("""
|
||||
findmnt --json \
|
||||
| jq -e ' \
|
||||
.filesystems[] \
|
||||
| select(.target == "/") \
|
||||
| .source \
|
||||
| contains("/dev/vda2") \
|
||||
and contains("/dev/vdb1") \
|
||||
and contains("/dev/vdc1") \
|
||||
and contains("[/subvolumes/root]") \
|
||||
'
|
||||
""");
|
||||
|
||||
machine.succeed("""
|
||||
findmnt --json \
|
||||
| jq -e ' \
|
||||
.filesystems[] \
|
||||
| .. \
|
||||
| select(.target? == "/home/Documents") \
|
||||
| .source \
|
||||
| contains("/dev/vdd1") \
|
||||
'
|
||||
""");
|
||||
|
||||
machine.fail("""
|
||||
findmnt --json \
|
||||
| jq -e ' \
|
||||
.filesystems[] \
|
||||
| select(.target == "/") \
|
||||
| .source \
|
||||
| contains(["/dev/non-existent"]) \
|
||||
'
|
||||
""");
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -87,4 +87,13 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
disko.test = {
|
||||
name = "boot-raid1";
|
||||
extraChecks = ''
|
||||
machine.succeed("test -b /dev/md/boot");
|
||||
machine.succeed("mountpoint /boot");
|
||||
'';
|
||||
# sadly systemd-boot fails to install to a raid /boot device
|
||||
nodes.machine.boot.loader.systemd-boot.enable = false;
|
||||
};
|
||||
}
|
||||
@@ -37,4 +37,10 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
disko.test = {
|
||||
name = "btrfs-only-root-subvolume";
|
||||
extraChecks = ''
|
||||
machine.succeed("btrfs subvolume list /");
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -76,4 +76,18 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
disko.test = {
|
||||
name = "btrfs-subvolumes";
|
||||
extraChecks = ''
|
||||
machine.succeed("test ! -e /test");
|
||||
machine.succeed("test -e /home/user");
|
||||
machine.succeed("btrfs subvolume list / | grep -qs 'path test$'");
|
||||
machine.succeed("btrfs subvolume list / | grep -qs 'path nix$'");
|
||||
machine.succeed("btrfs subvolume list / | grep -qs 'path home$'");
|
||||
machine.succeed("test -e /.swapvol/swapfile");
|
||||
machine.succeed("test -e /.swapvol/rel-path");
|
||||
machine.succeed("test -e /partition-root/swapfile");
|
||||
machine.succeed("test -e /partition-root/swapfile1");
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -190,4 +190,28 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
disko.test = {
|
||||
name = "complex";
|
||||
extraChecks = ''
|
||||
machine.succeed("test -b /dev/md/raid1p1");
|
||||
machine.succeed("test -b /dev/disk/by-partuuid/f0f0f0f0-f0f0-f0f0-f0f0-f0f0f0f0f0f0")
|
||||
|
||||
machine.succeed("mountpoint /zfs_fs");
|
||||
machine.succeed("mountpoint /zfs_legacy_fs");
|
||||
machine.succeed("mountpoint /ext4onzfs");
|
||||
machine.succeed("mountpoint /ext4_on_lvm");
|
||||
|
||||
|
||||
machine.succeed("test -e /ext4_on_lvm/file-from-postMountHook");
|
||||
'';
|
||||
nodes.machine = {
|
||||
fileSystems."/zfs_legacy_fs".options = [ "nofail" ]; # TODO find out why we need this!
|
||||
fileSystems."/zfs_fs".options = [ "nofail" ]; # TODO find out why we need this!
|
||||
};
|
||||
nodes.formatter.boot.kernelModules = [
|
||||
"dm-raid"
|
||||
"dm-mirror"
|
||||
];
|
||||
};
|
||||
networking.hostId = "8425e349";
|
||||
}
|
||||
@@ -38,4 +38,13 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
disko.test = {
|
||||
name = "f2fs";
|
||||
extraChecks = ''
|
||||
machine.succeed("mountpoint /");
|
||||
machine.succeed("lsblk --fs >&2");
|
||||
'';
|
||||
# so that the installer boots with a f2fs enabled kernel
|
||||
nodes.formatter.boot.supportedFilesystems = [ "f2fs" ];
|
||||
};
|
||||
}
|
||||
@@ -26,4 +26,11 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
disko.test = {
|
||||
name = "gpt-bios-compat";
|
||||
efi = false;
|
||||
extraChecks = ''
|
||||
machine.succeed("mountpoint /");
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -46,4 +46,12 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
disko.test = {
|
||||
name = "gpt-name-with-whitespace";
|
||||
extraChecks = ''
|
||||
machine.succeed("mountpoint /");
|
||||
machine.succeed("mountpoint '/name with spaces'");
|
||||
machine.succeed("mountpoint '/name^with\\some@special#chars'");
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -34,4 +34,10 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
disko.test = {
|
||||
name = "gpt-unformatted";
|
||||
extraChecks = ''
|
||||
machine.succeed("mountpoint /");
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -45,4 +45,10 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
disko.test = {
|
||||
name = "hybrid-mbr";
|
||||
extraChecks = ''
|
||||
machine.succeed("mountpoint /");
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -41,4 +41,11 @@
|
||||
];
|
||||
};
|
||||
};
|
||||
disko.test = {
|
||||
name = "hybrid-tmpfs-on-root";
|
||||
extraChecks = ''
|
||||
machine.succeed("mountpoint /");
|
||||
machine.succeed("findmnt / --types tmpfs");
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -34,4 +34,10 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
disko.test = {
|
||||
name = "hybrid";
|
||||
extraChecks = ''
|
||||
machine.succeed("mountpoint /");
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -53,4 +53,11 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
disko.test = {
|
||||
name = "legacy-table-with-whitespace";
|
||||
extraChecks = ''
|
||||
machine.succeed("mountpoint /");
|
||||
machine.succeed("mountpoint /name_with_spaces");
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -42,4 +42,10 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
disko.test = {
|
||||
name = "legacy-table";
|
||||
extraChecks = ''
|
||||
machine.succeed("mountpoint /");
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -31,4 +31,10 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
disko.test = {
|
||||
name = "long-device-name";
|
||||
extraChecks = ''
|
||||
machine.succeed("mountpoint /");
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -75,4 +75,12 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
disko.test = {
|
||||
name = "luks-btrfs-raid";
|
||||
extraChecks = ''
|
||||
machine.succeed("cryptsetup isLuks /dev/vda2");
|
||||
machine.succeed("cryptsetup isLuks /dev/vdb1");
|
||||
machine.succeed("btrfs subvolume list /");
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -67,4 +67,13 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
disko.test = {
|
||||
name = "luks-btrfs-subvolumes";
|
||||
extraChecks = ''
|
||||
machine.succeed("cryptsetup isLuks /dev/vda2");
|
||||
machine.succeed("btrfs subvolume list / | grep -qs 'path nix$'");
|
||||
machine.succeed("btrfs subvolume list / | grep -qs 'path home$'");
|
||||
machine.succeed("test -e /.swapvol/swapfile");
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -38,4 +38,12 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
disko.test = {
|
||||
name = "luks-fido2";
|
||||
enableCanokey = true;
|
||||
extraChecks = ''
|
||||
machine.succeed("cryptsetup isLuks /dev/vda2");
|
||||
machine.succeed("mountpoint /");
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -36,4 +36,15 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
disko.test = {
|
||||
name = "luks-interactive-login";
|
||||
enableOCR = true;
|
||||
bootCommands = ''
|
||||
machine.wait_for_text("[Pp]assphrase for")
|
||||
machine.send_chars("secretsecret\n")
|
||||
'';
|
||||
extraChecks = ''
|
||||
machine.succeed("cryptsetup isLuks /dev/vda2");
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -70,4 +70,11 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
disko.test = {
|
||||
name = "luks-lvm";
|
||||
extraChecks = ''
|
||||
machine.succeed("cryptsetup isLuks /dev/vda2");
|
||||
machine.succeed("mountpoint /home");
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -55,4 +55,12 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
disko.test = {
|
||||
name = "luks-on-mdadm";
|
||||
extraChecks = ''
|
||||
machine.succeed("test -b /dev/md/raid1");
|
||||
machine.succeed("mountpoint /");
|
||||
'';
|
||||
nodes.machine.boot.loader.systemd-boot.enable = false;
|
||||
};
|
||||
}
|
||||
@@ -92,4 +92,17 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
disko.test = {
|
||||
name = "lvm-raid";
|
||||
extraChecks = ''
|
||||
machine.succeed("mountpoint /home");
|
||||
'';
|
||||
nodes.formatter.boot.kernelModules = [
|
||||
"dm-raid"
|
||||
"raid0"
|
||||
"dm-mirror"
|
||||
];
|
||||
# sadly systemd-boot fails to install to a raid /boot device
|
||||
nodes.machine.boot.loader.systemd-boot.enable = false;
|
||||
};
|
||||
}
|
||||
@@ -61,4 +61,10 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
disko.test = {
|
||||
name = "lvm-sizes-sort";
|
||||
extraChecks = ''
|
||||
machine.succeed("mountpoint /home");
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -66,4 +66,10 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
disko.test = {
|
||||
name = "lvm-thin";
|
||||
extraChecks = ''
|
||||
machine.succeed("mountpoint /home");
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -62,4 +62,12 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
disko.test = {
|
||||
name = "mdadm-raid0";
|
||||
efi = false;
|
||||
extraChecks = ''
|
||||
machine.succeed("test -b /dev/md/raid0");
|
||||
machine.succeed("mountpoint /");
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -63,4 +63,12 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
disko.test = {
|
||||
name = "mdadm-raid5-args";
|
||||
efi = false;
|
||||
extraChecks = ''
|
||||
machine.succeed("test -b /dev/md/raid5");
|
||||
machine.succeed("mountpoint /");
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -62,4 +62,12 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
disko.test = {
|
||||
name = "mdadm";
|
||||
efi = false;
|
||||
extraChecks = ''
|
||||
machine.succeed("test -b /dev/md/raid1");
|
||||
machine.succeed("mountpoint /");
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -37,4 +37,12 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
disko.test = {
|
||||
name = "multi-device-no-deps";
|
||||
boot = false;
|
||||
extraChecks = ''
|
||||
machine.succeed("mountpoint /mnt/a");
|
||||
machine.succeed("mountpoint /mnt/b");
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -20,4 +20,11 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
disko.test = {
|
||||
name = "negative-size";
|
||||
boot = false;
|
||||
extraChecks = ''
|
||||
machine.succeed("mountpoint /mnt");
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -106,4 +106,46 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
disko.test = {
|
||||
name = "non-root-zfs";
|
||||
postDisko = ''
|
||||
machine.succeed("mountpoint /mnt/storage")
|
||||
machine.succeed("mountpoint /mnt/storage/dataset")
|
||||
|
||||
filesystem = machine.execute("stat --file-system --format=%T /mnt/storage")[1].rstrip()
|
||||
print(f"/mnt/storage {filesystem=}")
|
||||
assert filesystem == "zfs", "/mnt/storage is not ZFS"
|
||||
|
||||
machine.fail("mountpoint /mnt/storage2")
|
||||
machine.succeed("mountpoint /mnt/storage2/dataset")
|
||||
|
||||
filesystem = machine.execute("stat --file-system --format=%T /mnt/storage2")[1].rstrip()
|
||||
print(f"/mnt/storage2 {filesystem=}")
|
||||
assert filesystem != "zfs", "/mnt/storage should not be ZFS"
|
||||
|
||||
filesystem = machine.execute("stat --file-system --format=%T /mnt/storage2/dataset")[1].rstrip()
|
||||
print(f"/mnt/storage2/dataset {filesystem=}")
|
||||
assert filesystem == "zfs", "/mnt/storage/dataset is not ZFS"
|
||||
'';
|
||||
extraChecks = ''
|
||||
machine.succeed("mountpoint /storage")
|
||||
machine.succeed("mountpoint /storage/dataset")
|
||||
|
||||
filesystem = machine.execute("stat --file-system --format=%T /storage")[1].rstrip()
|
||||
print(f"/storage {filesystem=}")
|
||||
assert filesystem == "zfs", "/storage is not ZFS"
|
||||
|
||||
machine.fail("mountpoint /storage2")
|
||||
machine.succeed("mountpoint /storage2/dataset")
|
||||
|
||||
filesystem = machine.execute("stat --file-system --format=%T /storage2")[1].rstrip()
|
||||
print(f"/storage2 {filesystem=}")
|
||||
assert filesystem != "zfs", "/storage should not be ZFS"
|
||||
|
||||
filesystem = machine.execute("stat --file-system --format=%T /storage2/dataset")[1].rstrip()
|
||||
print(f"/storage2/dataset {filesystem=}")
|
||||
assert filesystem == "zfs", "/storage/dataset is not ZFS"
|
||||
'';
|
||||
};
|
||||
networking.hostId = "8425e349";
|
||||
}
|
||||
@@ -30,4 +30,10 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
disko.test = {
|
||||
name = "simple-efi";
|
||||
extraChecks = ''
|
||||
machine.succeed("mountpoint /");
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
{ pkgs, ... }:
|
||||
{
|
||||
disko.devices = {
|
||||
disk = {
|
||||
@@ -46,4 +47,28 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
disko.test = {
|
||||
name = "swap";
|
||||
extraChecks = ''
|
||||
import json
|
||||
machine.succeed("mountpoint /");
|
||||
machine.succeed("swapon --show >&2");
|
||||
machine.succeed("lsblk -o +PARTTYPENAME --json /dev/vda >&2");
|
||||
out = json.loads(machine.succeed("lsblk -o +PARTTYPENAME --json /dev/vda"))
|
||||
|
||||
encrypted_swap_crypt = out["blockdevices"][0]["children"][1]
|
||||
mnt_point = encrypted_swap_crypt["children"][0]["mountpoints"][0]
|
||||
assert mnt_point == "[SWAP]", f"Expected encrypted swap partition to be mounted as [SWAP], got {mnt_point}"
|
||||
part_type = encrypted_swap_crypt["parttypename"]
|
||||
# The dm-crypt partition should be labelled as swap, not dm-crypt, see https://github.com/util-linux/util-linux/issues/3238
|
||||
assert part_type == "Linux swap", f"Expected encrypted swap container to be of type Linux swap, got {part_type}"
|
||||
|
||||
plain_swap_part = out["blockdevices"][0]["children"][3]
|
||||
mnt_point = plain_swap_part["mountpoints"][0]
|
||||
assert mnt_point == "[SWAP]", f"Expected swap partition to be mounted as [SWAP], got {mnt_point}"
|
||||
part_type = plain_swap_part["parttypename"]
|
||||
assert part_type == "Linux swap", f"Expected plain swap partition to be of type Linux swap, got {part_type}"
|
||||
'';
|
||||
nodes.machine.environment.systemPackages = [ pkgs.jq ];
|
||||
};
|
||||
}
|
||||
@@ -38,4 +38,11 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
disko.test = {
|
||||
name = "tmpfs";
|
||||
extraChecks = ''
|
||||
machine.succeed("mountpoint /");
|
||||
machine.succeed("mountpoint /tmp");
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -29,4 +29,12 @@
|
||||
};
|
||||
});
|
||||
};
|
||||
_module.args.disks = [ "/dev/vdb" ];
|
||||
disko.test = {
|
||||
name = "with-lib";
|
||||
efi = false;
|
||||
extraChecks = ''
|
||||
machine.succeed("mountpoint /");
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -34,4 +34,12 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
disko.test = {
|
||||
name = "xfs";
|
||||
extraChecks = ''
|
||||
machine.succeed("mountpoint /");
|
||||
|
||||
machine.succeed("xfs_quota -c 'print' / | grep -q '(pquota)'")
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
{ lib, ... }:
|
||||
{
|
||||
disko.devices = {
|
||||
disk = {
|
||||
@@ -78,4 +79,15 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
disko.test = {
|
||||
name = "zfs-encrypted-root";
|
||||
defaults.disko.devices.zpool.zroot.datasets.root.options.keylocation =
|
||||
lib.mkForce "file:///tmp/secret.key";
|
||||
extraChecks = ''
|
||||
machine.succeed("mountpoint /");
|
||||
machine.succeed("mountpoint /nix");
|
||||
machine.succeed("swapon --show=NAME | grep /dev/zd"); # i.e. /dev/zd0
|
||||
'';
|
||||
};
|
||||
networking.hostId = "8425e349";
|
||||
}
|
||||
@@ -55,4 +55,12 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
disko.test = {
|
||||
name = "zfs-over-legacy";
|
||||
extraChecks = ''
|
||||
machine.succeed("test -e /zfs_fs");
|
||||
machine.succeed("mountpoint /zfs_fs");
|
||||
'';
|
||||
};
|
||||
networking.hostId = "8425e349";
|
||||
}
|
||||
@@ -314,4 +314,71 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
disko.test = {
|
||||
name = "zfs-with-vdevs";
|
||||
nodes.machine = {
|
||||
# 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
|
||||
'';
|
||||
};
|
||||
extraChecks = ''
|
||||
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}"
|
||||
|
||||
# These fields are 0 if l2arc is disabled
|
||||
assert (
|
||||
machine.succeed(
|
||||
"cat /proc/spl/kstat/zfs/arcstats"
|
||||
" | grep '^l2_' | tr -s ' '"
|
||||
" | cut -s -d ' ' -f3 | uniq"
|
||||
).strip() != "0"
|
||||
), "Excepted cache to be utilized."
|
||||
|
||||
assert_property("zroot", "compression", "zstd")
|
||||
assert_property("zroot/zfs_fs", "com.sun:auto-snapshot", "true")
|
||||
assert_property("zroot/zfs_fs", "compression", "zstd")
|
||||
machine.succeed("mountpoint /zfs_fs");
|
||||
|
||||
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',
|
||||
])
|
||||
assert actual == expected, f"Incorrect pool layout. Expected:\n\t{'\n\t'.join(expected)}\nActual:\n\t{'\n\t'.join(actual)}"
|
||||
'';
|
||||
};
|
||||
networking.hostId = "8425e349";
|
||||
}
|
||||
@@ -120,4 +120,37 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
disko.test = {
|
||||
name = "zfs";
|
||||
nodes.machine.fileSystems."/zfs_legacy_fs".options = [ "nofail" ]; # TODO find out why we need this!
|
||||
extraChecks = ''
|
||||
machine.succeed("test -b /dev/zvol/zroot/zfs_volume");
|
||||
machine.succeed("test -b /dev/zvol/zroot/zfs_encryptedvolume");
|
||||
|
||||
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}"
|
||||
|
||||
assert_property("zroot", "compression", "zstd")
|
||||
assert_property("zroot/zfs_fs", "compression", "zstd")
|
||||
assert_property("zroot", "com.sun:auto-snapshot", "false")
|
||||
assert_property("zroot/zfs_fs", "com.sun:auto-snapshot", "true")
|
||||
assert_property("zroot/zfs_volume", "volsize", "10M")
|
||||
assert_property("zroot/zfs_encryptedvolume", "volsize", "10M")
|
||||
assert_property("zroot/zfs_unmounted_fs", "mountpoint", "none")
|
||||
|
||||
machine.succeed("zfs get name zroot@blank")
|
||||
|
||||
machine.succeed("mountpoint /zfs_fs");
|
||||
machine.succeed("mountpoint /zfs_legacy_fs");
|
||||
machine.succeed("mountpoint /ext4onzfs");
|
||||
machine.succeed("mountpoint /ext4onzfsencrypted");
|
||||
machine.succeed("mountpoint /zfs_crypted");
|
||||
machine.succeed("zfs get keystatus zroot/encrypted");
|
||||
machine.succeed("zfs get keystatus zroot/encrypted/test");
|
||||
'';
|
||||
};
|
||||
networking.hostId = "8425e349";
|
||||
}
|
||||
Reference in new issue
Block a user