mirror of
https://github.com/nix-community/disko.git
synced 2026-11-30 13:03:28 +01:00
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.
88 lines
2.6 KiB
Nix
88 lines
2.6 KiB
Nix
{
|
|
diskoLib,
|
|
modulesPath,
|
|
config,
|
|
pkgs,
|
|
lib,
|
|
...
|
|
}:
|
|
|
|
let
|
|
vm_disko = (diskoLib.testLib.prepareDiskoConfig config diskoLib.testLib.devices).disko;
|
|
cfg_ =
|
|
(lib.evalModules {
|
|
modules = lib.singleton {
|
|
# _file = toString input;
|
|
imports = lib.singleton { disko.devices = vm_disko.devices; };
|
|
options = {
|
|
disko.devices = lib.mkOption {
|
|
type = diskoLib.toplevel;
|
|
};
|
|
disko.testMode = lib.mkOption {
|
|
type = lib.types.bool;
|
|
default = true;
|
|
};
|
|
};
|
|
};
|
|
}).config;
|
|
disks = lib.attrValues cfg_.disko.devices.disk;
|
|
rootDisk = {
|
|
name = "root";
|
|
file = ''"$tmp"/${lib.escapeShellArg (builtins.head disks).imageName}.qcow2'';
|
|
driveExtraOpts.cache = "writeback";
|
|
driveExtraOpts.werror = "report";
|
|
deviceExtraOpts.bootindex = "1";
|
|
deviceExtraOpts.serial = "root";
|
|
};
|
|
otherDisks = map (disk: {
|
|
name = disk.name;
|
|
file = ''"$tmp"/${lib.escapeShellArg disk.imageName}.qcow2'';
|
|
driveExtraOpts.werror = "report";
|
|
}) (builtins.tail disks);
|
|
|
|
diskoBasedConfiguration = {
|
|
# generated from disko config
|
|
virtualisation.fileSystems = cfg_.disko.devices._config.fileSystems;
|
|
boot = cfg_.disko.devices._config.boot or { };
|
|
swapDevices = cfg_.disko.devices._config.swapDevices or [ ];
|
|
};
|
|
|
|
hostPkgs = config.virtualisation.host.pkgs;
|
|
in
|
|
{
|
|
imports = [
|
|
(modulesPath + "/virtualisation/qemu-vm.nix")
|
|
diskoBasedConfiguration
|
|
];
|
|
|
|
disko.testMode = true;
|
|
|
|
disko.imageBuilder.copyNixStore = false;
|
|
disko.imageBuilder.extraConfig = {
|
|
disko.devices = cfg_.disko.devices;
|
|
};
|
|
disko.imageBuilder.imageFormat = "qcow2";
|
|
|
|
virtualisation.useEFIBoot = config.disko.test.efi;
|
|
virtualisation.memorySize = lib.mkDefault config.disko.memSize;
|
|
virtualisation.useDefaultFilesystems = false;
|
|
virtualisation.diskImage = null;
|
|
virtualisation.qemu.drives = [ rootDisk ] ++ otherDisks;
|
|
boot.zfs.devNodes = "/dev/disk/by-uuid"; # needed because /dev/disk/by-id is empty in qemu-vms
|
|
boot.zfs.forceImportAll = true;
|
|
boot.zfs.forceImportRoot = lib.mkForce true;
|
|
|
|
system.build.vmWithDisko = hostPkgs.writers.writeDashBin "disko-vm" ''
|
|
set -efux
|
|
export tmp=$(${hostPkgs.coreutils}/bin/mktemp -d)
|
|
trap 'rm -rf "$tmp"' EXIT
|
|
${lib.concatMapStringsSep "\n" (disk: ''
|
|
${hostPkgs.qemu}/bin/qemu-img create -f qcow2 \
|
|
-b ${config.system.build.diskoImages}/${lib.escapeShellArg disk.imageName}.qcow2 \
|
|
-F qcow2 "$tmp"/${lib.escapeShellArg disk.imageName}.qcow2
|
|
'') disks}
|
|
set +f
|
|
${config.system.build.vm}/bin/run-*-vm "$@"
|
|
'';
|
|
}
|