Files
disko/tests/complex.nix
T
Michael Hoang 88275cedd4 tests: modulify in-repo tests; switch tests/default.nix to evalModules discovery
Convert all 40 `tests/*.nix` files that previously called
`diskoLib.testLib.makeDiskoTest { … }` into pure NixOS modules. Each
test now imports its corresponding `../example/foo.nix` and sets
`disko.test = { name = …; extraChecks = …; nodes.machine = …; … };`
inline.

Switch `tests/default.nix` to discover the module-style tests via
nixpkgs's `nixos/lib/eval-config.nix` and read
`config.system.build.diskoTest` off each. The four bespoke tests
(`make-disk-image`, `make-disk-image-impure`, `mdadm-btrfs-wipe`,
`standalone`) keep their function-call shape and are still imported
imperatively; they don't fit the example-eval pattern.

Arg-to-option translations performed in each file:
  - `extraSystemConfig`    → `disko.test.nodes.machine`
  - `extraInstallerConfig` → `disko.test.nodes.formatter`
  - `bootCommands`/`efi`/`enableOCR`/`postDisko`/`enableCanokey`
    /`name` → `disko.test.<same>`
  - `extraTestScript` → `disko.test.extraChecks`
  - `testBoot` → `disko.test.boot`
  - `testMode` → `disko.test.mode` (`cli` and `module` set this
    explicitly; the rest use the default `"module"`)
  - `extraInstallerConfig.networking.hostId` /
    `extraSystemConfig.networking.hostId` → host-level
    `networking.hostId` (propagated to every node by module.nix's
    `defaults.networking.hostId` in the evalTest call)

`tests/cli.nix` and `tests/module.nix` both import
`../example/complex.nix` and override `disko.test.{name,mode,extraChecks}`
with `lib.mkForce` — those overrides will keep working after commit 8
folds `tests/complex.nix`'s `disko.test` block into
`example/complex.nix`.

`tests/zfs-encrypted-root.nix`'s legacy `pkgs.lib.recursiveUpdate` on
the imported disko-config becomes a flat
`disko.devices.zpool.zroot.datasets.root.options.keylocation = …;`
override — the module system merges nested attrs automatically.

Lost capability: `nix-build tests/luks.nix` standalone-build no
longer works (modules aren't directly buildable). Replace with
`nix build .#checks.<system>.luks`.
2026-05-18 14:21:23 +02:00

28 lines
854 B
Nix

{
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("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";
}