mirror of
https://github.com/nix-community/disko.git
synced 2026-12-02 14:03:28 +01:00
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`.
46 lines
1.8 KiB
Nix
46 lines
1.8 KiB
Nix
{
|
|
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"
|
|
|
|
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";
|
|
}
|