summary refs log tree commit diff
path: root/nixos/modules/tasks
diff options
context:
space:
mode:
authorWill Fancher <elvishjerricco@gmail.com>2023-07-13 16:24:34 -0400
committerGitHub <noreply@github.com>2023-07-13 16:24:34 -0400
commit11fec97761910d059a1315dbebe4e70a711a968a (patch)
treeffbffae6375c7754f39356e5543ae7423411d21e /nixos/modules/tasks
parent3d0e323be315beda11e941749cf65677be6631dc (diff)
parent7d2124f9e3206166d82e72990cb5637c25a42b47 (diff)
downloadnixpkgs-11fec97761910d059a1315dbebe4e70a711a968a.tar
nixpkgs-11fec97761910d059a1315dbebe4e70a711a968a.tar.gz
nixpkgs-11fec97761910d059a1315dbebe4e70a711a968a.tar.bz2
nixpkgs-11fec97761910d059a1315dbebe4e70a711a968a.tar.lz
nixpkgs-11fec97761910d059a1315dbebe4e70a711a968a.tar.xz
nixpkgs-11fec97761910d059a1315dbebe4e70a711a968a.tar.zst
nixpkgs-11fec97761910d059a1315dbebe4e70a711a968a.zip
Merge pull request #183314 from DeterminateSystems/optional-swraid
Make swraid optional
Diffstat (limited to 'nixos/modules/tasks')
-rw-r--r--nixos/modules/tasks/swraid.nix60
1 files changed, 42 insertions, 18 deletions
diff --git a/nixos/modules/tasks/swraid.nix b/nixos/modules/tasks/swraid.nix
index 1c3f1db1509..9dca230ac0d 100644
--- a/nixos/modules/tasks/swraid.nix
+++ b/nixos/modules/tasks/swraid.nix
@@ -1,47 +1,71 @@
 { 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 = ''
-        *This will only be used when systemd is used in stage 1.*
+      description = lib.mdDoc ''
+        Whether to enable support for Linux MD RAID arrays.
 
-        Whether to enable swraid support using mdadm.
+        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 = "";
     };
   };
 
-  config = {
+  config = lib.mkIf cfg.enable {
     environment.systemPackages = [ pkgs.mdadm ];
 
     services.udev.packages = [ pkgs.mdadm ];
 
     systemd.packages = [ pkgs.mdadm ];
 
-    boot.initrd.availableKernelModules = lib.mkIf (config.boot.initrd.systemd.enable -> cfg.enable) [ "md_mod" "raid0" "raid1" "raid10" "raid456" ];
+    boot.initrd = {
+      availableKernelModules = [ "md_mod" "raid0" "raid1" "raid10" "raid456" ];
 
-    boot.initrd.extraUdevRulesCommands = lib.mkIf (!config.boot.initrd.systemd.enable) ''
-      cp -v ${pkgs.mdadm}/lib/udev/rules.d/*.rules $out/
-    '';
+      extraUdevRulesCommands = lib.mkIf (!config.boot.initrd.systemd.enable) ''
+        cp -v ${pkgs.mdadm}/lib/udev/rules.d/*.rules $out/
+      '';
 
-    boot.initrd.systemd = lib.mkIf cfg.enable {
-      contents."/etc/mdadm.conf" = lib.mkIf (cfg.mdadmConf != "") {
-        text = cfg.mdadmConf;
+      extraUtilsCommands = ''
+        # Add RAID mdadm tool.
+        copy_bin_and_libs ${pkgs.mdadm}/sbin/mdadm
+        copy_bin_and_libs ${pkgs.mdadm}/sbin/mdmon
+      '';
+
+      extraUtilsCommandsTest = ''
+        $out/bin/mdadm --version
+      '';
+
+      extraFiles."/etc/mdadm.conf".source = pkgs.writeText "mdadm.conf" config.boot.swraid.mdadmConf;
+
+      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 = lib.mkIf cfg.enable [ pkgs.mdadm ];
   };
 }