Skip to content

tests: support overriding disko config#480

Draft
Enzime wants to merge 2 commits intonix-community:masterfrom
Enzime:add/extra-disko-config
Draft

tests: support overriding disko config#480
Enzime wants to merge 2 commits intonix-community:masterfrom
Enzime:add/extra-disko-config

Conversation

@Enzime
Copy link
Copy Markdown
Member

@Enzime Enzime commented Dec 23, 2023

The goal of this PR is to add an interface for end users to be able to override the disko config for disko-based tests like system.build.installTest.

I modified some examples to intentionally fail so that we can add test-specific overrides in the same file to show end users examples of overriding the disko config just for tests.

I chose to not make makeDiskoTest aware of disko-config.disko.tests.extraDiskoConfig to simplify the merging logic, however that means callers of makeDiskoTest need to set extraDiskoConfig from disko.tests.extraDiskoConfig if they're using standalone files like the tests inside this repo.

I'm not really sure if this PR is the right way to implement this as currently it feels like makeDiskoTest is just a poor man's module system:

disko/lib/tests.nix

Lines 44 to 80 in 9ab9637

makeDiskoTest =
{ name
, disko-config
, extendModules ? null
, pkgs ? import <nixpkgs> { }
, extraTestScript ? ""
, bootCommands ? ""
, extraInstallerConfig ? { }
, extraSystemConfig ? { }
, efi ? !pkgs.hostPlatform.isRiscV64
, postDisko ? ""
, testMode ? "module" # can be one of direct module cli
, testBoot ? true # if we actually want to test booting or just create/mount
}:
let
makeTest' = args:
makeTest args {
inherit pkgs;
inherit (pkgs) system;
};
# for installation we skip /dev/vda because it is the test runner disk
importedDiskoConfig =
if builtins.isPath disko-config then
import disko-config
else
disko-config;
diskoConfigWithArgs =
if builtins.isFunction importedDiskoConfig then
importedDiskoConfig { inherit lib; }
else
importedDiskoConfig;
testConfigInstall = testLib.prepareDiskoConfig diskoConfigWithArgs (lib.tail testLib.devices);
# we need to shift the disks by one because the first disk is the /dev/vda of the test runner
# so /dev/vdb becomes /dev/vda etc.
testConfigBooted = testLib.prepareDiskoConfig diskoConfigWithArgs testLib.devices;

and as I'm merging values manually, it makes it feel like that even more:

extendedDiskoConfigWithArgs = lib.recursiveUpdate diskoConfigWithArgs { disko = extraDiskoConfig; };

@Enzime Enzime marked this pull request as draft September 9, 2024 06:36
Enzime pushed a commit to Enzime/disko that referenced this pull request Jan 2, 2026
When extendModules is provided (from module.nix), use it to merge
extraSystemConfig with the base configuration BEFORE running
prepareDiskoConfig. This allows users to override disko settings
(partition sizes, LUKS keys, etc.) via disko.tests.extraConfig using
the proper NixOS module system rather than manual attribute merging.

The key change is that test-specific disko overrides are now merged
before device path transformation, so the overrides are included
when prepareDiskoConfig maps devices to QEMU virtio paths.

This makes PR nix-community#480 obsolete by using extendModules (enabled by PR nix-community#1094's
evalModules support for disko subtypes) instead of lib.recursiveUpdate.
Enzime pushed a commit to Enzime/disko that referenced this pull request Jan 2, 2026
When extendModules is provided (from module.nix), use it to merge
extraSystemConfig with the base configuration BEFORE running
prepareDiskoConfig. This allows users to override disko settings
(partition sizes, LUKS keys, etc.) via disko.tests.extraConfig using
the proper NixOS module system rather than manual attribute merging.

The key change is that test-specific disko overrides are now merged
before device path transformation, so the overrides are included
when prepareDiskoConfig maps devices to QEMU virtio paths.

This makes PR nix-community#480 obsolete by using extendModules (enabled by PR nix-community#1094's
evalModules support for disko subtypes) instead of lib.recursiveUpdate.
Enzime pushed a commit to Enzime/disko that referenced this pull request Jan 2, 2026
When extendModules is provided (from module.nix), use it to merge
extraSystemConfig with the base configuration BEFORE running
prepareDiskoConfig. This allows users to override disko settings
(partition sizes, LUKS keys, etc.) via disko.tests.extraConfig using
the proper NixOS module system rather than manual attribute merging.

The key change is that test-specific disko overrides are now merged
before device path transformation, so the overrides are included
when prepareDiskoConfig maps devices to QEMU virtio paths.

This makes PR nix-community#480 obsolete by using extendModules (enabled by PR nix-community#1094's
evalModules support for disko subtypes) instead of lib.recursiveUpdate.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant