Files
disko/example/complex.nix
Michael Hoang 50f929e48e 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).
2026-05-18 15:17:27 +02:00

218 lines
5.5 KiB
Nix

{
disko.devices = {
disk = {
disk0 = {
type = "disk";
device = "/dev/disk/by-id/ata-QEMU_HARDDISK_QM00001";
content = {
type = "gpt";
partitions = {
ESP = {
start = "1M";
end = "128M";
type = "EF00";
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
mountOptions = [ "umask=0077" ];
};
};
};
};
};
disk1 = {
type = "disk";
device = "/dev/disk/by-id/ata-QEMU_HARDDISK_QM00002";
content = {
type = "gpt";
partitions = {
luks = {
uuid = "f0f0f0f0-f0f0-f0f0-f0f0-f0f0f0f0f0f0";
start = "1M";
size = "100%";
content = {
type = "luks";
name = "crypted1";
settings.keyFile = "/tmp/secret.key";
additionalKeyFiles = [ "/tmp/additionalSecret.key" ];
extraFormatArgs = [
"--iter-time 1" # insecure but fast for tests
];
content = {
type = "lvm_pv";
vg = "pool";
};
};
};
};
};
};
disk2 = {
type = "disk";
device = "/dev/disk/by-id/ata-QEMU_HARDDISK_QM00003";
content = {
type = "gpt";
partitions = {
luks = {
start = "1M";
size = "100%";
content = {
type = "luks";
name = "crypted2";
settings = {
keyFile = "/tmp/secret.key";
keyFileSize = 8;
keyFileOffset = 2;
};
extraFormatArgs = [
"--iter-time 1" # insecure but fast for tests
];
content = {
type = "lvm_pv";
vg = "pool";
};
};
};
};
};
};
};
mdadm = {
raid1 = {
type = "mdadm";
level = 1;
content = {
type = "gpt";
partitions = {
bla = {
start = "1M";
size = "100%";
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/ext4_mdadm_lvm";
};
};
};
};
};
};
lvm_vg = {
pool = {
type = "lvm_vg";
lvs = {
root = {
size = "10M";
lvm_type = "mirror";
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/ext4_on_lvm";
mountOptions = [
"defaults"
];
postMountHook = ''
touch /mnt/ext4_on_lvm/file-from-postMountHook
'';
};
};
raid1 = {
size = "30M";
lvm_type = "raid0";
content = {
type = "mdraid";
name = "raid1";
};
};
raid2 = {
size = "30M";
lvm_type = "raid0";
content = {
type = "mdraid";
name = "raid1";
};
};
zfs1 = {
size = "128M";
lvm_type = "raid0";
content = {
type = "zfs";
pool = "zroot";
};
};
zfs2 = {
size = "128M";
lvm_type = "raid0";
content = {
type = "zfs";
pool = "zroot";
};
};
};
};
};
zpool = {
zroot = {
type = "zpool";
mode = "mirror";
rootFsOptions = {
compression = "zstd";
"com.sun:auto-snapshot" = "false";
};
mountpoint = "/";
datasets = {
zfs_fs = {
type = "zfs_fs";
mountpoint = "/zfs_fs";
options."com.sun:auto-snapshot" = "true";
};
zfs_unmounted_fs = {
type = "zfs_fs";
options.mountpoint = "none";
};
zfs_legacy_fs = {
type = "zfs_fs";
options.mountpoint = "legacy";
mountpoint = "/zfs_legacy_fs";
};
zfs_testvolume = {
type = "zfs_volume";
size = "10M";
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/ext4onzfs";
};
};
};
};
};
};
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";
}