mirror of
https://github.com/nix-community/disko.git
synced 2026-11-30 21:13:28 +01:00
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).
152 lines
4.0 KiB
Nix
152 lines
4.0 KiB
Nix
{
|
|
disko.devices = {
|
|
disk = {
|
|
x = {
|
|
type = "disk";
|
|
device = "/dev/sdx";
|
|
content = {
|
|
type = "gpt";
|
|
partitions = {
|
|
ESP = {
|
|
size = "64M";
|
|
type = "EF00";
|
|
content = {
|
|
type = "filesystem";
|
|
format = "vfat";
|
|
mountpoint = "/boot";
|
|
mountOptions = [ "umask=0077" ];
|
|
};
|
|
};
|
|
root = {
|
|
size = "100%";
|
|
content = {
|
|
type = "filesystem";
|
|
format = "ext4";
|
|
mountpoint = "/";
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
y = {
|
|
type = "disk";
|
|
device = "/dev/sdy";
|
|
content = {
|
|
type = "gpt";
|
|
partitions = {
|
|
zfs = {
|
|
size = "100%";
|
|
content = {
|
|
type = "zfs";
|
|
pool = "storage";
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
z = {
|
|
type = "disk";
|
|
device = "/dev/sdz";
|
|
content = {
|
|
type = "gpt";
|
|
partitions = {
|
|
zfs = {
|
|
size = "100%";
|
|
content = {
|
|
type = "zfs";
|
|
pool = "storage";
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
a = {
|
|
type = "disk";
|
|
device = "/dev/sda";
|
|
content = {
|
|
type = "gpt";
|
|
partitions = {
|
|
zfs = {
|
|
size = "100%";
|
|
content = {
|
|
type = "zfs";
|
|
pool = "storage2";
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
zpool = {
|
|
storage = {
|
|
type = "zpool";
|
|
mode = "mirror";
|
|
mountpoint = "/storage";
|
|
|
|
datasets = {
|
|
dataset = {
|
|
type = "zfs_fs";
|
|
mountpoint = "/storage/dataset";
|
|
};
|
|
};
|
|
};
|
|
storage2 = {
|
|
type = "zpool";
|
|
mountpoint = "/storage2";
|
|
rootFsOptions = {
|
|
canmount = "off";
|
|
};
|
|
|
|
datasets = {
|
|
dataset = {
|
|
type = "zfs_fs";
|
|
mountpoint = "/storage2/dataset";
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
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";
|
|
}
|