mirror of
https://github.com/nix-community/disko.git
synced 2026-12-02 05:53:28 +01:00
module.nix: wire disko.test as the test eval
Five coupled changes that must land together because they form one
atomic refactor of disko's test-option surface:
- Define `installTestEval` in the let-block via
`nixos-lib.evalTest`, importing `./lib/install-test.nix` and
threading `diskoLib`, `diskoDevices` (and indirectly `pkgs` via
`hostPkgs`) into the test eval's module args. Propagate the
host-level `networking.hostId` to every node via the framework's
native `defaults` hook — single source of truth, so
`lib/install-test.nix` drops its per-node hostId setter on
`nodes.formatter` (the host eval's hostId now flows to formatter
and machine identically).
- Declare `options.disko.test` as a submodule whose type is borrowed
from `installTestEval.type` — i.e. the full NixOS-test option tree
(`nodes`, `testScript`, `defaults`, `globalTimeout`, …) plus the
seven disko knobs declared in `./lib/install-test.nix`. Add
`diskoTest = lib.mkDefault config.disko.test.test;` to the
`system.build` attrset next to the existing
`installTest = makeDiskoTest { … };` (the legacy definition stays
for this commit).
- Delete the flat `disko.tests.{bootCommands,efi,enableOCR,extraChecks,extraConfig}`
declarations from the `options.disko` block. Drop the now-deleted
`config.disko.tests.extraConfig` import from `vmVariantWithDisko`'s
`extendModules` call.
- Add migration modules to the imports list:
- `mkRemovedOptionModule` for `disko.tests.extraConfig` with a
message pointing users at `disko.test.defaults` /
`virtualisation.vmVariantWithDisko = { imports = [ … ]; };`.
- 8 × `mkRenamedOptionModule` redirecting flat knobs into the
`disko.test` submodule. Existing user configs keep working with
one deprecation warning per renamed setter.
- Update `lib/interactive-vm.nix:66`: `config.disko.tests.efi` →
`config.disko.test.efi`. The legacy path would still resolve via
the rename but emit a deprecation warning on every interactive-VM
eval — update the callsite to be quiet.
The legacy `installTest = makeDiskoTest { … };` in the `system.build`
attrset is left in place but its read of `cfg.tests.extraConfig` is
dropped (the option no longer exists; the other reads forward through
`mkRenamedOptionModule`). The next commit replaces its RHS with
`lib.mkDefault config.disko.test.test` so both attrset entries point at
the same drv.
This commit is contained in:
1 parent
7a420ab8b0
commit
9f4cb09648
3 files changed
+83
-57
No files matched your search
@@ -134,9 +134,10 @@
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
networking.hostId = lib.mkIf (
|
# `networking.hostId` is propagated to every node via
|
||||||
(testConfigInstall ? networking.hostId) && (testConfigInstall.networking.hostId != null)
|
# `defaults.networking.hostId` in module.nix's evalTest call
|
||||||
) testConfigInstall.networking.hostId;
|
# (sourced from the host eval's config). No per-node setter
|
||||||
|
# needed here.
|
||||||
virtualisation = {
|
virtualisation = {
|
||||||
emptyDiskImages = builtins.genList (_: 4096) num-disks;
|
emptyDiskImages = builtins.genList (_: 4096) num-disks;
|
||||||
qemu.options = lib.mkIf config.enableCanokey [
|
qemu.options = lib.mkIf config.enableCanokey [
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ in
|
|||||||
};
|
};
|
||||||
disko.imageBuilder.imageFormat = "qcow2";
|
disko.imageBuilder.imageFormat = "qcow2";
|
||||||
|
|
||||||
virtualisation.useEFIBoot = config.disko.tests.efi;
|
virtualisation.useEFIBoot = config.disko.test.efi;
|
||||||
virtualisation.memorySize = lib.mkDefault config.disko.memSize;
|
virtualisation.memorySize = lib.mkDefault config.disko.memSize;
|
||||||
virtualisation.useDefaultFilesystems = false;
|
virtualisation.useDefaultFilesystems = false;
|
||||||
virtualisation.diskImage = null;
|
virtualisation.diskImage = null;
|
||||||
|
|||||||
+78
-53
@@ -11,14 +11,61 @@ let
|
|||||||
cfg = config.disko;
|
cfg = config.disko;
|
||||||
|
|
||||||
vmVariantWithDisko = extendModules {
|
vmVariantWithDisko = extendModules {
|
||||||
modules = [
|
modules = [ ./lib/interactive-vm.nix ];
|
||||||
./lib/interactive-vm.nix
|
};
|
||||||
config.disko.tests.extraConfig
|
|
||||||
|
# `evalTest` (not `runTest`) because we need the evalModules result's
|
||||||
|
# `.type` to declare `options.disko.test` as a submodule. `runTest`'s
|
||||||
|
# `.type` is the string "derivation", unusable as an option type.
|
||||||
|
nixos-lib = import (pkgs.path + "/nixos/lib") { inherit lib; };
|
||||||
|
installTestEval = nixos-lib.evalTest {
|
||||||
|
imports = [
|
||||||
|
./lib/install-test.nix
|
||||||
|
{
|
||||||
|
hostPkgs = pkgs;
|
||||||
|
node.pkgs = pkgs;
|
||||||
|
_module.args = {
|
||||||
|
inherit diskoLib;
|
||||||
|
diskoDevices = config.disko.devices;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
{
|
||||||
|
defaults.networking.hostId = lib.mkIf (config.networking.hostId != null) config.networking.hostId;
|
||||||
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
imports = [ ./lib/make-disk-image.nix ];
|
imports = [
|
||||||
|
./lib/make-disk-image.nix
|
||||||
|
|
||||||
|
(lib.mkRemovedOptionModule [ "disko" "tests" "extraConfig" ] ''
|
||||||
|
`disko.tests.extraConfig` has been removed. The shared-overlay role
|
||||||
|
split into the two consumers that previously imported it:
|
||||||
|
|
||||||
|
- For the install-test, set on `disko.test.defaults` (applies to
|
||||||
|
every node — the test framework's native "imported into all
|
||||||
|
nodes" hook):
|
||||||
|
|
||||||
|
disko.test.defaults = { ... };
|
||||||
|
|
||||||
|
- For `system.build.vmWithDisko`, set on the variant directly:
|
||||||
|
|
||||||
|
virtualisation.vmVariantWithDisko = { imports = [ ... ]; };
|
||||||
|
'')
|
||||||
|
|
||||||
|
# 8 × `mkRenamedOptionModule` redirecting flat knobs into the
|
||||||
|
# `disko.test` submodule. Existing user configs keep working with one
|
||||||
|
# deprecation warning per renamed setter.
|
||||||
|
(lib.mkRenamedOptionModule [ "disko" "tests" "bootCommands" ] [ "disko" "test" "bootCommands" ])
|
||||||
|
(lib.mkRenamedOptionModule [ "disko" "tests" "efi" ] [ "disko" "test" "efi" ])
|
||||||
|
(lib.mkRenamedOptionModule [ "disko" "tests" "extraChecks" ] [ "disko" "test" "extraChecks" ])
|
||||||
|
(lib.mkRenamedOptionModule [ "disko" "tests" "boot" ] [ "disko" "test" "boot" ])
|
||||||
|
(lib.mkRenamedOptionModule [ "disko" "tests" "enableCanokey" ] [ "disko" "test" "enableCanokey" ])
|
||||||
|
(lib.mkRenamedOptionModule [ "disko" "tests" "postDisko" ] [ "disko" "test" "postDisko" ])
|
||||||
|
(lib.mkRenamedOptionModule [ "disko" "tests" "name" ] [ "disko" "test" "name" ])
|
||||||
|
(lib.mkRenamedOptionModule [ "disko" "tests" "enableOCR" ] [ "disko" "test" "enableOCR" ])
|
||||||
|
];
|
||||||
|
|
||||||
options.disko = {
|
options.disko = {
|
||||||
imageBuilder = {
|
imageBuilder = {
|
||||||
@@ -184,53 +231,30 @@ in
|
|||||||
default = false;
|
default = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
tests = {
|
};
|
||||||
bootCommands = lib.mkOption {
|
|
||||||
description = ''
|
|
||||||
NixOS test script commands to run after the machine has started. Can
|
|
||||||
be used to enter an interactive password.
|
|
||||||
'';
|
|
||||||
type = lib.types.lines;
|
|
||||||
default = "";
|
|
||||||
};
|
|
||||||
|
|
||||||
efi = lib.mkOption {
|
options.disko.test = lib.mkOption {
|
||||||
description = ''
|
description = ''
|
||||||
Whether efi is enabled for the `system.build.installTest`.
|
The full NixOS test evaluation backing `system.build.diskoTest`
|
||||||
We try to automatically detect efi based on the configured bootloader.
|
(and its back-compat alias `system.build.installTest`).
|
||||||
'';
|
|
||||||
type = lib.types.bool;
|
|
||||||
defaultText = "config.boot.loader.systemd-boot.enable || config.boot.loader.grub.efiSupport";
|
|
||||||
default = config.boot.loader.systemd-boot.enable || config.boot.loader.grub.efiSupport;
|
|
||||||
};
|
|
||||||
|
|
||||||
enableOCR = lib.mkOption {
|
Override `nodes.formatter` to tweak the formatter VM (the one that
|
||||||
description = ''
|
runs disko); override `nodes.machine` to tweak the booted system.
|
||||||
Sets the enableOCR option in the NixOS VM test driver.
|
Override `testScript`, `enableOCR`, `defaults`, `globalTimeout`,
|
||||||
'';
|
etc. to reach the test framework directly. The disko-specific
|
||||||
type = lib.types.bool;
|
convenience knobs (`extraChecks`, `bootCommands`, `boot`, `efi`,
|
||||||
default = false;
|
`postDisko`, `enableCanokey`, `mode`) are declared on the test
|
||||||
};
|
eval inside `./lib/install-test.nix` itself.
|
||||||
|
|
||||||
extraChecks = lib.mkOption {
|
Singular: there's one install-test today. The path is the *role*
|
||||||
description = ''
|
("a test"); the framework's `name` option discriminates the
|
||||||
extra checks to run in the `system.build.installTest`.
|
*identity* (e.g. `disko.test.name = "luks-on-mdadm";`). Future
|
||||||
'';
|
tests, if any materialize, sit at parallel singular paths
|
||||||
type = lib.types.lines;
|
(`disko.formatTest`, `disko.upgradeTest`).
|
||||||
default = "";
|
'';
|
||||||
example = ''
|
inherit (installTestEval) type;
|
||||||
machine.succeed("test -e /var/secrets/my.secret")
|
default = { };
|
||||||
'';
|
visible = "shallow";
|
||||||
};
|
|
||||||
|
|
||||||
extraConfig = lib.mkOption {
|
|
||||||
description = ''
|
|
||||||
Extra NixOS config for your test. Can be used to specify a different luks key for tests.
|
|
||||||
A dummy key is in /tmp/secret.key
|
|
||||||
'';
|
|
||||||
default = { };
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
options.virtualisation.vmVariantWithDisko = lib.mkOption {
|
options.virtualisation.vmVariantWithDisko = lib.mkOption {
|
||||||
@@ -291,13 +315,14 @@ in
|
|||||||
name = "${config.networking.hostName}-disko";
|
name = "${config.networking.hostName}-disko";
|
||||||
disko-config = builtins.removeAttrs config [ "_module" ];
|
disko-config = builtins.removeAttrs config [ "_module" ];
|
||||||
testMode = "direct";
|
testMode = "direct";
|
||||||
bootCommands = cfg.tests.bootCommands;
|
bootCommands = cfg.test.bootCommands;
|
||||||
efi = cfg.tests.efi;
|
efi = cfg.test.efi;
|
||||||
enableOCR = cfg.tests.enableOCR;
|
enableOCR = cfg.test.enableOCR;
|
||||||
extraSystemConfig = cfg.tests.extraConfig;
|
extraTestScript = cfg.test.extraChecks;
|
||||||
extraTestScript = cfg.tests.extraChecks;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
diskoTest = lib.mkDefault config.disko.test.test;
|
||||||
|
|
||||||
vmWithDisko = lib.mkDefault config.virtualisation.vmVariantWithDisko.system.build.vmWithDisko;
|
vmWithDisko = lib.mkDefault config.virtualisation.vmVariantWithDisko.system.build.vmWithDisko;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in new issue
Block a user