From 715c211dd7797f9ede770e38105697e34dbd0e2f Mon Sep 17 00:00:00 2001 From: lassulus Date: Sat, 15 Jul 2023 16:57:18 +0200 Subject: [PATCH] testLib.makeDiskoTest: split extraConfig into nixos-config, extraSystemConfig & extraInstallerConfig --- lib/tests.nix | 62 ++++++++++++++++++++++++++-------------------- tests/bcachefs.nix | 2 +- tests/cli.nix | 4 +-- tests/complex.nix | 4 +-- tests/default.nix | 2 +- tests/luks-lvm.nix | 1 - tests/lvm-raid.nix | 2 +- tests/module.nix | 4 +-- tests/swap.nix | 2 +- tests/zfs.nix | 3 +-- 10 files changed, 46 insertions(+), 40 deletions(-) diff --git a/lib/tests.nix b/lib/tests.nix index c08f933..b6020a3 100644 --- a/lib/tests.nix +++ b/lib/tests.nix @@ -32,10 +32,12 @@ let makeDiskoTest = { name , disko-config + , nixos-config ? null , pkgs ? import { } , extraTestScript ? "" , bootCommands ? "" - , extraConfig ? { } + , extraInstallerConfig ? { } + , extraSystemConfig ? { } , grub-devices ? [ "nodev" ] , efi ? true , postDisko ? "" @@ -62,7 +64,17 @@ let tsp-config = tsp-generator.config testConfigBooted; num-disks = builtins.length (lib.attrNames testConfigBooted.disko.devices.disk); 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 == "module") { disko.enableConfig = true; @@ -71,31 +83,27 @@ let testConfigBooted ]; }) - (modulesPath + "/testing/test-instrumentation.nix") - (modulesPath + "/profiles/qemu-guest.nix") - (modulesPath + "/profiles/minimal.nix") - extraConfig - ]; - fileSystems."/nix/store" = { - device = "nix-store"; - 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 - ''; + { # config for tests to make them run faster or work at all + 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.loader.grub = { - devices = grub-devices; - efiSupport = efi; - efiInstallAsRemovable = efi; - }; + boot.consoleLogLevel = lib.mkForce 100; + boot.loader.grub = { + devices = grub-devices; + efiSupport = 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 { modules = [ installed-system ]; @@ -128,7 +136,7 @@ let }) (modulesPath + "/profiles/base.nix") (modulesPath + "/profiles/minimal.nix") - extraConfig + extraInstallerConfig ]; environment.systemPackages = [ pkgs.jq diff --git a/tests/bcachefs.nix b/tests/bcachefs.nix index 6624882..ad2ef51 100644 --- a/tests/bcachefs.nix +++ b/tests/bcachefs.nix @@ -10,7 +10,7 @@ makeDiskoTest { machine.succeed("lsblk >&2"); ''; # so that the installer boots with a bcachefs enabled kernel - extraConfig = { + extraInstallerConfig = { boot.supportedFilesystems = [ "bcachefs" ]; # disable zfs so we can support latest kernel nixpkgs.overlays = [ diff --git a/tests/cli.nix b/tests/cli.nix index ac9dbd3..23cead8 100644 --- a/tests/cli.nix +++ b/tests/cli.nix @@ -5,7 +5,7 @@ makeDiskoTest { inherit pkgs; name = "cli"; disko-config = ../example/complex.nix; - extraConfig = { + extraSystemConfig = { fileSystems."/zfs_legacy_fs".options = [ "nofail" ]; # TODO find out why we need this! }; testMode = "cli"; @@ -19,7 +19,7 @@ makeDiskoTest { machine.succeed("mountpoint /ext4onzfs"); machine.succeed("mountpoint /ext4_on_lvm"); ''; - extraConfig = { + extraInstallerConfig = { boot.kernelModules = [ "dm-raid" "dm-mirror" ]; }; } diff --git a/tests/complex.nix b/tests/complex.nix index 9ffe8e3..233364f 100644 --- a/tests/complex.nix +++ b/tests/complex.nix @@ -5,7 +5,7 @@ makeDiskoTest { inherit pkgs; name = "complex"; disko-config = ../example/complex.nix; - extraConfig = { + extraSystemConfig = { fileSystems."/zfs_legacy_fs".options = [ "nofail" ]; # TODO find out why we need this! }; extraTestScript = '' @@ -18,7 +18,7 @@ makeDiskoTest { machine.succeed("mountpoint /ext4onzfs"); machine.succeed("mountpoint /ext4_on_lvm"); ''; - extraConfig = { + extraInstallerConfig = { boot.kernelModules = [ "dm-raid" "dm-mirror" ]; }; } diff --git a/tests/default.nix b/tests/default.nix index 84c37a9..ce18c87 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -10,7 +10,7 @@ let allTestFilenames = builtins.map (lib.removeSuffix ".nix") ( 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 ./.)) ); diff --git a/tests/luks-lvm.nix b/tests/luks-lvm.nix index 69d13d1..5dc713c 100644 --- a/tests/luks-lvm.nix +++ b/tests/luks-lvm.nix @@ -5,7 +5,6 @@ makeDiskoTest { inherit pkgs; name = "luks-lvm"; disko-config = ../example/luks-lvm.nix; - extraConfig.boot.initrd.luks.devices.crypted.preLVM = false; extraTestScript = '' machine.succeed("cryptsetup isLuks /dev/vda2"); machine.succeed("mountpoint /home"); diff --git a/tests/lvm-raid.nix b/tests/lvm-raid.nix index 5acdc2c..74a8a4f 100644 --- a/tests/lvm-raid.nix +++ b/tests/lvm-raid.nix @@ -8,7 +8,7 @@ makeDiskoTest { extraTestScript = '' machine.succeed("mountpoint /home"); ''; - extraConfig = { + extraInstallerConfig = { boot.kernelModules = [ "dm-raid0" "dm-mirror" ]; }; } diff --git a/tests/module.nix b/tests/module.nix index faf25f7..3e48fc9 100644 --- a/tests/module.nix +++ b/tests/module.nix @@ -5,7 +5,7 @@ makeDiskoTest { inherit pkgs; name = "module"; disko-config = ../example/complex.nix; - extraConfig = { + extraSystemConfig = { fileSystems."/zfs_legacy_fs".options = [ "nofail" ]; # TODO find out why we need this! }; testMode = "module"; @@ -19,7 +19,7 @@ makeDiskoTest { machine.succeed("mountpoint /ext4onzfs"); machine.succeed("mountpoint /ext4_on_lvm"); ''; - extraConfig = { + extraInstallerConfig = { boot.kernelModules = [ "dm-raid" "dm-mirror" ]; }; } diff --git a/tests/swap.nix b/tests/swap.nix index f3284ae..c4faa9e 100644 --- a/tests/swap.nix +++ b/tests/swap.nix @@ -18,7 +18,7 @@ makeDiskoTest { ' """); ''; - extraConfig = { + extraSystemConfig = { environment.systemPackages = [ pkgs.jq ]; }; } diff --git a/tests/zfs.nix b/tests/zfs.nix index f9a206c..9a40083 100644 --- a/tests/zfs.nix +++ b/tests/zfs.nix @@ -5,9 +5,8 @@ makeDiskoTest { inherit pkgs; name = "zfs"; disko-config = ../example/zfs.nix; - extraConfig = { + extraSystemConfig = { fileSystems."/zfs_legacy_fs".options = [ "nofail" ]; # TODO find out why we need this! - boot.zfs.requestEncryptionCredentials = true; }; extraTestScript = '' machine.succeed("test -b /dev/zvol/zroot/zfs_testvolume");