mirror of
https://github.com/nix-community/disko.git
synced 2026-12-01 13:33: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).
94 lines
3.0 KiB
Nix
94 lines
3.0 KiB
Nix
{
|
|
disko.devices = {
|
|
disk = {
|
|
main = {
|
|
type = "disk";
|
|
device = "/dev/disk/by-diskseq/1";
|
|
content = {
|
|
type = "gpt";
|
|
partitions = {
|
|
ESP = {
|
|
priority = 1;
|
|
name = "ESP";
|
|
start = "1M";
|
|
end = "128M";
|
|
type = "EF00";
|
|
content = {
|
|
type = "filesystem";
|
|
format = "vfat";
|
|
mountpoint = "/boot";
|
|
mountOptions = [ "umask=0077" ];
|
|
};
|
|
};
|
|
root = {
|
|
size = "100%";
|
|
content = {
|
|
type = "btrfs";
|
|
extraArgs = [ "-f" ]; # Override existing partition
|
|
# Subvolumes must set a mountpoint in order to be mounted,
|
|
# unless their parent is mounted
|
|
subvolumes = {
|
|
# Subvolume name is different from mountpoint
|
|
"/rootfs" = {
|
|
mountpoint = "/";
|
|
};
|
|
# Subvolume name is the same as the mountpoint
|
|
"/home" = {
|
|
mountOptions = [ "compress=zstd" ];
|
|
mountpoint = "/home";
|
|
};
|
|
# Sub(sub)volume doesn't need a mountpoint as its parent is mounted
|
|
"/home/user" = { };
|
|
# Parent is not mounted so the mountpoint must be set
|
|
"/nix" = {
|
|
mountOptions = [
|
|
"compress=zstd"
|
|
"noatime"
|
|
];
|
|
mountpoint = "/nix";
|
|
};
|
|
# This subvolume will be created but not mounted
|
|
"/test" = { };
|
|
# Subvolume for the swapfile
|
|
"/swap" = {
|
|
mountpoint = "/.swapvol";
|
|
swap = {
|
|
swapfile.size = "20M";
|
|
swapfile2.size = "20M";
|
|
swapfile2.path = "rel-path";
|
|
};
|
|
};
|
|
};
|
|
|
|
mountpoint = "/partition-root";
|
|
swap = {
|
|
swapfile = {
|
|
size = "20M";
|
|
};
|
|
swapfile1 = {
|
|
size = "20M";
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
disko.test = {
|
|
name = "btrfs-subvolumes";
|
|
extraChecks = ''
|
|
machine.succeed("test ! -e /test");
|
|
machine.succeed("test -e /home/user");
|
|
machine.succeed("btrfs subvolume list / | grep -qs 'path test$'");
|
|
machine.succeed("btrfs subvolume list / | grep -qs 'path nix$'");
|
|
machine.succeed("btrfs subvolume list / | grep -qs 'path home$'");
|
|
machine.succeed("test -e /.swapvol/swapfile");
|
|
machine.succeed("test -e /.swapvol/rel-path");
|
|
machine.succeed("test -e /partition-root/swapfile");
|
|
machine.succeed("test -e /partition-root/swapfile1");
|
|
'';
|
|
};
|
|
}
|