From e38823931182caa243a12ebeda21f89f919cb31e Mon Sep 17 00:00:00 2001 From: lassulus Date: Thu, 20 Jul 2023 18:03:59 +0200 Subject: [PATCH 01/16] example zfs: add ESP type --- example/zfs.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/example/zfs.nix b/example/zfs.nix index 0d34667..8e85c96 100644 --- a/example/zfs.nix +++ b/example/zfs.nix @@ -9,6 +9,7 @@ partitions = { ESP = { size = "64M"; + type = "EF00"; content = { type = "filesystem"; format = "vfat"; From 260c0023db1e20ec426e9cfc73ab12e79add3fdf Mon Sep 17 00:00:00 2001 From: lassulus Date: Thu, 20 Jul 2023 18:04:41 +0200 Subject: [PATCH 02/16] types gpt: set grub.devices automatically --- lib/types/gpt.nix | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/types/gpt.nix b/lib/types/gpt.nix index fed2f01..35ca347 100644 --- a/lib/types/gpt.nix +++ b/lib/types/gpt.nix @@ -129,11 +129,14 @@ in _config = lib.mkOption { internal = true; readOnly = true; - default = map + default = (map (partition: lib.optional (partition.content != null) partition.content._config ) - (lib.attrValues config.partitions); + (lib.attrValues config.partitions)) + ++ (lib.optional (lib.any (part: part.type == "EF02") (lib.attrValues config.partitions)) { + boot.loader.grub.devices = [ config.device ]; + }); description = "NixOS configuration"; }; _pkgs = lib.mkOption { From 97b09a791fd56ddd5fd21217ed84cc1753f04409 Mon Sep 17 00:00:00 2001 From: lassulus Date: Thu, 20 Jul 2023 18:05:23 +0200 Subject: [PATCH 03/16] lib toplevel._scripts: set mountScriptNoDeps in correct namespace --- lib/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/default.nix b/lib/default.nix index 1377c8b..9a01a2f 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -407,7 +407,7 @@ let ${cfg.config._create} ''; - system.build.mountScriptNoDeps = (diskoLib.writeCheckedBash { inherit pkgs checked; noDeps = true; }) "disko-mount" '' + mountScriptNoDeps = (diskoLib.writeCheckedBash { inherit pkgs checked; noDeps = true; }) "disko-mount" '' ${cfg.config._mount} ''; From 815d018e2f1f9707beee70731fb097c4046fb15e Mon Sep 17 00:00:00 2001 From: lassulus Date: Thu, 20 Jul 2023 18:30:55 +0200 Subject: [PATCH 04/16] lib makeDiskoTest: allow passing of extendModules --- lib/tests.nix | 110 +++++++++++++++++++++++++++++++------------------- 1 file changed, 68 insertions(+), 42 deletions(-) diff --git a/lib/tests.nix b/lib/tests.nix index e029dbd..a84fa25 100644 --- a/lib/tests.nix +++ b/lib/tests.nix @@ -10,21 +10,27 @@ let # basically changes all the disk.*.devices to something like /dev/vda or /dev/vdb etc. prepareDiskoConfig = toplevel: devices: let + cleanedTopLevel = lib.filterAttrsRecursive (n: _: !lib.hasPrefix "_" n) toplevel; + preparedDisks = lib.foldlAttrs (acc: n: v: { devices = lib.tail acc.devices; - value = acc.value // { - ${n} = v // { + grub-devices = acc.grub-devices ++ (lib.optional (lib.any (part: (part.type or "") == "EF02") (lib.attrValues (v.content.partitions or {}))) (lib.head acc.devices)); + disks = acc.disks // { + "${n}" = v // { device = lib.head acc.devices; + content = v.content // { device = lib.head acc.devices; }; }; }; }) { inherit devices; - value = {}; - } toplevel.disko.devices.disk; + grub-devices = []; + disks = {}; + } cleanedTopLevel.disko.devices.disk; in - toplevel // { - disko.devices = toplevel.disko.devices // { - disk = preparedDisks.value; + cleanedTopLevel // { + boot.loader.grub.devices = preparedDisks.grub-devices; + disko.devices = cleanedTopLevel.disko.devices // { + disk = preparedDisks.disks; }; }; @@ -32,7 +38,7 @@ let makeDiskoTest = { name , disko-config - , nixos-config ? null + , extendModules ? null , pkgs ? import { } , extraTestScript ? "" , bootCommands ? "" @@ -50,9 +56,14 @@ let inherit pkgs; inherit (pkgs) system; }; - devices = [ "/dev/vda" "/dev/vdb" "/dev/vdc" "/dev/vdd" "/dev/vde" "/dev/vdf"]; # for installation we skip /dev/vda because it is the test runner disk - importedDiskoConfig = import disko-config; + devices = [ "/dev/vda" "/dev/vdb" "/dev/vdc" "/dev/vdd" "/dev/vde" "/dev/vdf"]; + + importedDiskoConfig = if builtins.isPath disko-config then + import disko-config + else + disko-config; + diskoConfigWithArgs = if builtins.isFunction importedDiskoConfig then importedDiskoConfig { inherit lib; } else @@ -68,18 +79,9 @@ let tsp-disko = (tsp-generator.diskoScript testConfigInstall) pkgs; tsp-config = tsp-generator.config testConfigBooted; num-disks = builtins.length (lib.attrNames testConfigBooted.disko.devices.disk); - installed-system = { modulesPath, ... }: { - # 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 [ + installed-system = { modulesPath, ... }: { + imports = [ (lib.optionalAttrs (testMode == "direct" || testMode == "cli") tsp-config) (lib.optionalAttrs (testMode == "module") { disko.enableConfig = true; @@ -88,34 +90,54 @@ let testConfigBooted ]; }) - { # 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; - }; - } - ]) ++ [ - (modulesPath + "/testing/test-instrumentation.nix") # we need these 2 modules always to be able to run the tests - (modulesPath + "/profiles/qemu-guest.nix") - extraSystemConfig ]; + + # 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.initrd.preDeviceCommands = '' + echo -n 'secretsecret' > /tmp/secret.key + ''; + boot.consoleLogLevel = lib.mkForce 100; }; installed-system-eval = eval-config { modules = [ installed-system ]; inherit (pkgs) system; }; - installedTopLevel = installed-system-eval.config.system.build.toplevel; + installedTopLevel = ((if extendModules != null then extendModules else installed-system-eval.extendModules) { + modules = [{ + imports = [ + extraSystemConfig + ({ modulesPath, ... }: { + imports = [ + (modulesPath + "/testing/test-instrumentation.nix") # we need these 2 modules always to be able to run the tests + (modulesPath + "/profiles/qemu-guest.nix") + ]; + disko.devices = lib.mkForce testConfigBooted.disko.devices; + }) + ]; + + # since we boot on a different machine, the efi payload needs to be portable + boot.loader.grub.efiInstallAsRemovable = efi; + boot.loader.grub.efiSupport = efi; + boot.loader.systemd-boot.graceful = true; + + # 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" ]; + }; + boot.zfs.devNodes = "/dev/disk/by-uuid"; # needed because /dev/disk/by-id is empty in qemu-vms + + # grub will install to these devices, we need to force those or we are offset by 1 + boot.loader.grub.devices = lib.mkForce testConfigInstall.boot.loader.grub.devices; + }]; + }).config.system.build.toplevel; + in makeTest' { name = "disko-${name}"; @@ -156,6 +178,8 @@ let connect-timeout = 1; }; + networking.hostId = lib.mkIf (testConfigInstall ? networking.hostId) testConfigInstall.networking.hostId; + virtualisation.emptyDiskImages = builtins.genList (_: 4096) num-disks; # useful for debugging via repl @@ -181,12 +205,14 @@ let machine.succeed("echo -n 'additionalSecret' > /tmp/additionalSecret.key") machine.succeed("echo -n 'secretsecret' > /tmp/secret.key") ${lib.optionalString (testMode == "direct") '' + # running direct mode machine.succeed("${tsp-create}") machine.succeed("${tsp-mount}") machine.succeed("${tsp-mount}") # verify that the command is idempotent machine.succeed("${tsp-disko}") # verify that we can destroy and recreate ''} ${lib.optionalString (testMode == "module") '' + # running module mode machine.succeed("${nodes.machine.system.build.formatScript}") machine.succeed("${nodes.machine.system.build.mountScript}") machine.succeed("${nodes.machine.system.build.mountScript}") # verify that the command is idempotent From fc98920ef5d554f09fdedf8deef977b7abd306a6 Mon Sep 17 00:00:00 2001 From: lassulus Date: Thu, 20 Jul 2023 18:31:17 +0200 Subject: [PATCH 05/16] lib makeDiskoTest: use systemd-boot if efi is enabled --- lib/tests.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/tests.nix b/lib/tests.nix index a84fa25..09d3316 100644 --- a/lib/tests.nix +++ b/lib/tests.nix @@ -100,7 +100,9 @@ let echo -n 'secretsecret' > /tmp/secret.key ''; boot.consoleLogLevel = lib.mkForce 100; + boot.loader.systemd-boot.enable = lib.mkDefault efi; }; + installed-system-eval = eval-config { modules = [ installed-system ]; inherit (pkgs) system; From 4df1400b383e00025471681eb0026ef073188a03 Mon Sep 17 00:00:00 2001 From: lassulus Date: Thu, 20 Jul 2023 18:31:53 +0200 Subject: [PATCH 06/16] makeDiskoTest: remove deprecated grub-devices --- lib/tests.nix | 1 - tests/gpt-bios-compat.nix | 1 - tests/mdadm.nix | 1 - tests/with-lib.nix | 1 - 4 files changed, 4 deletions(-) diff --git a/lib/tests.nix b/lib/tests.nix index 09d3316..da2760c 100644 --- a/lib/tests.nix +++ b/lib/tests.nix @@ -44,7 +44,6 @@ let , bootCommands ? "" , extraInstallerConfig ? { } , extraSystemConfig ? { } - , grub-devices ? [ "nodev" ] , efi ? true , postDisko ? "" , testMode ? "module" # can be one of direct module cli diff --git a/tests/gpt-bios-compat.nix b/tests/gpt-bios-compat.nix index a5b4bf9..97c41cb 100644 --- a/tests/gpt-bios-compat.nix +++ b/tests/gpt-bios-compat.nix @@ -9,5 +9,4 @@ makeDiskoTest { machine.succeed("mountpoint /"); ''; efi = false; - grub-devices = [ "/dev/vdb" ]; } diff --git a/tests/mdadm.nix b/tests/mdadm.nix index 4bb8f3d..1c61350 100644 --- a/tests/mdadm.nix +++ b/tests/mdadm.nix @@ -10,5 +10,4 @@ makeDiskoTest { machine.succeed("mountpoint /"); ''; efi = false; - grub-devices = [ "/dev/vdb" "/dev/vdc" ]; } diff --git a/tests/with-lib.nix b/tests/with-lib.nix index 6245794..551f2b7 100644 --- a/tests/with-lib.nix +++ b/tests/with-lib.nix @@ -9,5 +9,4 @@ makeDiskoTest { machine.succeed("mountpoint /"); ''; efi = false; - grub-devices = [ "/dev/vdb" ]; } From bfc300b1c2138d4abaa87971f85d1fe5f4187f3e Mon Sep 17 00:00:00 2001 From: lassulus Date: Thu, 20 Jul 2023 18:32:21 +0200 Subject: [PATCH 07/16] tests boot-raid1: use grub as systemd-boot is broken with raid1 /boot --- tests/boot-raid1.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/boot-raid1.nix b/tests/boot-raid1.nix index 2d76a7d..7dafd51 100644 --- a/tests/boot-raid1.nix +++ b/tests/boot-raid1.nix @@ -9,4 +9,8 @@ makeDiskoTest { machine.succeed("test -b /dev/md/boot"); machine.succeed("mountpoint /boot"); ''; + extraSystemConfig = { + # sadly systemd-boot fails to install to a raid /boot device + boot.loader.systemd-boot.enable = false; + }; } From 4cad47f3fad2767458d9d5ebaabec544d508bdca Mon Sep 17 00:00:00 2001 From: lassulus Date: Thu, 20 Jul 2023 18:32:47 +0200 Subject: [PATCH 08/16] module: expose diskoTest via system.build --- module.nix | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/module.nix b/module.nix index ccece50..b6815d2 100644 --- a/module.nix +++ b/module.nix @@ -1,4 +1,4 @@ -{ config, lib, pkgs, ... }: +{ config, lib, pkgs, extendModules, ... }@args: let diskoLib = import ./lib { inherit lib; @@ -34,6 +34,16 @@ in type = lib.types.bool; default = false; }; + tests = { + efi = lib.mkOption { + description = '' + Whether efi is enabled for the `system.build.installTest`. + We try to automatically detect efi based on the configured bootloader. + ''; + type = lib.types.bool; + default = config.boot.loader.systemd-boot.enable || config.boot.loader.grub.efiSupport; + }; + }; }; config = lib.mkIf (cfg.devices.disk != { }) { system.build = (cfg.devices._scripts { inherit pkgs; checked = cfg.checkScripts; }) // { @@ -41,6 +51,14 @@ in # we keep this old outputs for compatibility disko = builtins.trace "the .disko output is deprecated, plase use .diskoScript instead" cfg.devices._scripts.diskoScript; diskoNoDeps = builtins.trace "the .diskoNoDeps output is deprecated, plase use .diskoScriptNoDeps instead" cfg.devices._scripts.diskoScriptNoDeps; + + installTest = diskoLib.testLib.makeDiskoTest { + inherit extendModules pkgs; + name = "${config.networking.hostName}-disko"; + disko-config = builtins.removeAttrs config ["_module"]; + testMode = "direct"; + efi = cfg.tests.efi; + }; }; From 4fa29318f61952358b0645518518eace0ee8b3df Mon Sep 17 00:00:00 2001 From: lassulus Date: Thu, 20 Jul 2023 18:41:35 +0200 Subject: [PATCH 09/16] examples: set EF00 partition types --- example/btrfs-subvolumes.nix | 1 + example/complex.nix | 1 + example/hybrid-tmpfs-on-root.nix | 1 + example/hybrid.nix | 1 + example/luks-lvm.nix | 1 + example/lvm-raid.nix | 2 ++ example/lvm-sizes-sort.nix | 1 + example/swap.nix | 1 + example/tmpfs.nix | 1 + example/zfs-over-legacy.nix | 1 + 10 files changed, 11 insertions(+) diff --git a/example/btrfs-subvolumes.nix b/example/btrfs-subvolumes.nix index 877cf12..72af6f4 100644 --- a/example/btrfs-subvolumes.nix +++ b/example/btrfs-subvolumes.nix @@ -12,6 +12,7 @@ name = "ESP"; start = "1M"; end = "128MiB"; + type = "EF00"; content = { type = "filesystem"; format = "vfat"; diff --git a/example/complex.nix b/example/complex.nix index 4a6f35f..a73389f 100644 --- a/example/complex.nix +++ b/example/complex.nix @@ -10,6 +10,7 @@ ESP = { start = "1MiB"; end = "128MiB"; + type = "EF00"; content = { type = "filesystem"; format = "vfat"; diff --git a/example/hybrid-tmpfs-on-root.nix b/example/hybrid-tmpfs-on-root.nix index 46a1c76..61a76e4 100644 --- a/example/hybrid-tmpfs-on-root.nix +++ b/example/hybrid-tmpfs-on-root.nix @@ -13,6 +13,7 @@ ESP = { name = "ESP"; size = "512M"; + type = "EF00"; content = { type = "filesystem"; format = "vfat"; diff --git a/example/hybrid.nix b/example/hybrid.nix index 5f97fa9..61762cc 100644 --- a/example/hybrid.nix +++ b/example/hybrid.nix @@ -13,6 +13,7 @@ }; ESP = { size = "512M"; + type = "EF00"; content = { type = "filesystem"; format = "vfat"; diff --git a/example/luks-lvm.nix b/example/luks-lvm.nix index 48d3c84..c1b76c5 100644 --- a/example/luks-lvm.nix +++ b/example/luks-lvm.nix @@ -9,6 +9,7 @@ partitions = { ESP = { size = "100M"; + type = "EF00"; content = { type = "filesystem"; format = "vfat"; diff --git a/example/lvm-raid.nix b/example/lvm-raid.nix index b26b24c..e0a6287 100644 --- a/example/lvm-raid.nix +++ b/example/lvm-raid.nix @@ -9,6 +9,7 @@ partitions = { boot = { size = "100M"; + type = "EF00"; content = { type = "mdraid"; name = "boot"; @@ -33,6 +34,7 @@ boot = { name = "boot"; size = "100M"; + type = "EF00"; content = { type = "mdraid"; name = "boot"; diff --git a/example/lvm-sizes-sort.nix b/example/lvm-sizes-sort.nix index a088adc..623be42 100644 --- a/example/lvm-sizes-sort.nix +++ b/example/lvm-sizes-sort.nix @@ -9,6 +9,7 @@ partitions = { boot = { size = "100M"; + type = "EF00"; content = { type = "filesystem"; format = "vfat"; diff --git a/example/swap.nix b/example/swap.nix index fdfbe6f..cf8aa6c 100644 --- a/example/swap.nix +++ b/example/swap.nix @@ -9,6 +9,7 @@ partitions = { ESP = { size = "100M"; + type = "EF00"; content = { type = "filesystem"; format = "vfat"; diff --git a/example/tmpfs.nix b/example/tmpfs.nix index afda544..72508e8 100644 --- a/example/tmpfs.nix +++ b/example/tmpfs.nix @@ -9,6 +9,7 @@ partitions = { ESP = { size = "100M"; + type = "EF00"; content = { type = "filesystem"; format = "vfat"; diff --git a/example/zfs-over-legacy.nix b/example/zfs-over-legacy.nix index e91b1b7..8dc77f3 100644 --- a/example/zfs-over-legacy.nix +++ b/example/zfs-over-legacy.nix @@ -9,6 +9,7 @@ partitions = { ESP = { size = "100M"; + type = "EF00"; content = { type = "filesystem"; format = "vfat"; From 7e2a3475f0cd06b2cd13d92ea8e070916395725a Mon Sep 17 00:00:00 2001 From: lassulus Date: Thu, 20 Jul 2023 18:43:06 +0200 Subject: [PATCH 10/16] tests lvm-raid: use grub as systemd-boot is broken with raid1 /boot --- tests/lvm-raid.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/lvm-raid.nix b/tests/lvm-raid.nix index 74a8a4f..1b8cb02 100644 --- a/tests/lvm-raid.nix +++ b/tests/lvm-raid.nix @@ -11,4 +11,8 @@ makeDiskoTest { extraInstallerConfig = { boot.kernelModules = [ "dm-raid0" "dm-mirror" ]; }; + extraSystemConfig = { + # sadly systemd-boot fails to install to a raid /boot device + boot.loader.systemd-boot.enable = false; + }; } From 2b728ffe029c7589346b87d93b2f1edc9ec4a153 Mon Sep 17 00:00:00 2001 From: lassulus Date: Thu, 20 Jul 2023 19:03:16 +0200 Subject: [PATCH 11/16] libTests prepareDisks: set grub.devices to nodev if empty --- lib/tests.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tests.nix b/lib/tests.nix index da2760c..2375b74 100644 --- a/lib/tests.nix +++ b/lib/tests.nix @@ -28,7 +28,7 @@ let } cleanedTopLevel.disko.devices.disk; in cleanedTopLevel // { - boot.loader.grub.devices = preparedDisks.grub-devices; + boot.loader.grub.devices = if (preparedDisks.grub-devices != []) then preparedDisks.grub-devices else [ "nodev" ]; disko.devices = cleanedTopLevel.disko.devices // { disk = preparedDisks.disks; }; From 2800cf502a87f548bb624bc46f0b0b23985aa7af Mon Sep 17 00:00:00 2001 From: lassulus Date: Thu, 20 Jul 2023 19:17:11 +0200 Subject: [PATCH 12/16] tests cli: use direct mode --- lib/tests.nix | 22 ++-------------------- tests/cli.nix | 10 +++++++++- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/lib/tests.nix b/lib/tests.nix index 2375b74..fefffe4 100644 --- a/lib/tests.nix +++ b/lib/tests.nix @@ -46,7 +46,7 @@ let , extraSystemConfig ? { } , efi ? true , postDisko ? "" - , testMode ? "module" # can be one of direct module cli + , testMode ? "module" # can be direct or module , testBoot ? true # if we actually want to test booting or just create/mount }: let @@ -81,7 +81,7 @@ let installed-system = { modulesPath, ... }: { imports = [ - (lib.optionalAttrs (testMode == "direct" || testMode == "cli") tsp-config) + (lib.optionalAttrs (testMode == "direct") tsp-config) (lib.optionalAttrs (testMode == "module") { disko.enableConfig = true; imports = [ @@ -155,13 +155,6 @@ let devices = testConfigInstall.disko.devices; }; }) - (lib.optionalAttrs (testMode == "cli") { - imports = [ (modulesPath + "/installer/cd-dvd/channel.nix") ]; - system.extraDependencies = [ - ((pkgs.callPackage ../. { checked = true; }).createScript testConfigInstall pkgs) - ((pkgs.callPackage ../. { checked = true; }).mountScript testConfigInstall pkgs) - ]; - }) (modulesPath + "/profiles/base.nix") (modulesPath + "/profiles/minimal.nix") extraInstallerConfig @@ -219,17 +212,6 @@ let machine.succeed("${nodes.machine.system.build.mountScript}") # verify that the command is idempotent machine.succeed("${nodes.machine.system.build.diskoScript}") # verify that we can destroy and recreate again ''} - ${lib.optionalString (testMode == "cli") '' - # TODO use the disko cli here - # machine.succeed("${../.}/disko --no-pkgs --mode create ${disko-config}") - # machine.succeed("${../.}/disko --no-pkgs --mode mount ${disko-config}") - # machine.succeed("${../.}/disko --no-pkgs --mode mount ${disko-config}") # verify that the command is idempotent - # machine.succeed("${../.}/disko --no-pkgs --mode zap_create_mount ${disko-config}") # verify that we can destroy and recreate again - machine.succeed("${tsp-create}") - machine.succeed("${tsp-mount}") - machine.succeed("${tsp-mount}") # verify that the command is idempotent - machine.succeed("${tsp-disko}") # verify that we can destroy and recreate - ''} ${postDisko} diff --git a/tests/cli.nix b/tests/cli.nix index 23cead8..4d6d136 100644 --- a/tests/cli.nix +++ b/tests/cli.nix @@ -8,7 +8,7 @@ makeDiskoTest { extraSystemConfig = { fileSystems."/zfs_legacy_fs".options = [ "nofail" ]; # TODO find out why we need this! }; - testMode = "cli"; + testMode = "direct"; extraTestScript = '' machine.succeed("test -b /dev/zroot/zfs_testvolume"); machine.succeed("test -b /dev/md/raid1p1"); @@ -19,7 +19,15 @@ makeDiskoTest { machine.succeed("mountpoint /ext4onzfs"); machine.succeed("mountpoint /ext4_on_lvm"); ''; + extraSystemConfig = { + imports = [ + ../module.nix + ]; + }; extraInstallerConfig = { boot.kernelModules = [ "dm-raid" "dm-mirror" ]; + imports = [ + ../module.nix + ]; }; } From 1ddcff717c43167de66396166388d4653d306aa8 Mon Sep 17 00:00:00 2001 From: lassulus Date: Thu, 20 Jul 2023 21:32:53 +0200 Subject: [PATCH 13/16] module: pass makeTest and eval-config to diskoLib --- lib/tests.nix | 2 +- module.nix | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/tests.nix b/lib/tests.nix index fefffe4..ba40265 100644 --- a/lib/tests.nix +++ b/lib/tests.nix @@ -46,7 +46,7 @@ let , extraSystemConfig ? { } , efi ? true , postDisko ? "" - , testMode ? "module" # can be direct or module + , testMode ? "module" # can be one of direct module cli , testBoot ? true # if we actually want to test booting or just create/mount }: let diff --git a/module.nix b/module.nix index b6815d2..c2aa8f3 100644 --- a/module.nix +++ b/module.nix @@ -3,6 +3,8 @@ let diskoLib = import ./lib { inherit lib; rootMountPoint = config.disko.rootMountPoint; + makeTest = import (pkgs.path + "/nixos/tests/make-test-python.nix"); + eval-config = import (pkgs.path + "/nixos/lib/eval-config.nix"); }; cfg = config.disko; in From 737a21794cd05ab53dcca4b5b68c5c45ddcb3c41 Mon Sep 17 00:00:00 2001 From: lassulus Date: Thu, 20 Jul 2023 21:33:13 +0200 Subject: [PATCH 14/16] lib makeDiskoTest: set networking.hostId to non null value --- lib/tests.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/tests.nix b/lib/tests.nix index ba40265..959e389 100644 --- a/lib/tests.nix +++ b/lib/tests.nix @@ -172,7 +172,9 @@ let connect-timeout = 1; }; - networking.hostId = lib.mkIf (testConfigInstall ? networking.hostId) testConfigInstall.networking.hostId; + networking.hostId = lib.mkIf ( + (testConfigInstall ? networking.hostId) && (testConfigInstall.networking.hostId != null) + ) testConfigInstall.networking.hostId; virtualisation.emptyDiskImages = builtins.genList (_: 4096) num-disks; From 7a37b476348243f861c09213765282c370bc7980 Mon Sep 17 00:00:00 2001 From: lassulus Date: Fri, 21 Jul 2023 14:25:51 +0200 Subject: [PATCH 15/16] lib makeDiskoTest: create -> format --- lib/tests.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tests.nix b/lib/tests.nix index 959e389..f2edcbf 100644 --- a/lib/tests.nix +++ b/lib/tests.nix @@ -73,7 +73,7 @@ let testConfigBooted = testlib.prepareDiskoConfig diskoConfigWithArgs devices; tsp-generator = pkgs.callPackage ../. { checked = true; }; - tsp-create = (tsp-generator.createScript testConfigInstall) pkgs; + tsp-format = (tsp-generator.formatScript testConfigInstall) pkgs; tsp-mount = (tsp-generator.mountScript testConfigInstall) pkgs; tsp-disko = (tsp-generator.diskoScript testConfigInstall) pkgs; tsp-config = tsp-generator.config testConfigBooted; @@ -202,7 +202,7 @@ let machine.succeed("echo -n 'secretsecret' > /tmp/secret.key") ${lib.optionalString (testMode == "direct") '' # running direct mode - machine.succeed("${tsp-create}") + machine.succeed("${tsp-format}") machine.succeed("${tsp-mount}") machine.succeed("${tsp-mount}") # verify that the command is idempotent machine.succeed("${tsp-disko}") # verify that we can destroy and recreate From c3e4e625c19ca486f73bfb4df5dcd07f11e26099 Mon Sep 17 00:00:00 2001 From: lassulus Date: Fri, 21 Jul 2023 14:28:58 +0200 Subject: [PATCH 16/16] examples; document EF02 type --- example/boot-raid1.nix | 4 ++-- example/gpt-bios-compat.nix | 2 +- example/hybrid-tmpfs-on-root.nix | 2 +- example/hybrid.nix | 2 +- example/mdadm.nix | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/example/boot-raid1.nix b/example/boot-raid1.nix index 8fbe73b..89a108c 100644 --- a/example/boot-raid1.nix +++ b/example/boot-raid1.nix @@ -9,7 +9,7 @@ partitions = { boot = { size = "1M"; - type = "EF02"; + type = "EF02"; # for grub MBR }; ESP = { size = "100M"; @@ -37,7 +37,7 @@ partitions = { boot = { size = "1M"; - type = "EF02"; + type = "EF02"; # for grub MBR }; ESP = { size = "128M"; diff --git a/example/gpt-bios-compat.nix b/example/gpt-bios-compat.nix index 6ace866..f0e8f97 100644 --- a/example/gpt-bios-compat.nix +++ b/example/gpt-bios-compat.nix @@ -10,7 +10,7 @@ partitions = { boot = { size = "1M"; - type = "EF02"; + type = "EF02"; # for grub MBR }; root = { size = "100%"; diff --git a/example/hybrid-tmpfs-on-root.nix b/example/hybrid-tmpfs-on-root.nix index 61a76e4..308f7bf 100644 --- a/example/hybrid-tmpfs-on-root.nix +++ b/example/hybrid-tmpfs-on-root.nix @@ -8,7 +8,7 @@ partitions = { boot = { size = "1M"; - type = "EF02"; + type = "EF02"; # for grub MBR }; ESP = { name = "ESP"; diff --git a/example/hybrid.nix b/example/hybrid.nix index 61762cc..50176e0 100644 --- a/example/hybrid.nix +++ b/example/hybrid.nix @@ -9,7 +9,7 @@ partitions = { boot = { size = "1M"; - type = "EF02"; + type = "EF02"; # for grub MBR }; ESP = { size = "512M"; diff --git a/example/mdadm.nix b/example/mdadm.nix index 08178d2..33faac9 100644 --- a/example/mdadm.nix +++ b/example/mdadm.nix @@ -9,7 +9,7 @@ partitions = { boot = { size = "1M"; - type = "EF02"; + type = "EF02"; # for grub MBR }; mdadm = { size = "100%"; @@ -29,7 +29,7 @@ partitions = { boot = { size = "1M"; - type = "EF02"; + type = "EF02"; # for grub MBR }; mdadm = { size = "100%";