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).
75 lines
2.5 KiB
Nix
75 lines
2.5 KiB
Nix
{ pkgs, ... }:
|
|
{
|
|
disko.devices = {
|
|
disk = {
|
|
main = {
|
|
device = "/dev/vdb";
|
|
type = "disk";
|
|
content = {
|
|
type = "gpt";
|
|
partitions = {
|
|
ESP = {
|
|
size = "500M";
|
|
type = "EF00";
|
|
content = {
|
|
type = "filesystem";
|
|
format = "vfat";
|
|
mountpoint = "/boot";
|
|
mountOptions = [ "umask=0077" ];
|
|
};
|
|
};
|
|
root = {
|
|
end = "-1G";
|
|
content = {
|
|
type = "filesystem";
|
|
format = "ext4";
|
|
mountpoint = "/";
|
|
};
|
|
};
|
|
encryptedSwap = {
|
|
size = "10M";
|
|
content = {
|
|
type = "swap";
|
|
randomEncryption = true;
|
|
priority = 100; # prefer to encrypt as long as we have space for it
|
|
};
|
|
};
|
|
plainSwap = {
|
|
size = "100%";
|
|
content = {
|
|
type = "swap";
|
|
discardPolicy = "both";
|
|
resumeDevice = true; # resume from hiberation from this device
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
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}"
|
|
|
|
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 ];
|
|
};
|
|
}
|