summary refs log tree commit diff
path: root/nixos/modules/system
diff options
context:
space:
mode:
authorGraham Christensen <graham@grahamc.com>2021-10-13 09:58:25 -0400
committerGitHub <noreply@github.com>2021-10-13 09:58:25 -0400
commita997f198a394a92fe75554133c15051212cba8b4 (patch)
tree6c09a96c80401dce1266ab8f3ae6c6fa12e3159f /nixos/modules/system
parenta8010e647f4d2740350ebb8dd1f08da73d05c0ce (diff)
parent121cfd1998e50f55d48502c0fc80cb7611f7e699 (diff)
downloadnixpkgs-a997f198a394a92fe75554133c15051212cba8b4.tar
nixpkgs-a997f198a394a92fe75554133c15051212cba8b4.tar.gz
nixpkgs-a997f198a394a92fe75554133c15051212cba8b4.tar.bz2
nixpkgs-a997f198a394a92fe75554133c15051212cba8b4.tar.lz
nixpkgs-a997f198a394a92fe75554133c15051212cba8b4.tar.xz
nixpkgs-a997f198a394a92fe75554133c15051212cba8b4.tar.zst
nixpkgs-a997f198a394a92fe75554133c15051212cba8b4.zip
Merge pull request #139833 from flox/multipath
nixos/multipath: add module for multipath-tools package
Diffstat (limited to 'nixos/modules/system')
-rw-r--r--nixos/modules/system/boot/stage-1.nix49
1 files changed, 48 insertions, 1 deletions
diff --git a/nixos/modules/system/boot/stage-1.nix b/nixos/modules/system/boot/stage-1.nix
index bd7e955a6f4..adbed9d8d58 100644
--- a/nixos/modules/system/boot/stage-1.nix
+++ b/nixos/modules/system/boot/stage-1.nix
@@ -137,6 +137,14 @@ let
         copy_bin_and_libs ${pkgs.e2fsprogs}/sbin/resize2fs
       ''}
 
+      # Copy multipath.
+      ${optionalString config.services.multipath.enable ''
+        copy_bin_and_libs ${config.services.multipath.package}/bin/multipath
+        copy_bin_and_libs ${config.services.multipath.package}/bin/multipathd
+        # Copy lib/multipath manually.
+        cp -rpv ${config.services.multipath.package}/lib/multipath $out/lib
+      ''}
+
       # Copy secrets if needed.
       #
       # TODO: move out to a separate script; see #85000.
@@ -199,6 +207,10 @@ let
       $out/bin/dmsetup --version 2>&1 | tee -a log | grep -q "version:"
       LVM_SYSTEM_DIR=$out $out/bin/lvm version 2>&1 | tee -a log | grep -q "LVM"
       $out/bin/mdadm --version
+      ${optionalString config.services.multipath.enable ''
+        ($out/bin/multipath || true) 2>&1 | grep -q 'need to be root'
+        ($out/bin/multipathd || true) 2>&1 | grep -q 'need to be root'
+      ''}
 
       ${config.boot.initrd.extraUtilsCommandsTest}
       fi
@@ -338,7 +350,26 @@ let
         { object = pkgs.kmod-debian-aliases;
           symlink = "/etc/modprobe.d/debian.conf";
         }
-      ];
+      ] ++ lib.optionals config.services.multipath.enable [
+        { object = pkgs.runCommand "multipath.conf" {
+              src = config.environment.etc."multipath.conf".text;
+              preferLocalBuild = true;
+            } ''
+              target=$out
+              printf "$src" > $out
+              substituteInPlace $out \
+                --replace ${config.services.multipath.package}/lib ${extraUtils}/lib
+            '';
+          symlink = "/etc/multipath.conf";
+        }
+      ] ++ (lib.mapAttrsToList
+        (symlink: options:
+          {
+            inherit symlink;
+            object = options.source;
+          }
+        )
+        config.boot.initrd.extraFiles);
   };
 
   # Script to add secret files to the initrd at bootloader update time
@@ -419,6 +450,22 @@ in
       '';
     };
 
+    boot.initrd.extraFiles = mkOption {
+      default = { };
+      type = types.attrsOf
+        (types.submodule {
+          options = {
+            source = mkOption {
+              type = types.package;
+              description = "The object to make available inside the initrd.";
+            };
+          };
+        });
+      description = ''
+        Extra files to link and copy in to the initrd.
+      '';
+    };
+
     boot.initrd.prepend = mkOption {
       default = [ ];
       type = types.listOf types.str;