Skip to content

Commit c256b90

Browse files
committed
makeDiskoTest: merge extraSystemConfig before prepareDiskoConfig
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.
1 parent 9b14aa4 commit c256b90

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

lib/tests.nix

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,25 @@ let
107107
importedDiskoConfig { inherit lib; }
108108
else
109109
importedDiskoConfig;
110-
testConfigInstall = testLib.prepareDiskoConfig diskoConfigWithArgs (lib.tail testLib.devices);
110+
111+
# When extendModules is provided (from module.nix), we need to first merge
112+
# extraSystemConfig to get the combined disko configuration, then run
113+
# prepareDiskoConfig on the merged result. This allows users to override
114+
# disko settings (like partition sizes, LUKS keys) via disko.tests.extraConfig.
115+
mergedDiskoConfig =
116+
if extendModules != null then
117+
# Evaluate with extraSystemConfig to get merged disko settings
118+
let
119+
mergedEval = extendModules { modules = [ extraSystemConfig ]; };
120+
in
121+
builtins.removeAttrs mergedEval.config [ "_module" ]
122+
else
123+
diskoConfigWithArgs;
124+
125+
testConfigInstall = testLib.prepareDiskoConfig mergedDiskoConfig (lib.tail testLib.devices);
111126
# we need to shift the disks by one because the first disk is the /dev/vda of the test runner
112127
# so /dev/vdb becomes /dev/vda etc.
113-
testConfigBooted = testLib.prepareDiskoConfig diskoConfigWithArgs testLib.devices;
128+
testConfigBooted = testLib.prepareDiskoConfig mergedDiskoConfig testLib.devices;
114129

115130
tsp-generator = pkgs.callPackage ../. { checked = true; };
116131
tsp-format = (tsp-generator._cliFormat testConfigInstall) pkgs;
@@ -121,6 +136,7 @@ let
121136
num-disks = builtins.length (lib.attrNames testConfigBooted.disko.devices.disk);
122137

123138
# Module containing the base disko configuration for the installed system
139+
# Only used when extendModules is NOT provided (standalone test mode)
124140
diskoModule =
125141
{ config, ... }:
126142
{
@@ -147,6 +163,7 @@ let
147163
};
148164

149165
# Module containing test-specific configuration for the VM environment
166+
# This applies the QEMU device paths from prepareDiskoConfig
150167
testInstrumentationModule =
151168
{ config, modulesPath, ... }:
152169
{
@@ -155,6 +172,10 @@ let
155172
(modulesPath + "/profiles/qemu-guest.nix")
156173
];
157174

175+
# Apply the prepared disko config with QEMU device paths.
176+
# We use mkForce because the device paths MUST be the QEMU virtio devices,
177+
# but other disko settings (partition sizes, LUKS config, etc.) have already
178+
# been merged via extraSystemConfig before prepareDiskoConfig was called.
158179
disko.devices = lib.mkForce testConfigBooted.disko.devices;
159180

160181
# since we boot on a different machine, the efi payload needs to be portable
@@ -207,11 +228,13 @@ let
207228
system = pkgs.stdenv.hostPlatform.system;
208229
}).extendModules;
209230

231+
# When extendModules is provided, extraSystemConfig has already been merged
232+
# into mergedDiskoConfig above, so we only add testInstrumentationModule here.
233+
# When extendModules is NOT provided, we add both.
210234
installed-system-eval = baseExtendModules {
211-
modules = [
212-
testInstrumentationModule
213-
extraSystemConfig
214-
];
235+
modules =
236+
[ testInstrumentationModule ]
237+
++ lib.optional (extendModules == null) extraSystemConfig;
215238
};
216239

217240
installedTopLevel = installed-system-eval.config.system.build.toplevel;

0 commit comments

Comments
 (0)