After the makeDiskoTest rewrite (commit 4) and the tests/ modulification
(commit 5), the `makeTest`, `eval-config`, and `qemu-common` args
threaded through
flake.nix -> diskoLib = import ./lib { … }
-> import ./tests { … }
lib/default.nix -> testLib = import ./tests.nix { … }
module.nix -> _module.args.diskoLib = import ./lib { … }
are dead — every callsite now imports
`nixos/lib/eval-config.nix` and `nixos/lib/qemu-common.nix` directly
from `pkgs.path` (see `lib/tests.nix`, `lib/install-test.nix`,
`tests/default.nix`). `makeTest` is replaced by the
`nixos-lib.evalTest` call in `module.nix`'s `installTestEval` block.
Strip the dead threading:
- `flake.nix`: drop the three args from the `diskoLib = import ./lib`
call and the `import ./tests` call.
- `lib/default.nix`: drop them from the function signature and from
the `testLib = import ./tests.nix { … }` call; drop the
`qemu-common-lib` derivation that wrapped `qemu-common`.
- `lib/tests.nix`: drop them from the function signature.
- `module.nix`: drop them from the inner `_module.args.diskoLib =
import ./lib { … }` call; drop the now-unused `modulesPath` arg
destructure (its only consumers were the three
`import "${modulesPath}/..."` lines just removed).
One-line semantic change in `module.nix`: replace
`installTest = diskoLib.testLib.makeDiskoTest { … };` with
`installTest = lib.mkDefault config.disko.test.test;` in the
`system.build` attrset — same RHS as the `diskoTest` definition added
in the previous commit.
After this commit, `diskoTest` and `installTest` are two attrset
entries with identical values; `installTest` is purely a back-compat
alias resolving to the exact same derivation as `diskoTest`.
The `cfg.test.efi` / `cfg.test.bootCommands` / etc. reads that used to
be `makeDiskoTest` arguments disappear with the legacy call.
`vmWithDisko` stays unchanged.
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.
Allow users to override the automatic thread count detection for nix
store copying. The default "auto" behavior remains unchanged (min of
nproc and 8), but users can now specify a fixed thread count for
environments where the automatic detection isn't optimal.
It seems that there is a difference between how `pkgs` and `lib` get
passed to NixOS modules: `pkgs` is the unmodified original, `lib` is the
final version after overrides etc.
This causes `pkgs.lib.version` to be `24.11git` in some cases, while
`lib.version` is `24.11.20241123.0c58267`.
Maybe this can be fixed in nixpkgs? Either way, this change fixes that
issue.
Fixes#904
Previously, an error like
error: function 'anonymous lambda' called with unexpected argument 'customQemu'
at /nix/store/lbqj1cndic4121whnx8xm0jgb1c8x4xx-source/pkgs/build-support/vm/default.nix:1:1:
was printed when trying to evaluate `config.system.build.vmWithDisko` or
`config.system.build.diskoImagesScript` with nixpkgs 24.05 (and below).
This argument was added in
https://github.com/NixOS/nixpkgs/commit/65c851cd7523c669b8fb25236b1c48283a2f43ec,
so technically the minimum version is 24.11.20240708.65c851c. However,
`versionAtLeast` only compares versions alphabetically, so the comparison's
result will be incorrect for other commits made on the same day.
Instead, we compare against 24.11.20240709, which is the next day.
This means this function returns false for some commits that DO support the
customQemu argument, but if it returns true, we can be 100% certain that this
is correct, and we can pass the customQemu argument to vmTools without an
evaluation error.
Fixes#850
As `makeDiskImages` always requires a NixOS configuration, we can
simplify the code by convering it into a NixOS module. Then we can make
it responsible for populating `system.build.diskoImages` and
`system.build.diskoImagesScript`.
This is needed to prevent two layers of emulation when offering a build for a host running binfmt such as an x86 host trying to compile for aarch64 via binfmt
This is especially useful when trying to build images for embedded systems such as the pi, which have a vendor kernel that can't be booted as part of the disko image builder process
fixes an error when using this minimal configuration:
```nix
let
pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/tarball/nixos-23.11") { };
disko = fetchTarball "https://github.com/nix-community/disko/tarball/master";
in
pkgs.nixos {
imports = [
"${disko}/module.nix"
"${disko}/example/hybrid.nix"
];
}
```
when running:
```console
$ nix-build
...
error: 'default' at /nix/store/y981rwszq9yi36rvvz2vrr6hb22si0hc-source/lib/default.nix:391:23 called with unexpected argument 'system'
```
I do build my workstation with `documentation.nixos.includeAllModules`
to also have private modules and external stuff in my local options'
reference.
Not sure why exactly this breaks with
error: attribute 'loader' missing
at /nix/store/h6qicay9fgggx9nf6apdl6zkdpdp28xx-source/module.nix:46:19:
45| type = lib.types.bool;
46| default = config.boot.loader.systemd-boot.enable || config.boot.loader.grub.efiSupport;
| ^
47| };
but using defaultText is the usual fix that also works here.