testLib.makeDiskoTest: split extraConfig into nixos-config, extraSystemConfig & extraInstallerConfig

This commit is contained in:
lassulus 2023-07-15 16:57:18 +02:00 committed by mergify[bot]
parent 056637d3c9
commit 715c211dd7
10 changed files with 46 additions and 40 deletions

View File

@ -32,10 +32,12 @@ let
makeDiskoTest = makeDiskoTest =
{ name { name
, disko-config , disko-config
, nixos-config ? null
, pkgs ? import <nixpkgs> { } , pkgs ? import <nixpkgs> { }
, extraTestScript ? "" , extraTestScript ? ""
, bootCommands ? "" , bootCommands ? ""
, extraConfig ? { } , extraInstallerConfig ? { }
, extraSystemConfig ? { }
, grub-devices ? [ "nodev" ] , grub-devices ? [ "nodev" ]
, efi ? true , efi ? true
, postDisko ? "" , postDisko ? ""
@ -62,7 +64,17 @@ let
tsp-config = tsp-generator.config testConfigBooted; tsp-config = tsp-generator.config testConfigBooted;
num-disks = builtins.length (lib.attrNames testConfigBooted.disko.devices.disk); num-disks = builtins.length (lib.attrNames testConfigBooted.disko.devices.disk);
installed-system = { modulesPath, ... }: { installed-system = { modulesPath, ... }: {
imports = [ # we always want the bind-mounted nix store. otherwise tests take forever
fileSystems."/nix/store" = lib.mkForce {
device = "nix-store";
fsType = "9p";
neededForBoot = true;
options = [ "trans=virtio" "version=9p2000.L" "cache=loose" ];
};
imports = (if nixos-config != null then [
nixos-config
] else [
(lib.optionalAttrs (testMode == "direct" || testMode == "cli") tsp-config) (lib.optionalAttrs (testMode == "direct" || testMode == "cli") tsp-config)
(lib.optionalAttrs (testMode == "module") { (lib.optionalAttrs (testMode == "module") {
disko.enableConfig = true; disko.enableConfig = true;
@ -71,31 +83,27 @@ let
testConfigBooted testConfigBooted
]; ];
}) })
(modulesPath + "/testing/test-instrumentation.nix") { # config for tests to make them run faster or work at all
(modulesPath + "/profiles/qemu-guest.nix") documentation.enable = false;
(modulesPath + "/profiles/minimal.nix") hardware.enableAllFirmware = lib.mkForce false;
extraConfig networking.hostId = "8425e349"; # from profiles/base.nix, needed for zfs
]; boot.zfs.devNodes = "/dev/disk/by-uuid"; # needed because /dev/disk/by-id is empty in qemu-vms
fileSystems."/nix/store" = { boot.initrd.preDeviceCommands = ''
device = "nix-store"; echo -n 'secretsecret' > /tmp/secret.key
fsType = "9p"; '';
neededForBoot = true;
options = [ "trans=virtio" "version=9p2000.L" "cache=loose" ];
};
documentation.enable = false;
hardware.enableAllFirmware = lib.mkForce false;
networking.hostId = "8425e349"; # from profiles/base.nix, needed for zfs
boot.zfs.devNodes = "/dev/disk/by-uuid"; # needed because /dev/disk/by-id is empty in qemu-vms
boot.initrd.preDeviceCommands = ''
echo -n 'secretsecret' > /tmp/secret.key
'';
boot.consoleLogLevel = lib.mkForce 100; boot.consoleLogLevel = lib.mkForce 100;
boot.loader.grub = { boot.loader.grub = {
devices = grub-devices; devices = grub-devices;
efiSupport = efi; efiSupport = efi;
efiInstallAsRemovable = efi; efiInstallAsRemovable = efi;
}; };
}
]) ++ [
(modulesPath + "/testing/test-instrumentation.nix") # we need these 2 modules always to be able to run the tests
(modulesPath + "/profiles/qemu-guest.nix")
extraSystemConfig
];
}; };
installed-system-eval = eval-config { installed-system-eval = eval-config {
modules = [ installed-system ]; modules = [ installed-system ];
@ -128,7 +136,7 @@ let
}) })
(modulesPath + "/profiles/base.nix") (modulesPath + "/profiles/base.nix")
(modulesPath + "/profiles/minimal.nix") (modulesPath + "/profiles/minimal.nix")
extraConfig extraInstallerConfig
]; ];
environment.systemPackages = [ environment.systemPackages = [
pkgs.jq pkgs.jq

View File

@ -10,7 +10,7 @@ makeDiskoTest {
machine.succeed("lsblk >&2"); machine.succeed("lsblk >&2");
''; '';
# so that the installer boots with a bcachefs enabled kernel # so that the installer boots with a bcachefs enabled kernel
extraConfig = { extraInstallerConfig = {
boot.supportedFilesystems = [ "bcachefs" ]; boot.supportedFilesystems = [ "bcachefs" ];
# disable zfs so we can support latest kernel # disable zfs so we can support latest kernel
nixpkgs.overlays = [ nixpkgs.overlays = [

View File

@ -5,7 +5,7 @@ makeDiskoTest {
inherit pkgs; inherit pkgs;
name = "cli"; name = "cli";
disko-config = ../example/complex.nix; disko-config = ../example/complex.nix;
extraConfig = { extraSystemConfig = {
fileSystems."/zfs_legacy_fs".options = [ "nofail" ]; # TODO find out why we need this! fileSystems."/zfs_legacy_fs".options = [ "nofail" ]; # TODO find out why we need this!
}; };
testMode = "cli"; testMode = "cli";
@ -19,7 +19,7 @@ makeDiskoTest {
machine.succeed("mountpoint /ext4onzfs"); machine.succeed("mountpoint /ext4onzfs");
machine.succeed("mountpoint /ext4_on_lvm"); machine.succeed("mountpoint /ext4_on_lvm");
''; '';
extraConfig = { extraInstallerConfig = {
boot.kernelModules = [ "dm-raid" "dm-mirror" ]; boot.kernelModules = [ "dm-raid" "dm-mirror" ];
}; };
} }

View File

@ -5,7 +5,7 @@ makeDiskoTest {
inherit pkgs; inherit pkgs;
name = "complex"; name = "complex";
disko-config = ../example/complex.nix; disko-config = ../example/complex.nix;
extraConfig = { extraSystemConfig = {
fileSystems."/zfs_legacy_fs".options = [ "nofail" ]; # TODO find out why we need this! fileSystems."/zfs_legacy_fs".options = [ "nofail" ]; # TODO find out why we need this!
}; };
extraTestScript = '' extraTestScript = ''
@ -18,7 +18,7 @@ makeDiskoTest {
machine.succeed("mountpoint /ext4onzfs"); machine.succeed("mountpoint /ext4onzfs");
machine.succeed("mountpoint /ext4_on_lvm"); machine.succeed("mountpoint /ext4_on_lvm");
''; '';
extraConfig = { extraInstallerConfig = {
boot.kernelModules = [ "dm-raid" "dm-mirror" ]; boot.kernelModules = [ "dm-raid" "dm-mirror" ];
}; };
} }

View File

@ -10,7 +10,7 @@ let
allTestFilenames = allTestFilenames =
builtins.map (lib.removeSuffix ".nix") ( builtins.map (lib.removeSuffix ".nix") (
builtins.filter builtins.filter
(x: lib.hasSuffix ".nix" x && x != "default.nix" && x != "lib.nix") (x: lib.hasSuffix ".nix" x && x != "default.nix")
(lib.attrNames (builtins.readDir ./.)) (lib.attrNames (builtins.readDir ./.))
); );

View File

@ -5,7 +5,6 @@ makeDiskoTest {
inherit pkgs; inherit pkgs;
name = "luks-lvm"; name = "luks-lvm";
disko-config = ../example/luks-lvm.nix; disko-config = ../example/luks-lvm.nix;
extraConfig.boot.initrd.luks.devices.crypted.preLVM = false;
extraTestScript = '' extraTestScript = ''
machine.succeed("cryptsetup isLuks /dev/vda2"); machine.succeed("cryptsetup isLuks /dev/vda2");
machine.succeed("mountpoint /home"); machine.succeed("mountpoint /home");

View File

@ -8,7 +8,7 @@ makeDiskoTest {
extraTestScript = '' extraTestScript = ''
machine.succeed("mountpoint /home"); machine.succeed("mountpoint /home");
''; '';
extraConfig = { extraInstallerConfig = {
boot.kernelModules = [ "dm-raid0" "dm-mirror" ]; boot.kernelModules = [ "dm-raid0" "dm-mirror" ];
}; };
} }

View File

@ -5,7 +5,7 @@ makeDiskoTest {
inherit pkgs; inherit pkgs;
name = "module"; name = "module";
disko-config = ../example/complex.nix; disko-config = ../example/complex.nix;
extraConfig = { extraSystemConfig = {
fileSystems."/zfs_legacy_fs".options = [ "nofail" ]; # TODO find out why we need this! fileSystems."/zfs_legacy_fs".options = [ "nofail" ]; # TODO find out why we need this!
}; };
testMode = "module"; testMode = "module";
@ -19,7 +19,7 @@ makeDiskoTest {
machine.succeed("mountpoint /ext4onzfs"); machine.succeed("mountpoint /ext4onzfs");
machine.succeed("mountpoint /ext4_on_lvm"); machine.succeed("mountpoint /ext4_on_lvm");
''; '';
extraConfig = { extraInstallerConfig = {
boot.kernelModules = [ "dm-raid" "dm-mirror" ]; boot.kernelModules = [ "dm-raid" "dm-mirror" ];
}; };
} }

View File

@ -18,7 +18,7 @@ makeDiskoTest {
' '
"""); """);
''; '';
extraConfig = { extraSystemConfig = {
environment.systemPackages = [ pkgs.jq ]; environment.systemPackages = [ pkgs.jq ];
}; };
} }

View File

@ -5,9 +5,8 @@ makeDiskoTest {
inherit pkgs; inherit pkgs;
name = "zfs"; name = "zfs";
disko-config = ../example/zfs.nix; disko-config = ../example/zfs.nix;
extraConfig = { extraSystemConfig = {
fileSystems."/zfs_legacy_fs".options = [ "nofail" ]; # TODO find out why we need this! fileSystems."/zfs_legacy_fs".options = [ "nofail" ]; # TODO find out why we need this!
boot.zfs.requestEncryptionCredentials = true;
}; };
extraTestScript = '' extraTestScript = ''
machine.succeed("test -b /dev/zvol/zroot/zfs_testvolume"); machine.succeed("test -b /dev/zvol/zroot/zfs_testvolume");