about summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorMatthias Berndt <matthias_berndt@gmx.de>2023-05-16 22:48:36 -0400
committerMatthias Berndt <matthias_berndt@gmx.de>2023-05-16 22:48:36 -0400
commit92814241a8b992c18accbb939360654369eb2cc4 (patch)
treeb46a13c7553c3d9398b253b4166b3e492a065417 /nixos
parent3aa262b644feff5153888ed85661450cb151088b (diff)
downloadnixlib-92814241a8b992c18accbb939360654369eb2cc4.tar
nixlib-92814241a8b992c18accbb939360654369eb2cc4.tar.gz
nixlib-92814241a8b992c18accbb939360654369eb2cc4.tar.bz2
nixlib-92814241a8b992c18accbb939360654369eb2cc4.tar.lz
nixlib-92814241a8b992c18accbb939360654369eb2cc4.tar.xz
nixlib-92814241a8b992c18accbb939360654369eb2cc4.tar.zst
nixlib-92814241a8b992c18accbb939360654369eb2cc4.zip
improve stratis initrd support
it is now possible to supply a stratis pool uuid
for every filesystem, and if that filesystem
is required for boot, the relevant pool will be
started in the initramfs.
Diffstat (limited to 'nixos')
-rw-r--r--nixos/doc/manual/release-notes/rl-2305.section.md2
-rw-r--r--nixos/modules/system/boot/stratisroot.nix58
-rw-r--r--nixos/modules/tasks/filesystems.nix9
-rw-r--r--nixos/tests/installer.nix7
4 files changed, 37 insertions, 39 deletions
diff --git a/nixos/doc/manual/release-notes/rl-2305.section.md b/nixos/doc/manual/release-notes/rl-2305.section.md
index 44d82a950294..07b6a5f2445d 100644
--- a/nixos/doc/manual/release-notes/rl-2305.section.md
+++ b/nixos/doc/manual/release-notes/rl-2305.section.md
@@ -476,7 +476,7 @@ In addition to numerous new and upgraded packages, this release has the followin
 
 - `boot.initrd.luks.device.<name>` has a new `tryEmptyPassphrase` option, this is useful for OEM's who need to install an encrypted disk with a future settable passphrase
 
-- there is a new `boot/stratisroot.nix` module that enables booting from a volume managed by the Stratis storage management daemon. Use `boot.stratis.rootPoolUuid` to configure the pool containing the root volume
+- there is a new `boot/stratisroot.nix` module that enables booting from a volume managed by the Stratis storage management daemon. Use `fileSystems.<name>.stratis.poolUuid` to configure the pool containing the fs.
 
 - Lisp gained a [manual section](https://nixos.org/manual/nixpkgs/stable/#lisp), documenting a new and backwards incompatible interface. The previous interface will be removed in a future release.
 
diff --git a/nixos/modules/system/boot/stratisroot.nix b/nixos/modules/system/boot/stratisroot.nix
index 53621008c338..f0d1b5475554 100644
--- a/nixos/modules/system/boot/stratisroot.nix
+++ b/nixos/modules/system/boot/stratisroot.nix
@@ -1,19 +1,11 @@
-{ config, lib, pkgs, ... }:
+{ config, lib, pkgs, utils, ... }:
 let
   types = lib.types;
+  requiredStratisFilesystems = lib.attrsets.filterAttrs (_: x: utils.fsNeededForBoot x && x.stratis.poolUuid != null) config.fileSystems;
 in
 {
-  options.boot.stratis = {
-    rootPoolUuid = lib.mkOption {
-      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 = lib.mkIf (config.boot.stratis.rootPoolUuid != null) {
+  options = {};
+  config = lib.mkIf (builtins.length (lib.attrsets.attrValues requiredStratisFilesystems) != 0) {
     assertions = [
       {
         assertion = config.boot.initrd.systemd.enable;
@@ -36,25 +28,29 @@ in
           thin_metadata_size = "${pkgs."thin-provisioning-tools"}/bin/thin_metadata_size";
           stratis-min = "${pkgs.stratisd}/bin/stratis-min";
         };
-        services = {
-          stratis-setup = {
-            description = "setup for Stratis root filesystem";
-            unitConfig.DefaultDependencies = "no";
-            conflicts = [ "shutdown.target" "initrd-switch-root.target" ];
-            onFailure = [ "emergency.target" ];
-            unitConfig.OnFailureJobMode = "isolate";
-            wants = [ "stratisd-min.service" "plymouth-start.service" ];
-            wantedBy = [ "initrd.target" ];
-            after = [ "paths.target" "plymouth-start.service" "stratisd-min.service" ];
-            before = [ "initrd.target" "shutdown.target" "initrd-switch-root.target" ];
-            environment.STRATIS_ROOTFS_UUID = config.boot.stratis.rootPoolUuid;
-            serviceConfig = {
-              Type = "oneshot";
-              ExecStart = "${pkgs.stratisd.initrd}/bin/stratis-rootfs-setup";
-              RemainAfterExit = "yes";
-            };
-          };
-        };
+        services =
+          lib.attrsets.mapAttrs' (
+            mountPoint: fileSystem: {
+              name = "stratis-setup-${fileSystem.stratis.poolUuid}";
+              value = {
+                description = "setup for Stratis root filesystem";
+                unitConfig.DefaultDependencies = "no";
+                conflicts = [ "shutdown.target" "initrd-switch-root.target" ];
+                onFailure = [ "emergency.target" ];
+                unitConfig.OnFailureJobMode = "isolate";
+                wants = [ "stratisd-min.service" "plymouth-start.service" ];
+                wantedBy = [ "initrd.target" ];
+                after = [ "paths.target" "plymouth-start.service" "stratisd-min.service" ];
+                before = [ "initrd.target" "shutdown.target" "initrd-switch-root.target" ];
+                environment.STRATIS_ROOTFS_UUID = fileSystem.stratis.poolUuid;
+                serviceConfig = {
+                  Type = "oneshot";
+                  ExecStart = "${pkgs.stratisd.initrd}/bin/stratis-rootfs-setup";
+                  RemainAfterExit = "yes";
+                };
+              };
+            }
+          ) requiredStratisFilesystems;
       };
       availableKernelModules = [ "dm-thin-pool" "dm-crypt" ] ++ [ "aes" "aes_generic" "blowfish" "twofish"
         "serpent" "cbc" "xts" "lrw" "sha1" "sha256" "sha512"
diff --git a/nixos/modules/tasks/filesystems.nix b/nixos/modules/tasks/filesystems.nix
index 326862f836a5..2f032c3faf5c 100644
--- a/nixos/modules/tasks/filesystems.nix
+++ b/nixos/modules/tasks/filesystems.nix
@@ -36,6 +36,15 @@ let
         description = lib.mdDoc "Location of the mounted file system.";
       };
 
+      stratis.poolUuid = lib.mkOption {
+        type = types.uniq (types.nullOr types.str);
+        description = lib.mdDoc ''
+          UUID of the stratis pool that the fs is located in
+        '';
+        example = "04c68063-90a5-4235-b9dd-6180098a20d9";
+        default = null;
+      };
+
       device = mkOption {
         default = null;
         example = "/dev/sda";
diff --git a/nixos/tests/installer.nix b/nixos/tests/installer.nix
index 1346eb36c36e..d398924aa4a6 100644
--- a/nixos/tests/installer.nix
+++ b/nixos/tests/installer.nix
@@ -1038,12 +1038,6 @@ in {
         "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, ...}: {
@@ -1058,6 +1052,5 @@ in {
         ];
       };
     };
-    extraConfig = "boot.stratis.rootPoolUuid = builtins.readFile ./rootPoolUuid.txt;";
   };
 }