Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: support overriding disko config #480

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Enzime
Copy link
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
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