summary refs log tree commit diff
path: root/nixos/modules
diff options
context:
space:
mode:
authorLinus Heckemann <git@sphalerite.org>2023-07-10 20:20:08 +0200
committerLinus Heckemann <git@sphalerite.org>2023-07-10 20:20:08 +0200
commitc0f963a33805a7906de59b1f4bd73962d0130d5b (patch)
tree363fa9f54fb94e17bc2d84c2bf58501f7acf289e /nixos/modules
parent0b277bcc2b40c6ecd728c44635fa92262bedf620 (diff)
downloadnixpkgs-c0f963a33805a7906de59b1f4bd73962d0130d5b.tar
nixpkgs-c0f963a33805a7906de59b1f4bd73962d0130d5b.tar.gz
nixpkgs-c0f963a33805a7906de59b1f4bd73962d0130d5b.tar.bz2
nixpkgs-c0f963a33805a7906de59b1f4bd73962d0130d5b.tar.lz
nixpkgs-c0f963a33805a7906de59b1f4bd73962d0130d5b.tar.xz
nixpkgs-c0f963a33805a7906de59b1f4bd73962d0130d5b.tar.zst
nixpkgs-c0f963a33805a7906de59b1f4bd73962d0130d5b.zip
boot.initrd.services.swraid -> boot.swraid
Since the option affects both stage-1 and stage-2, it does not make
sense to keep it within the boot.initrd namespace.
Diffstat (limited to 'nixos/modules')
-rw-r--r--nixos/modules/installer/tools/nixos-generate-config.pl2
-rw-r--r--nixos/modules/profiles/installation-device.nix4
-rw-r--r--nixos/modules/system/boot/stage-1.nix5
-rw-r--r--nixos/modules/tasks/swraid.nix44
4 files changed, 32 insertions, 23 deletions
diff --git a/nixos/modules/installer/tools/nixos-generate-config.pl b/nixos/modules/installer/tools/nixos-generate-config.pl
index b08bf1e45d1..7d0c5898e23 100644
--- a/nixos/modules/installer/tools/nixos-generate-config.pl
+++ b/nixos/modules/installer/tools/nixos-generate-config.pl
@@ -534,7 +534,7 @@ EOF
     }
 }
 if ($useSwraid) {
-    push @attrs, "boot.initrd.services.swraid.enable = true;\n\n";
+    push @attrs, "boot.swraid.enable = true;\n\n";
 }
 
 
diff --git a/nixos/modules/profiles/installation-device.nix b/nixos/modules/profiles/installation-device.nix
index eea58294fb1..4120d5919d7 100644
--- a/nixos/modules/profiles/installation-device.nix
+++ b/nixos/modules/profiles/installation-device.nix
@@ -106,9 +106,7 @@ with lib;
         systemdStage1Network
       ];
 
-    boot.initrd.services = {
-      swraid.enable = true;
-    };
+    boot.swraid.enable = true;
 
     # Show all debug messages from the kernel but don't log refused packets
     # because we have the firewall enabled. This makes installs from the
diff --git a/nixos/modules/system/boot/stage-1.nix b/nixos/modules/system/boot/stage-1.nix
index dcb15cf7d42..81e5e974b9c 100644
--- a/nixos/modules/system/boot/stage-1.nix
+++ b/nixos/modules/system/boot/stage-1.nix
@@ -354,9 +354,6 @@ let
       [ { object = bootStage1;
           symlink = "/init";
         }
-        { object = pkgs.writeText "mdadm.conf" config.boot.initrd.services.swraid.mdadmConf;
-          symlink = "/etc/mdadm.conf";
-        }
         { object = pkgs.runCommand "initrd-kmod-blacklist-ubuntu" {
               src = "${pkgs.kmod-blacklist-ubuntu}/modprobe.conf";
               preferLocalBuild = true;
@@ -727,6 +724,6 @@ in
   };
 
   imports = [
-    (mkRenamedOptionModule [ "boot" "initrd" "mdadmConf" ] [ "boot" "initrd" "services" "swraid" "mdadmConf" ])
+    (mkRenamedOptionModule [ "boot" "initrd" "mdadmConf" ] [ "boot" "swraid" "mdadmConf" ])
   ];
 }
diff --git a/nixos/modules/tasks/swraid.nix b/nixos/modules/tasks/swraid.nix
index fde0f7e0091..d7a29b17a4b 100644
--- a/nixos/modules/tasks/swraid.nix
+++ b/nixos/modules/tasks/swraid.nix
@@ -1,20 +1,30 @@
 { config, pkgs, lib, ... }: let
 
-  cfg = config.boot.initrd.services.swraid;
+  cfg = config.boot.swraid;
 
 in {
 
-  options.boot.initrd.services.swraid = {
+  options.boot.swraid = {
     enable = lib.mkEnableOption (lib.mdDoc "swraid support using mdadm") // {
       description = lib.mdDoc ''
-        Whether to enable swraid support using mdadm.
+        Whether to enable support for Linux MD RAID arrays.
+
+        When this is enabled, mdadm will be added to the system path,
+        and MD RAID arrays will be detected and activated
+        automatically, both in stage-1 (initramfs) and in stage-2 (the
+        final NixOS system).
+
+        This should be enabled if you want to be able to access and/or
+        boot from MD RAID arrays. {command}`nixos-generate-config`
+        should detect it correctly in the standard installation
+        procedure.
       '';
       default = lib.versionOlder config.system.stateVersion "23.11";
       defaultText = lib.mdDoc "`true` if stateVersion is older than 23.11";
     };
 
     mdadmConf = lib.mkOption {
-      description = lib.mdDoc "Contents of {file}`/etc/mdadm.conf` in initrd.";
+      description = lib.mdDoc "Contents of {file}`/etc/mdadm.conf`.";
       type = lib.types.lines;
       default = "";
     };
@@ -27,21 +37,25 @@ in {
 
     systemd.packages = [ pkgs.mdadm ];
 
-    boot.initrd.availableKernelModules = [ "md_mod" "raid0" "raid1" "raid10" "raid456" ];
+    boot.initrd = {
+      availableKernelModules = [ "md_mod" "raid0" "raid1" "raid10" "raid456" ];
+
+      extraUdevRulesCommands = lib.mkIf (!config.boot.initrd.systemd.enable) ''
+        cp -v ${pkgs.mdadm}/lib/udev/rules.d/*.rules $out/
+      '';
+
+      extraFiles."/etc/mdadm.conf".source = pkgs.writeText "mdadm.conf" config.boot.swraid.mdadmConf;
 
-    boot.initrd.extraUdevRulesCommands = lib.mkIf (!config.boot.initrd.systemd.enable) ''
-      cp -v ${pkgs.mdadm}/lib/udev/rules.d/*.rules $out/
-    '';
+      systemd = {
+        contents."/etc/mdadm.conf" = lib.mkIf (cfg.mdadmConf != "") {
+          text = cfg.mdadmConf;
+        };
 
-    boot.initrd.systemd = {
-      contents."/etc/mdadm.conf" = lib.mkIf (cfg.mdadmConf != "") {
-        text = cfg.mdadmConf;
+        packages = [ pkgs.mdadm ];
+        initrdBin = [ pkgs.mdadm ];
       };
 
-      packages = [ pkgs.mdadm ];
-      initrdBin = [ pkgs.mdadm ];
+      services.udev.packages = [ pkgs.mdadm ];
     };
-
-    boot.initrd.services.udev.packages = [ pkgs.mdadm ];
   };
 }