diff --git a/tests/bcachefs.nix b/tests/bcachefs.nix index a6326f3..3347cc7 100644 --- a/tests/bcachefs.nix +++ b/tests/bcachefs.nix @@ -1,145 +1,131 @@ +{ pkgs, ... }: { - pkgs ? import { }, - diskoLib ? pkgs.callPackage ../lib { }, -}: -diskoLib.testLib.makeDiskoTest { - inherit pkgs; - name = "bcachefs"; - disko-config = ../example/bcachefs.nix; - 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"); - ''; - extraInstallerConfig = { - boot = { - kernelPackages = pkgs.linuxPackages_latest; - supportedFilesystems = [ "bcachefs" ]; + imports = [ ../example/bcachefs.nix ]; + 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" ]; + }; }; - }; - extraSystemConfig = { - 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 + 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"]) \ + ' + """); ''; }; - extraTestScript = '' - # 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"); - - # Verify existence of mountpoints. - machine.succeed("mountpoint /"); - machine.succeed("mountpoint /home"); - machine.succeed("mountpoint /nix"); - 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'"); - - # 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 mount options from configuration. - # Test that verbose option was set for "/". - machine.succeed(""" - findmnt --json \ - | jq -e ' \ - .filesystems[] \ - | select(.target == "/") \ - | .options \ - | split(",") \ - | contains(["verbose"]) \ - ' - """); - - # Test that verbose option was not set for "/home/Documents". - machine.fail(""" - findmnt --json \ - | jq -e ' \ - .filesystems[] \ - | .. \ - | select(.target? == "/home/Documents") \ - | .options \ - | split(",") \ - | contains(["verbose"]) \ - ' - """); - - # Test that non-existent option was not set for "/". - machine.fail(""" - findmnt --json \ - | jq -e ' \ - .filesystems[] \ - | select(.target == "/") \ - | .options \ - | split(",") \ - | contains(["non-existent"]) \ - ' - """); - - # Verify device composition of filesystems. - 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"]) \ - ' - """); - ''; } diff --git a/tests/boot-raid1.nix b/tests/boot-raid1.nix index e05b3db..3a6b68c 100644 --- a/tests/boot-raid1.nix +++ b/tests/boot-raid1.nix @@ -1,17 +1,12 @@ { - pkgs ? import { }, - diskoLib ? pkgs.callPackage ../lib { }, -}: -diskoLib.testLib.makeDiskoTest { - inherit pkgs; - name = "boot-raid1"; - disko-config = ../example/boot-raid1.nix; - extraTestScript = '' - machine.succeed("test -b /dev/md/boot"); - machine.succeed("mountpoint /boot"); - ''; - extraSystemConfig = { + imports = [ ../example/boot-raid1.nix ]; + 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 - boot.loader.systemd-boot.enable = false; + nodes.machine.boot.loader.systemd-boot.enable = false; }; } diff --git a/tests/btrfs-only-root-subvolume.nix b/tests/btrfs-only-root-subvolume.nix index ef2d2ec..680e25b 100644 --- a/tests/btrfs-only-root-subvolume.nix +++ b/tests/btrfs-only-root-subvolume.nix @@ -1,12 +1,9 @@ { - pkgs ? import { }, - diskoLib ? pkgs.callPackage ../lib { }, -}: -diskoLib.testLib.makeDiskoTest { - inherit pkgs; - name = "btrfs-only-root-subvolume"; - disko-config = ../example/btrfs-only-root-subvolume.nix; - extraTestScript = '' - machine.succeed("btrfs subvolume list /"); - ''; + imports = [ ../example/btrfs-only-root-subvolume.nix ]; + disko.test = { + name = "btrfs-only-root-subvolume"; + extraChecks = '' + machine.succeed("btrfs subvolume list /"); + ''; + }; } diff --git a/tests/btrfs-subvolumes.nix b/tests/btrfs-subvolumes.nix index b9cc096..cd2c679 100644 --- a/tests/btrfs-subvolumes.nix +++ b/tests/btrfs-subvolumes.nix @@ -1,20 +1,17 @@ { - pkgs ? import { }, - diskoLib ? pkgs.callPackage ../lib { }, -}: -diskoLib.testLib.makeDiskoTest { - inherit pkgs; - name = "btrfs-subvolumes"; - disko-config = ../example/btrfs-subvolumes.nix; - extraTestScript = '' - 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"); - ''; + imports = [ ../example/btrfs-subvolumes.nix ]; + 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"); + ''; + }; } diff --git a/tests/cli.nix b/tests/cli.nix index 3fe0f7c..e3c9a67 100644 --- a/tests/cli.nix +++ b/tests/cli.nix @@ -1,38 +1,24 @@ +{ lib, ... }: { - pkgs ? import { }, - diskoLib ? pkgs.callPackage ../lib { }, -}: -diskoLib.testLib.makeDiskoTest { - inherit pkgs; - name = "cli"; - disko-config = ../example/complex.nix; - extraInstallerConfig.networking.hostId = "8425e349"; - extraSystemConfig = { - networking.hostId = "8425e349"; - 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! - }; - testMode = "direct"; - extraTestScript = '' - machine.succeed("test -b /dev/md/raid1p1"); - - machine.succeed("mountpoint /zfs_fs"); - machine.succeed("mountpoint /zfs_legacy_fs"); - machine.succeed("mountpoint /ext4onzfs"); - machine.succeed("mountpoint /ext4_on_lvm"); - ''; - extraSystemConfig = { - imports = [ - ../module.nix - ]; - }; - extraInstallerConfig = { - boot.kernelModules = [ + imports = [ ../example/complex.nix ]; + disko.test = { + name = lib.mkForce "cli"; + mode = "direct"; + extraChecks = lib.mkForce '' + machine.succeed("test -b /dev/md/raid1p1"); + machine.succeed("mountpoint /zfs_fs"); + machine.succeed("mountpoint /zfs_legacy_fs"); + machine.succeed("mountpoint /ext4onzfs"); + machine.succeed("mountpoint /ext4_on_lvm"); + ''; + nodes.machine.fileSystems = { + "/zfs_legacy_fs".options = [ "nofail" ]; + "/zfs_fs".options = [ "nofail" ]; + }; + nodes.formatter.boot.kernelModules = [ "dm-raid" "dm-mirror" ]; - imports = [ - ../module.nix - ]; }; + networking.hostId = "8425e349"; } diff --git a/tests/complex.nix b/tests/complex.nix index 2f821c6..ebef948 100644 --- a/tests/complex.nix +++ b/tests/complex.nix @@ -1,33 +1,27 @@ { - pkgs ? import { }, - diskoLib ? pkgs.callPackage ../lib { }, -}: -diskoLib.testLib.makeDiskoTest { - inherit pkgs; - name = "complex"; - disko-config = ../example/complex.nix; - extraInstallerConfig.networking.hostId = "8425e349"; - extraSystemConfig = { - networking.hostId = "8425e349"; - 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! - }; - extraTestScript = '' - machine.succeed("test -b /dev/md/raid1p1"); - machine.succeed("test -b /dev/disk/by-partuuid/f0f0f0f0-f0f0-f0f0-f0f0-f0f0f0f0f0f0") + imports = [ ../example/complex.nix ]; + 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("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"); - ''; - extraInstallerConfig = { - boot.kernelModules = [ + 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"; } diff --git a/tests/default.nix b/tests/default.nix index 39bc518..6335c5e 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -1,36 +1,50 @@ { - makeTest ? import , - eval-config ? import , - qemu-common ? import , pkgs ? import { }, + ... }: let - lib = pkgs.lib; - diskoLib = import ../lib { - inherit - lib - makeTest - eval-config - qemu-common - ; - }; + inherit (pkgs) lib; - allTestFilenames = builtins.map (lib.removeSuffix ".nix") ( - builtins.filter (x: lib.hasSuffix ".nix" x && x != "default.nix") ( - lib.attrNames (builtins.readDir ./.) - ) - ); - incompatibleTests = lib.optionals pkgs.stdenv.buildPlatform.isRiscV64 [ + bespoke = [ + "make-disk-image" + "make-disk-image-impure" + "mdadm-btrfs-wipe" + "standalone" + ]; + incompatible = lib.optionals pkgs.stdenv.buildPlatform.isRiscV64 [ "zfs" "zfs-over-legacy" "cli" "module" "complex" ]; - allCompatibleFilenames = lib.subtractLists incompatibleTests allTestFilenames; - allTests = lib.genAttrs allCompatibleFilenames ( - test: import (./. + "/${test}.nix") { inherit diskoLib pkgs; } + listNix = + dir: + map (lib.removeSuffix ".nix") ( + lib.attrNames ( + lib.filterAttrs (n: _: lib.hasSuffix ".nix" n && n != "default.nix") (builtins.readDir dir) + ) + ); + + evalModule = + file: + import (pkgs.path + "/nixos/lib/eval-config.nix") { + system = pkgs.stdenv.hostPlatform.system; + modules = [ + ../module.nix + file + ]; + }; + + testsDirModule = lib.genAttrs (lib.subtractLists bespoke (listNix ./.)) ( + name: evalModule (./. + "/${name}.nix") ); + + moduleTests = lib.mapAttrs (_: eval: eval.config.system.build.diskoTest) ( + lib.removeAttrs testsDirModule incompatible + ); + + bespokeTests = lib.genAttrs bespoke (name: import (./. + "/${name}.nix") { inherit pkgs; }); in -allTests +moduleTests // bespokeTests diff --git a/tests/f2fs.nix b/tests/f2fs.nix index cbae7f8..826c9b4 100644 --- a/tests/f2fs.nix +++ b/tests/f2fs.nix @@ -1,17 +1,12 @@ { - pkgs ? import { }, - diskoLib ? pkgs.callPackage ../lib { }, -}: -diskoLib.testLib.makeDiskoTest { - inherit pkgs; - name = "f2fs"; - disko-config = ../example/f2fs.nix; - extraTestScript = '' - machine.succeed("mountpoint /"); - machine.succeed("lsblk --fs >&2"); - ''; - # so that the installer boots with a f2fs enabled kernel - extraInstallerConfig = { - boot.supportedFilesystems = [ "f2fs" ]; + imports = [ ../example/f2fs.nix ]; + 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" ]; }; } diff --git a/tests/gpt-bios-compat.nix b/tests/gpt-bios-compat.nix index c6ac331..256bbf0 100644 --- a/tests/gpt-bios-compat.nix +++ b/tests/gpt-bios-compat.nix @@ -1,13 +1,10 @@ { - pkgs ? import { }, - diskoLib ? pkgs.callPackage ../lib { }, -}: -diskoLib.testLib.makeDiskoTest { - inherit pkgs; - name = "gpt-bios-compat"; - disko-config = ../example/gpt-bios-compat.nix; - extraTestScript = '' - machine.succeed("mountpoint /"); - ''; - efi = false; + imports = [ ../example/gpt-bios-compat.nix ]; + disko.test = { + name = "gpt-bios-compat"; + efi = false; + extraChecks = '' + machine.succeed("mountpoint /"); + ''; + }; } diff --git a/tests/gpt-name-with-special-chars.nix b/tests/gpt-name-with-special-chars.nix index aac12e3..dc5aa61 100644 --- a/tests/gpt-name-with-special-chars.nix +++ b/tests/gpt-name-with-special-chars.nix @@ -1,14 +1,11 @@ { - pkgs ? import { }, - diskoLib ? pkgs.callPackage ../lib { }, -}: -diskoLib.testLib.makeDiskoTest { - inherit pkgs; - name = "gpt-name-with-whitespace"; - disko-config = ../example/gpt-name-with-whitespace.nix; - extraTestScript = '' - machine.succeed("mountpoint /"); - machine.succeed("mountpoint '/name with spaces'"); - machine.succeed("mountpoint '/name^with\\some@special#chars'"); - ''; + imports = [ ../example/gpt-name-with-whitespace.nix ]; + 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'"); + ''; + }; } diff --git a/tests/gpt-unformatted.nix b/tests/gpt-unformatted.nix index 6ff25b4..29cf368 100644 --- a/tests/gpt-unformatted.nix +++ b/tests/gpt-unformatted.nix @@ -1,12 +1,9 @@ { - pkgs ? import { }, - diskoLib ? pkgs.callPackage ../lib { }, -}: -diskoLib.testLib.makeDiskoTest { - inherit pkgs; - name = "gpt-unformatted"; - disko-config = ../example/gpt-unformatted.nix; - extraTestScript = '' - machine.succeed("mountpoint /"); - ''; + imports = [ ../example/gpt-unformatted.nix ]; + disko.test = { + name = "gpt-unformatted"; + extraChecks = '' + machine.succeed("mountpoint /"); + ''; + }; } diff --git a/tests/hybrid-mbr.nix b/tests/hybrid-mbr.nix index 105abfb..b7e9dfa 100644 --- a/tests/hybrid-mbr.nix +++ b/tests/hybrid-mbr.nix @@ -1,12 +1,9 @@ { - pkgs ? import { }, - diskoLib ? pkgs.callPackage ../lib { }, -}: -diskoLib.testLib.makeDiskoTest { - inherit pkgs; - name = "hybrid-mbr"; - disko-config = ../example/hybrid-mbr.nix; - extraTestScript = '' - machine.succeed("mountpoint /"); - ''; + imports = [ ../example/hybrid-mbr.nix ]; + disko.test = { + name = "hybrid-mbr"; + extraChecks = '' + machine.succeed("mountpoint /"); + ''; + }; } diff --git a/tests/hybrid-tmpfs-on-root.nix b/tests/hybrid-tmpfs-on-root.nix index 8fecf9b..0838018 100644 --- a/tests/hybrid-tmpfs-on-root.nix +++ b/tests/hybrid-tmpfs-on-root.nix @@ -1,13 +1,10 @@ { - pkgs ? import { }, - diskoLib ? pkgs.callPackage ../lib { }, -}: -diskoLib.testLib.makeDiskoTest { - inherit pkgs; - name = "hybrid-tmpfs-on-root"; - disko-config = ../example/hybrid-tmpfs-on-root.nix; - extraTestScript = '' - machine.succeed("mountpoint /"); - machine.succeed("findmnt / --types tmpfs"); - ''; + imports = [ ../example/hybrid-tmpfs-on-root.nix ]; + disko.test = { + name = "hybrid-tmpfs-on-root"; + extraChecks = '' + machine.succeed("mountpoint /"); + machine.succeed("findmnt / --types tmpfs"); + ''; + }; } diff --git a/tests/hybrid.nix b/tests/hybrid.nix index 7feb2a3..2320d9b 100644 --- a/tests/hybrid.nix +++ b/tests/hybrid.nix @@ -1,12 +1,9 @@ { - pkgs ? import { }, - diskoLib ? pkgs.callPackage ../lib { }, -}: -diskoLib.testLib.makeDiskoTest { - inherit pkgs; - name = "hybrid"; - disko-config = ../example/hybrid.nix; - extraTestScript = '' - machine.succeed("mountpoint /"); - ''; + imports = [ ../example/hybrid.nix ]; + disko.test = { + name = "hybrid"; + extraChecks = '' + machine.succeed("mountpoint /"); + ''; + }; } diff --git a/tests/legacy-table-with-whitespace.nix b/tests/legacy-table-with-whitespace.nix index 5a6fef7..06e303d 100644 --- a/tests/legacy-table-with-whitespace.nix +++ b/tests/legacy-table-with-whitespace.nix @@ -1,13 +1,10 @@ { - pkgs ? import { }, - diskoLib ? pkgs.callPackage ../lib { }, -}: -diskoLib.testLib.makeDiskoTest { - inherit pkgs; - name = "legacy-table-with-whitespace"; - disko-config = ../example/legacy-table-with-whitespace.nix; - extraTestScript = '' - machine.succeed("mountpoint /"); - machine.succeed("mountpoint /name_with_spaces"); - ''; + imports = [ ../example/legacy-table-with-whitespace.nix ]; + disko.test = { + name = "legacy-table-with-whitespace"; + extraChecks = '' + machine.succeed("mountpoint /"); + machine.succeed("mountpoint /name_with_spaces"); + ''; + }; } diff --git a/tests/legacy-table.nix b/tests/legacy-table.nix index 5c58bf4..5e30a90 100644 --- a/tests/legacy-table.nix +++ b/tests/legacy-table.nix @@ -1,12 +1,9 @@ { - pkgs ? import { }, - diskoLib ? pkgs.callPackage ../lib { }, -}: -diskoLib.testLib.makeDiskoTest { - inherit pkgs; - name = "legacy-table"; - disko-config = ../example/legacy-table.nix; - extraTestScript = '' - machine.succeed("mountpoint /"); - ''; + imports = [ ../example/legacy-table.nix ]; + disko.test = { + name = "legacy-table"; + extraChecks = '' + machine.succeed("mountpoint /"); + ''; + }; } diff --git a/tests/long-device-name.nix b/tests/long-device-name.nix index 273fa62..5e1f61e 100644 --- a/tests/long-device-name.nix +++ b/tests/long-device-name.nix @@ -1,12 +1,9 @@ { - pkgs ? import { }, - diskoLib ? pkgs.callPackage ../lib { }, -}: -diskoLib.testLib.makeDiskoTest { - inherit pkgs; - name = "long-device-name"; - disko-config = ../example/long-device-name.nix; - extraTestScript = '' - machine.succeed("mountpoint /"); - ''; + imports = [ ../example/long-device-name.nix ]; + disko.test = { + name = "long-device-name"; + extraChecks = '' + machine.succeed("mountpoint /"); + ''; + }; } diff --git a/tests/luks-btrfs-raid.nix b/tests/luks-btrfs-raid.nix index 6e12749..23022f7 100644 --- a/tests/luks-btrfs-raid.nix +++ b/tests/luks-btrfs-raid.nix @@ -1,14 +1,11 @@ { - pkgs ? import { }, - diskoLib ? pkgs.callPackage ../lib { }, -}: -diskoLib.testLib.makeDiskoTest { - inherit pkgs; - name = "luks-btrfs-raid"; - disko-config = ../example/luks-btrfs-raid.nix; - extraTestScript = '' - machine.succeed("cryptsetup isLuks /dev/vda2"); - machine.succeed("cryptsetup isLuks /dev/vdb1"); - machine.succeed("btrfs subvolume list /"); - ''; + imports = [ ../example/luks-btrfs-raid.nix ]; + disko.test = { + name = "luks-btrfs-raid"; + extraChecks = '' + machine.succeed("cryptsetup isLuks /dev/vda2"); + machine.succeed("cryptsetup isLuks /dev/vdb1"); + machine.succeed("btrfs subvolume list /"); + ''; + }; } diff --git a/tests/luks-btrfs-subvolumes.nix b/tests/luks-btrfs-subvolumes.nix index eb1264a..1d8764b 100644 --- a/tests/luks-btrfs-subvolumes.nix +++ b/tests/luks-btrfs-subvolumes.nix @@ -1,15 +1,12 @@ { - pkgs ? import { }, - diskoLib ? pkgs.callPackage ../lib { }, -}: -diskoLib.testLib.makeDiskoTest { - inherit pkgs; - name = "luks-btrfs-subvolumes"; - disko-config = ../example/luks-btrfs-subvolumes.nix; - extraTestScript = '' - 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"); - ''; + imports = [ ../example/luks-btrfs-subvolumes.nix ]; + 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"); + ''; + }; } diff --git a/tests/luks-fido2.nix b/tests/luks-fido2.nix index 2a02957..27a2ec9 100644 --- a/tests/luks-fido2.nix +++ b/tests/luks-fido2.nix @@ -1,14 +1,11 @@ { - pkgs ? import { }, - diskoLib ? pkgs.callPackage ../lib { }, -}: -diskoLib.testLib.makeDiskoTest { - inherit pkgs; - name = "luks-fido2"; - disko-config = ../example/luks-fido2.nix; - enableCanokey = true; - extraTestScript = '' - machine.succeed("cryptsetup isLuks /dev/vda2"); - machine.succeed("mountpoint /"); - ''; + imports = [ ../example/luks-fido2.nix ]; + disko.test = { + name = "luks-fido2"; + enableCanokey = true; + extraChecks = '' + machine.succeed("cryptsetup isLuks /dev/vda2"); + machine.succeed("mountpoint /"); + ''; + }; } diff --git a/tests/luks-interactive-login.nix b/tests/luks-interactive-login.nix index a1225d0..f85623a 100644 --- a/tests/luks-interactive-login.nix +++ b/tests/luks-interactive-login.nix @@ -1,17 +1,14 @@ { - pkgs ? import { }, - diskoLib ? pkgs.callPackage ../lib { }, -}: -diskoLib.testLib.makeDiskoTest { - inherit pkgs; - name = "luks-interactive-login"; - disko-config = ../example/luks-interactive-login.nix; - enableOCR = true; - extraTestScript = '' - machine.succeed("cryptsetup isLuks /dev/vda2"); - ''; - bootCommands = '' - machine.wait_for_text("[Pp]assphrase for") - machine.send_chars("secretsecret\n") - ''; + imports = [ ../example/luks-interactive-login.nix ]; + 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"); + ''; + }; } diff --git a/tests/luks-lvm.nix b/tests/luks-lvm.nix index fec9c3b..a1906f9 100644 --- a/tests/luks-lvm.nix +++ b/tests/luks-lvm.nix @@ -1,13 +1,10 @@ { - pkgs ? import { }, - diskoLib ? pkgs.callPackage ../lib { }, -}: -diskoLib.testLib.makeDiskoTest { - inherit pkgs; - name = "luks-lvm"; - disko-config = ../example/luks-lvm.nix; - extraTestScript = '' - machine.succeed("cryptsetup isLuks /dev/vda2"); - machine.succeed("mountpoint /home"); - ''; + imports = [ ../example/luks-lvm.nix ]; + disko.test = { + name = "luks-lvm"; + extraChecks = '' + machine.succeed("cryptsetup isLuks /dev/vda2"); + machine.succeed("mountpoint /home"); + ''; + }; } diff --git a/tests/luks-on-mdadm.nix b/tests/luks-on-mdadm.nix index 34f8317..b50eadc 100644 --- a/tests/luks-on-mdadm.nix +++ b/tests/luks-on-mdadm.nix @@ -1,17 +1,11 @@ { - pkgs ? import { }, - diskoLib ? pkgs.callPackage ../lib { }, -}: -diskoLib.testLib.makeDiskoTest { - inherit pkgs; - name = "luks-on-mdadm"; - disko-config = ../example/luks-on-mdadm.nix; - extraTestScript = '' - machine.succeed("test -b /dev/md/raid1"); - machine.succeed("mountpoint /"); - ''; - extraSystemConfig = { - # sadly systemd-boot fails to install to a raid /boot device - boot.loader.systemd-boot.enable = false; + imports = [ ../example/luks-on-mdadm.nix ]; + 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; }; } diff --git a/tests/lvm-raid.nix b/tests/lvm-raid.nix index 88d6c74..6e30921 100644 --- a/tests/lvm-raid.nix +++ b/tests/lvm-raid.nix @@ -1,23 +1,16 @@ { - pkgs ? import { }, - diskoLib ? pkgs.callPackage ../lib { }, -}: -diskoLib.testLib.makeDiskoTest { - inherit pkgs; - name = "lvm-raid"; - disko-config = ../example/lvm-raid.nix; - extraTestScript = '' - machine.succeed("mountpoint /home"); - ''; - extraInstallerConfig = { - boot.kernelModules = [ + imports = [ ../example/lvm-raid.nix ]; + disko.test = { + name = "lvm-raid"; + extraChecks = '' + machine.succeed("mountpoint /home"); + ''; + nodes.formatter.boot.kernelModules = [ "dm-raid" "raid0" "dm-mirror" ]; - }; - extraSystemConfig = { # sadly systemd-boot fails to install to a raid /boot device - boot.loader.systemd-boot.enable = false; + nodes.machine.boot.loader.systemd-boot.enable = false; }; } diff --git a/tests/lvm-sizes-sort.nix b/tests/lvm-sizes-sort.nix index 976d58c..42b50a6 100644 --- a/tests/lvm-sizes-sort.nix +++ b/tests/lvm-sizes-sort.nix @@ -1,12 +1,9 @@ { - pkgs ? import { }, - diskoLib ? pkgs.callPackage ../lib { }, -}: -diskoLib.testLib.makeDiskoTest { - inherit pkgs; - name = "lvm-sizes-sort"; - disko-config = ../example/lvm-sizes-sort.nix; - extraTestScript = '' - machine.succeed("mountpoint /home"); - ''; + imports = [ ../example/lvm-sizes-sort.nix ]; + disko.test = { + name = "lvm-sizes-sort"; + extraChecks = '' + machine.succeed("mountpoint /home"); + ''; + }; } diff --git a/tests/lvm-thin.nix b/tests/lvm-thin.nix index 6a848a0..ea9a27e 100644 --- a/tests/lvm-thin.nix +++ b/tests/lvm-thin.nix @@ -1,12 +1,9 @@ { - pkgs ? import { }, - diskoLib ? pkgs.callPackage ../lib { }, -}: -diskoLib.testLib.makeDiskoTest { - inherit pkgs; - name = "lvm-thin"; - disko-config = ../example/lvm-thin.nix; - extraTestScript = '' - machine.succeed("mountpoint /home"); - ''; + imports = [ ../example/lvm-thin.nix ]; + disko.test = { + name = "lvm-thin"; + extraChecks = '' + machine.succeed("mountpoint /home"); + ''; + }; } diff --git a/tests/mdadm-raid0.nix b/tests/mdadm-raid0.nix index e8db3cc..edc62f0 100644 --- a/tests/mdadm-raid0.nix +++ b/tests/mdadm-raid0.nix @@ -1,14 +1,11 @@ { - pkgs ? import { }, - diskoLib ? pkgs.callPackage ../lib { }, -}: -diskoLib.testLib.makeDiskoTest { - inherit pkgs; - name = "mdadm-raid0"; - disko-config = ../example/mdadm-raid0.nix; - extraTestScript = '' - machine.succeed("test -b /dev/md/raid0"); - machine.succeed("mountpoint /"); - ''; - efi = false; + imports = [ ../example/mdadm-raid0.nix ]; + disko.test = { + name = "mdadm-raid0"; + efi = false; + extraChecks = '' + machine.succeed("test -b /dev/md/raid0"); + machine.succeed("mountpoint /"); + ''; + }; } diff --git a/tests/mdadm-raid5-args.nix b/tests/mdadm-raid5-args.nix index 867fbe9..ce28a30 100644 --- a/tests/mdadm-raid5-args.nix +++ b/tests/mdadm-raid5-args.nix @@ -1,14 +1,11 @@ { - pkgs ? import { }, - diskoLib ? pkgs.callPackage ../lib { }, -}: -diskoLib.testLib.makeDiskoTest { - inherit pkgs; - name = "mdadm-raid5-args"; - disko-config = ../example/mdadm-raid5-args.nix; - extraTestScript = '' - machine.succeed("test -b /dev/md/raid5"); - machine.succeed("mountpoint /"); - ''; - efi = false; + imports = [ ../example/mdadm-raid5-args.nix ]; + disko.test = { + name = "mdadm-raid5-args"; + efi = false; + extraChecks = '' + machine.succeed("test -b /dev/md/raid5"); + machine.succeed("mountpoint /"); + ''; + }; } diff --git a/tests/mdadm.nix b/tests/mdadm.nix index e569f65..195d204 100644 --- a/tests/mdadm.nix +++ b/tests/mdadm.nix @@ -1,14 +1,11 @@ { - pkgs ? import { }, - diskoLib ? pkgs.callPackage ../lib { }, -}: -diskoLib.testLib.makeDiskoTest { - inherit pkgs; - name = "mdadm"; - disko-config = ../example/mdadm.nix; - extraTestScript = '' - machine.succeed("test -b /dev/md/raid1"); - machine.succeed("mountpoint /"); - ''; - efi = false; + imports = [ ../example/mdadm.nix ]; + disko.test = { + name = "mdadm"; + efi = false; + extraChecks = '' + machine.succeed("test -b /dev/md/raid1"); + machine.succeed("mountpoint /"); + ''; + }; } diff --git a/tests/module.nix b/tests/module.nix index a9c0da9..0561926 100644 --- a/tests/module.nix +++ b/tests/module.nix @@ -1,30 +1,21 @@ +{ lib, ... }: { - pkgs ? import { }, - diskoLib ? pkgs.callPackage ../lib { }, -}: -diskoLib.testLib.makeDiskoTest { - inherit pkgs; - name = "module"; - disko-config = ../example/complex.nix; - extraInstallerConfig.networking.hostId = "8425e349"; - extraSystemConfig = { - networking.hostId = "8425e349"; - fileSystems."/zfs_legacy_fs".options = [ "nofail" ]; # TODO find out why we need this! - }; - testMode = "module"; - extraTestScript = '' - machine.succeed("test -b /dev/md/raid1p1"); - - - machine.succeed("mountpoint /zfs_fs"); - machine.succeed("mountpoint /zfs_legacy_fs"); - machine.succeed("mountpoint /ext4onzfs"); - machine.succeed("mountpoint /ext4_on_lvm"); - ''; - extraInstallerConfig = { - boot.kernelModules = [ + imports = [ ../example/complex.nix ]; + disko.test = { + name = lib.mkForce "module"; + mode = "module"; + extraChecks = lib.mkForce '' + machine.succeed("test -b /dev/md/raid1p1"); + machine.succeed("mountpoint /zfs_fs"); + machine.succeed("mountpoint /zfs_legacy_fs"); + machine.succeed("mountpoint /ext4onzfs"); + machine.succeed("mountpoint /ext4_on_lvm"); + ''; + nodes.machine.fileSystems."/zfs_legacy_fs".options = [ "nofail" ]; + nodes.formatter.boot.kernelModules = [ "dm-raid" "dm-mirror" ]; }; + networking.hostId = "8425e349"; } diff --git a/tests/multi-device-no-deps.nix b/tests/multi-device-no-deps.nix index f063fa8..9978a1c 100644 --- a/tests/multi-device-no-deps.nix +++ b/tests/multi-device-no-deps.nix @@ -1,15 +1,12 @@ # this is a regression test for https://github.com/nix-community/disko/issues/52 { - pkgs ? import { }, - diskoLib ? pkgs.callPackage ../lib { }, -}: -diskoLib.testLib.makeDiskoTest { - inherit pkgs; - name = "multi-device-no-deps"; - disko-config = ../example/multi-device-no-deps.nix; - testBoot = false; - extraTestScript = '' - machine.succeed("mountpoint /mnt/a"); - machine.succeed("mountpoint /mnt/b"); - ''; + imports = [ ../example/multi-device-no-deps.nix ]; + disko.test = { + name = "multi-device-no-deps"; + boot = false; + extraChecks = '' + machine.succeed("mountpoint /mnt/a"); + machine.succeed("mountpoint /mnt/b"); + ''; + }; } diff --git a/tests/negative-size.nix b/tests/negative-size.nix index 2d4329b..be9fd83 100644 --- a/tests/negative-size.nix +++ b/tests/negative-size.nix @@ -1,14 +1,11 @@ # this is a regression test for https://github.com/nix-community/disko/issues/52 { - pkgs ? import { }, - diskoLib ? pkgs.callPackage ../lib { }, -}: -diskoLib.testLib.makeDiskoTest { - inherit pkgs; - name = "negative-size"; - disko-config = ../example/negative-size.nix; - testBoot = false; - extraTestScript = '' - machine.succeed("mountpoint /mnt"); - ''; + imports = [ ../example/negative-size.nix ]; + disko.test = { + name = "negative-size"; + boot = false; + extraChecks = '' + machine.succeed("mountpoint /mnt"); + ''; + }; } diff --git a/tests/non-root-zfs.nix b/tests/non-root-zfs.nix index ada8f20..5d3af3a 100644 --- a/tests/non-root-zfs.nix +++ b/tests/non-root-zfs.nix @@ -1,49 +1,45 @@ { - pkgs ? import { }, - diskoLib ? pkgs.callPackage ../lib { }, -}: -diskoLib.testLib.makeDiskoTest { - inherit pkgs; - name = "non-root-zfs"; - disko-config = ../example/non-root-zfs.nix; - extraInstallerConfig.networking.hostId = "8425e349"; - extraSystemConfig.networking.hostId = "8425e349"; - postDisko = '' - machine.succeed("mountpoint /mnt/storage") - machine.succeed("mountpoint /mnt/storage/dataset") + imports = [ ../example/non-root-zfs.nix ]; + 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" + 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") + 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")[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" - ''; - extraTestScript = '' - machine.succeed("mountpoint /storage") - machine.succeed("mountpoint /storage/dataset") + 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" + 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") + 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")[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" - ''; + 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"; } diff --git a/tests/simple-efi.nix b/tests/simple-efi.nix index fa47173..7713728 100644 --- a/tests/simple-efi.nix +++ b/tests/simple-efi.nix @@ -1,12 +1,9 @@ { - pkgs ? import { }, - diskoLib ? pkgs.callPackage ../lib { }, -}: -diskoLib.testLib.makeDiskoTest { - inherit pkgs; - name = "simple-efi"; - disko-config = ../example/simple-efi.nix; - extraTestScript = '' - machine.succeed("mountpoint /"); - ''; + imports = [ ../example/simple-efi.nix ]; + disko.test = { + name = "simple-efi"; + extraChecks = '' + machine.succeed("mountpoint /"); + ''; + }; } diff --git a/tests/swap.nix b/tests/swap.nix index f7075ea..5ebf5c7 100644 --- a/tests/swap.nix +++ b/tests/swap.nix @@ -1,32 +1,28 @@ +{ pkgs, ... }: { - pkgs ? import { }, - diskoLib ? pkgs.callPackage ../lib { }, -}: -diskoLib.testLib.makeDiskoTest { - inherit pkgs; - name = "swap"; - disko-config = ../example/swap.nix; - extraTestScript = '' - 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")) + imports = [ ../example/swap.nix ]; + 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}" + 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}" - ''; - extraSystemConfig = { - environment.systemPackages = [ pkgs.jq ]; + 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 ]; }; } diff --git a/tests/tmpfs.nix b/tests/tmpfs.nix index af9b3c3..4f97aa3 100644 --- a/tests/tmpfs.nix +++ b/tests/tmpfs.nix @@ -1,13 +1,10 @@ { - pkgs ? import { }, - diskoLib ? pkgs.callPackage ../lib { }, -}: -diskoLib.testLib.makeDiskoTest { - inherit pkgs; - name = "tmpfs"; - disko-config = ../example/tmpfs.nix; - extraTestScript = '' - machine.succeed("mountpoint /"); - machine.succeed("mountpoint /tmp"); - ''; + imports = [ ../example/tmpfs.nix ]; + disko.test = { + name = "tmpfs"; + extraChecks = '' + machine.succeed("mountpoint /"); + machine.succeed("mountpoint /tmp"); + ''; + }; } diff --git a/tests/with-lib.nix b/tests/with-lib.nix index 1ad4829..cd34f9a 100644 --- a/tests/with-lib.nix +++ b/tests/with-lib.nix @@ -1,13 +1,11 @@ { - pkgs ? import { }, - diskoLib ? pkgs.callPackage ../lib { }, -}: -diskoLib.testLib.makeDiskoTest { - inherit pkgs; - name = "with-lib"; - disko-config = ../example/with-lib.nix; - extraTestScript = '' - machine.succeed("mountpoint /"); - ''; - efi = false; + imports = [ ../example/with-lib.nix ]; + _module.args.disks = [ "/dev/vdb" ]; + disko.test = { + name = "with-lib"; + efi = false; + extraChecks = '' + machine.succeed("mountpoint /"); + ''; + }; } diff --git a/tests/xfs.nix b/tests/xfs.nix index 081755a..9ef12ce 100644 --- a/tests/xfs.nix +++ b/tests/xfs.nix @@ -1,14 +1,11 @@ { - pkgs ? import { }, - diskoLib ? pkgs.callPackage ../lib { }, -}: -diskoLib.testLib.makeDiskoTest { - inherit pkgs; - name = "xfs"; - disko-config = ../example/xfs-with-quota.nix; - extraTestScript = '' - machine.succeed("mountpoint /"); + imports = [ ../example/xfs-with-quota.nix ]; + disko.test = { + name = "xfs"; + extraChecks = '' + machine.succeed("mountpoint /"); - machine.succeed("xfs_quota -c 'print' / | grep -q '(pquota)'") - ''; + machine.succeed("xfs_quota -c 'print' / | grep -q '(pquota)'") + ''; + }; } diff --git a/tests/zfs-encrypted-root.nix b/tests/zfs-encrypted-root.nix index a196d06..9bf1623 100644 --- a/tests/zfs-encrypted-root.nix +++ b/tests/zfs-encrypted-root.nix @@ -1,18 +1,15 @@ +{ lib, ... }: { - pkgs ? import { }, - diskoLib ? pkgs.callPackage ../lib { }, -}: -diskoLib.testLib.makeDiskoTest { - inherit pkgs; - name = "zfs-encrypted-root"; - extraInstallerConfig.networking.hostId = "8425e349"; - extraSystemConfig.networking.hostId = "8425e349"; - disko-config = pkgs.lib.recursiveUpdate (import ../example/zfs-encrypted-root.nix) { - disko.devices.zpool.zroot.datasets.root.options.keylocation = "file:///tmp/secret.key"; + imports = [ ../example/zfs-encrypted-root.nix ]; + 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 + ''; }; - extraTestScript = '' - machine.succeed("mountpoint /"); - machine.succeed("mountpoint /nix"); - machine.succeed("swapon --show=NAME | grep /dev/zd"); # i.e. /dev/zd0 - ''; + networking.hostId = "8425e349"; } diff --git a/tests/zfs-over-legacy.nix b/tests/zfs-over-legacy.nix index 1d60a85..44d8401 100644 --- a/tests/zfs-over-legacy.nix +++ b/tests/zfs-over-legacy.nix @@ -1,15 +1,11 @@ { - pkgs ? import { }, - diskoLib ? pkgs.callPackage ../lib { }, -}: -diskoLib.testLib.makeDiskoTest { - inherit pkgs; - name = "zfs-over-legacy"; - extraInstallerConfig.networking.hostId = "8425e349"; - extraSystemConfig.networking.hostId = "8425e349"; - disko-config = ../example/zfs-over-legacy.nix; - extraTestScript = '' - machine.succeed("test -e /zfs_fs"); - machine.succeed("mountpoint /zfs_fs"); - ''; + imports = [ ../example/zfs-over-legacy.nix ]; + disko.test = { + name = "zfs-over-legacy"; + extraChecks = '' + machine.succeed("test -e /zfs_fs"); + machine.succeed("mountpoint /zfs_fs"); + ''; + }; + networking.hostId = "8425e349"; } diff --git a/tests/zfs-with-vdevs.nix b/tests/zfs-with-vdevs.nix index 4ac5e98..3a2cda5 100644 --- a/tests/zfs-with-vdevs.nix +++ b/tests/zfs-with-vdevs.nix @@ -1,78 +1,70 @@ { - pkgs ? import { }, - diskoLib ? pkgs.callPackage ../lib { }, -}: -diskoLib.testLib.makeDiskoTest { - inherit pkgs; - name = "zfs-with-vdevs"; - disko-config = ../example/zfs-with-vdevs.nix; - 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 + imports = [ ../example/zfs-with-vdevs.nix ]; + 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)}" ''; }; - extraTestScript = '' - 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"); - - # 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', - ]) - assert actual == expected, f"Incorrect pool layout. Expected:\n\t{'\n\t'.join(expected)}\nActual:\n\t{'\n\t'.join(actual)}" - ''; + networking.hostId = "8425e349"; } diff --git a/tests/zfs.nix b/tests/zfs.nix index c3d2af8..14fe981 100644 --- a/tests/zfs.nix +++ b/tests/zfs.nix @@ -1,42 +1,36 @@ { - pkgs ? import { }, - diskoLib ? pkgs.callPackage ../lib { }, -}: -diskoLib.testLib.makeDiskoTest { - inherit pkgs; - name = "zfs"; - disko-config = ../example/zfs.nix; - extraInstallerConfig.networking.hostId = "8425e349"; - extraSystemConfig = { - networking.hostId = "8425e349"; - fileSystems."/zfs_legacy_fs".options = [ "nofail" ]; # TODO find out why we need this! + imports = [ ../example/zfs.nix ]; + 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"); + ''; }; - extraTestScript = '' - 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"; }