Files
disko/example/luks-btrfs-raid.nix
T
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

87 lines
2.6 KiB
Nix

{
disko.devices = {
disk = {
# Devices will be mounted and formatted in alphabetical order, and btrfs can only mount raids
# when all devices are present. So we define an "empty" luks device on the first disk,
# and the actual btrfs raid on the second disk, and the name of these entries matters!
disk1 = {
type = "disk";
device = "/dev/sda";
content = {
type = "gpt";
partitions = {
ESP = {
size = "512M";
type = "EF00";
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
mountOptions = [ "umask=0077" ];
};
};
crypt_p1 = {
size = "100%";
content = {
type = "luks";
name = "p1"; # device-mapper name when decrypted
# Remove settings.keyFile if you want to use interactive password entry
settings = {
allowDiscards = true;
keyFile = "/tmp/secret.key";
};
};
};
};
};
};
disk2 = {
type = "disk";
device = "/dev/sdb";
content = {
type = "gpt";
partitions = {
crypt_p2 = {
size = "100%";
content = {
type = "luks";
name = "p2";
# Remove settings.keyFile if you want to use interactive password entry
settings = {
allowDiscards = true;
keyFile = "/tmp/secret.key"; # Same key for both devices
};
content = {
type = "btrfs";
extraArgs = [
"-d raid1"
"/dev/mapper/p1" # Use decrypted mapped device, same name as defined in disk1
];
subvolumes = {
"/root" = {
mountpoint = "/";
mountOptions = [
"rw"
"relatime"
"ssd"
];
};
};
};
};
};
};
};
};
};
};
disko.test = {
name = "luks-btrfs-raid";
extraChecks = ''
machine.succeed("cryptsetup isLuks /dev/vda2");
machine.succeed("cryptsetup isLuks /dev/vdb1");
machine.succeed("btrfs subvolume list /");
'';
};
}