about summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorMatthias Berndt <matthias_berndt@gmx.de>2023-05-08 23:18:55 +0200
committerMatthias Berndt <matthias_berndt@gmx.de>2023-05-08 23:18:55 +0200
commit8aa320b4c2d0d7699170f6da154ebb7598e4d154 (patch)
tree031f7d4e9b2c34565027749271991b6d4a00f52b /nixos
parentd1411444b62e4d4c0d83dd8d7d44a4a45de1c51d (diff)
downloadnixlib-8aa320b4c2d0d7699170f6da154ebb7598e4d154.tar
nixlib-8aa320b4c2d0d7699170f6da154ebb7598e4d154.tar.gz
nixlib-8aa320b4c2d0d7699170f6da154ebb7598e4d154.tar.bz2
nixlib-8aa320b4c2d0d7699170f6da154ebb7598e4d154.tar.lz
nixlib-8aa320b4c2d0d7699170f6da154ebb7598e4d154.tar.xz
nixlib-8aa320b4c2d0d7699170f6da154ebb7598e4d154.tar.zst
nixlib-8aa320b4c2d0d7699170f6da154ebb7598e4d154.zip
address code review issues
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/module-list.nix1
-rw-r--r--nixos/modules/system/boot/stratisroot.nix9
-rw-r--r--nixos/tests/installer.nix59
3 files changed, 30 insertions, 39 deletions
diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix
index 0eb9631e6d42..4821b4033fdd 100644
--- a/nixos/modules/module-list.nix
+++ b/nixos/modules/module-list.nix
@@ -1331,6 +1331,7 @@
   ./system/boot/loader/raspberrypi/raspberrypi.nix
   ./system/boot/loader/systemd-boot/systemd-boot.nix
   ./system/boot/luksroot.nix
+  ./system/boot/stratisroot.nix
   ./system/boot/modprobe.nix
   ./system/boot/networkd.nix
   ./system/boot/plymouth.nix
diff --git a/nixos/modules/system/boot/stratisroot.nix b/nixos/modules/system/boot/stratisroot.nix
index a53d2c496306..53621008c338 100644
--- a/nixos/modules/system/boot/stratisroot.nix
+++ b/nixos/modules/system/boot/stratisroot.nix
@@ -5,18 +5,19 @@ in
 {
   options.boot.stratis = {
     rootPoolUuid = lib.mkOption {
-      type = types.uniq types.str;
-      description = lib.mdoc ''
+      type = types.uniq (types.nullOr types.str);
+      description = lib.mdDoc ''
         UUID of the stratis pool that the root fs is located in
       '';
       example = "04c68063-90a5-4235-b9dd-6180098a20d9";
+      default = null;
     };
   };
-  config = {
+  config = lib.mkIf (config.boot.stratis.rootPoolUuid != null) {
     assertions = [
       {
         assertion = config.boot.initrd.systemd.enable;
-        message = "stratis root fs requires systemd initrd";
+        message = "stratis root fs requires systemd stage 1";
       }
     ];
     boot.initrd = {
diff --git a/nixos/tests/installer.nix b/nixos/tests/installer.nix
index 5a58744d6209..1346eb36c36e 100644
--- a/nixos/tests/installer.nix
+++ b/nixos/tests/installer.nix
@@ -19,7 +19,6 @@ let
       { imports =
           [ ./hardware-configuration.nix
             <nixpkgs/nixos/modules/testing/test-instrumentation.nix>
-            ./amendments.nix
           ];
 
         documentation.enable = false;
@@ -73,7 +72,7 @@ let
   # partitions and filesystems.
   testScriptFun = { bootLoader, createPartitions, grubVersion, grubDevice, grubUseEfi
                   , grubIdentifier, preBootCommands, postBootCommands, extraConfig
-                  , testSpecialisationConfig, amendConfig
+                  , testSpecialisationConfig
                   }:
     let iface = if grubVersion == 1 then "ide" else "virtio";
         isEfi = bootLoader == "systemd-boot" || (bootLoader == "grub" && grubUseEfi);
@@ -130,9 +129,6 @@ let
               "/mnt/etc/nixos/configuration.nix",
           )
           machine.copy_from_host("${pkgs.writeText "secret" "secret"}", "/mnt/etc/nixos/secret")
-          amendments = '{}'
-          ${amendConfig}
-          machine.succeed(f"printf '{amendments}' > /mnt/etc/nixos/amendments.nix")
 
       with subtest("Perform the installation"):
           machine.succeed("nixos-install < /dev/null >&2")
@@ -285,7 +281,7 @@ let
 
 
   makeInstallerTest = name:
-    { createPartitions, preBootCommands ? "", postBootCommands ? "", extraConfig ? "", amendConfig ? ""
+    { createPartitions, preBootCommands ? "", postBootCommands ? "", extraConfig ? ""
     , extraInstallerConfig ? {}
     , bootLoader ? "grub" # either "grub" or "systemd-boot"
     , grubVersion ? 2, grubDevice ? "/dev/vda", grubIdentifier ? "uuid", grubUseEfi ? false
@@ -396,7 +392,7 @@ let
 
       testScript = testScriptFun {
         inherit bootLoader createPartitions preBootCommands postBootCommands
-                grubVersion grubDevice grubIdentifier grubUseEfi extraConfig amendConfig
+                grubVersion grubDevice grubIdentifier grubUseEfi extraConfig
                 testSpecialisationConfig;
       };
     };
@@ -1025,23 +1021,29 @@ in {
   stratisRoot = makeInstallerTest "stratisRoot" {
     createPartitions = ''
       machine.succeed(
-          "sgdisk --zap-all /dev/vda",
-          "sgdisk --new=1:0:+100M --typecode=0:ef00 /dev/vda", # /boot
-          "sgdisk --new=2:0:+1G --typecode=0:8200 /dev/vda", # swap
-          "sgdisk --new=3:0:+5G --typecode=0:8300 /dev/vda", # /
-          "udevadm settle",
+        "sgdisk --zap-all /dev/vda",
+        "sgdisk --new=1:0:+100M --typecode=0:ef00 /dev/vda", # /boot
+        "sgdisk --new=2:0:+1G --typecode=0:8200 /dev/vda", # swap
+        "sgdisk --new=3:0:+5G --typecode=0:8300 /dev/vda", # /
+        "udevadm settle",
 
-          "mkfs.vfat /dev/vda1",
-          "mkswap /dev/vda2 -L swap",
-          "swapon -L swap",
-          "stratis pool create my-pool /dev/vda3",
-          "stratis filesystem create my-pool nixos",
-          "udevadm settle",
+        "mkfs.vfat /dev/vda1",
+        "mkswap /dev/vda2 -L swap",
+        "swapon -L swap",
+        "stratis pool create my-pool /dev/vda3",
+        "stratis filesystem create my-pool nixos",
+        "udevadm settle",
 
-          "mount /dev/stratis/my-pool/nixos /mnt",
-          "mkdir -p /mnt/boot",
-          "mount /dev/vda1 /mnt/boot"
+        "mount /dev/stratis/my-pool/nixos /mnt",
+        "mkdir -p /mnt/boot",
+        "mount /dev/vda1 /mnt/boot"
       )
+
+      (header, pool_line) = machine.succeed("stratis pool list").splitlines()
+      index = header.find("UUID")
+      uuid = pool_line[index - 32: index + 4]
+      machine.succeed("mkdir -p /mnt/etc/nixos")
+      machine.succeed(f"printf %s {uuid} > /mnt/etc/nixos/rootPoolUuid.txt")
     '';
     bootLoader = "systemd-boot";
     extraInstallerConfig = { modulesPath, ...}: {
@@ -1056,19 +1058,6 @@ in {
         ];
       };
     };
-    amendConfig = ''
-      # This comment is here for Python indentation purposes
-          (header, pool_line) = machine.succeed("stratis pool list").splitlines()
-          index = header.find("UUID")
-          uuid = pool_line[index - 32: index + 4]
-          amendments = f"""{{ modulesPath, ... }}: {{
-            imports = [
-              (modulesPath + "/system/boot/stratisroot.nix")
-            ];
-            config = {{
-              boot.stratis.rootPoolUuid = "{uuid}";
-            }};
-          }}"""
-    '';
+    extraConfig = "boot.stratis.rootPoolUuid = builtins.readFile ./rootPoolUuid.txt;";
   };
 }