mirror of
https://github.com/nix-community/disko.git
synced 2026-12-02 14:03:28 +01:00
tests: modulify in-repo tests; switch tests/default.nix to evalModules discovery
Convert all 40 `tests/*.nix` files that previously called
`diskoLib.testLib.makeDiskoTest { … }` into pure NixOS modules. Each
test now imports its corresponding `../example/foo.nix` and sets
`disko.test = { name = …; extraChecks = …; nodes.machine = …; … };`
inline.
Switch `tests/default.nix` to discover the module-style tests via
nixpkgs's `nixos/lib/eval-config.nix` and read
`config.system.build.diskoTest` off each. The four bespoke tests
(`make-disk-image`, `make-disk-image-impure`, `mdadm-btrfs-wipe`,
`standalone`) keep their function-call shape and are still imported
imperatively; they don't fit the example-eval pattern.
Arg-to-option translations performed in each file:
- `extraSystemConfig` → `disko.test.nodes.machine`
- `extraInstallerConfig` → `disko.test.nodes.formatter`
- `bootCommands`/`efi`/`enableOCR`/`postDisko`/`enableCanokey`
/`name` → `disko.test.<same>`
- `extraTestScript` → `disko.test.extraChecks`
- `testBoot` → `disko.test.boot`
- `testMode` → `disko.test.mode` (`cli` and `module` set this
explicitly; the rest use the default `"module"`)
- `extraInstallerConfig.networking.hostId` /
`extraSystemConfig.networking.hostId` → host-level
`networking.hostId` (propagated to every node by module.nix's
`defaults.networking.hostId` in the evalTest call)
`tests/cli.nix` and `tests/module.nix` both import
`../example/complex.nix` and override `disko.test.{name,mode,extraChecks}`
with `lib.mkForce` — those overrides will keep working after commit 8
folds `tests/complex.nix`'s `disko.test` block into
`example/complex.nix`.
`tests/zfs-encrypted-root.nix`'s legacy `pkgs.lib.recursiveUpdate` on
the imported disko-config becomes a flat
`disko.devices.zpool.zroot.datasets.root.options.keylocation = …;`
override — the module system merges nested attrs automatically.
Lost capability: `nix-build tests/luks.nix` standalone-build no
longer works (modules aren't directly buildable). Replace with
`nix build .#checks.<system>.luks`.
This commit is contained in:
1 parent
6e082c9e74
commit
88275cedd4
42 files changed
+652
-813
No files matched your search
+36
-22
@@ -1,36 +1,50 @@
|
||||
{
|
||||
makeTest ? import <nixpkgs/nixos/tests/make-test-python.nix>,
|
||||
eval-config ? import <nixpkgs/nixos/lib/eval-config.nix>,
|
||||
qemu-common ? import <nixpkgs/nixos/lib/qemu-common.nix>,
|
||||
pkgs ? import <nixpkgs> { },
|
||||
...
|
||||
}:
|
||||
let
|
||||
lib = pkgs.lib;
|
||||
diskoLib = import ../lib {
|
||||
inherit
|
||||
lib
|
||||
makeTest
|
||||
eval-config
|
||||
qemu-common
|
||||
;
|
||||
};
|
||||
inherit (pkgs) lib;
|
||||
|
||||
allTestFilenames = builtins.map (lib.removeSuffix ".nix") (
|
||||
builtins.filter (x: lib.hasSuffix ".nix" x && x != "default.nix") (
|
||||
lib.attrNames (builtins.readDir ./.)
|
||||
)
|
||||
);
|
||||
incompatibleTests = lib.optionals pkgs.stdenv.buildPlatform.isRiscV64 [
|
||||
bespoke = [
|
||||
"make-disk-image"
|
||||
"make-disk-image-impure"
|
||||
"mdadm-btrfs-wipe"
|
||||
"standalone"
|
||||
];
|
||||
incompatible = lib.optionals pkgs.stdenv.buildPlatform.isRiscV64 [
|
||||
"zfs"
|
||||
"zfs-over-legacy"
|
||||
"cli"
|
||||
"module"
|
||||
"complex"
|
||||
];
|
||||
allCompatibleFilenames = lib.subtractLists incompatibleTests allTestFilenames;
|
||||
|
||||
allTests = lib.genAttrs allCompatibleFilenames (
|
||||
test: import (./. + "/${test}.nix") { inherit diskoLib pkgs; }
|
||||
listNix =
|
||||
dir:
|
||||
map (lib.removeSuffix ".nix") (
|
||||
lib.attrNames (
|
||||
lib.filterAttrs (n: _: lib.hasSuffix ".nix" n && n != "default.nix") (builtins.readDir dir)
|
||||
)
|
||||
);
|
||||
|
||||
evalModule =
|
||||
file:
|
||||
import (pkgs.path + "/nixos/lib/eval-config.nix") {
|
||||
system = pkgs.stdenv.hostPlatform.system;
|
||||
modules = [
|
||||
../module.nix
|
||||
file
|
||||
];
|
||||
};
|
||||
|
||||
testsDirModule = lib.genAttrs (lib.subtractLists bespoke (listNix ./.)) (
|
||||
name: evalModule (./. + "/${name}.nix")
|
||||
);
|
||||
|
||||
moduleTests = lib.mapAttrs (_: eval: eval.config.system.build.diskoTest) (
|
||||
lib.removeAttrs testsDirModule incompatible
|
||||
);
|
||||
|
||||
bespokeTests = lib.genAttrs bespoke (name: import (./. + "/${name}.nix") { inherit pkgs; });
|
||||
in
|
||||
allTests
|
||||
moduleTests // bespokeTests
|
||||
Reference in new issue
Block a user