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.
This commit is contained in:
Linus Heckemann
2023-07-10 20:20:08 +02:00
parent 0b277bcc2b
commit c0f963a338
6 changed files with 39 additions and 30 deletions

View File

@@ -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" ];
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 = {
contents."/etc/mdadm.conf" = lib.mkIf (cfg.mdadmConf != "") {
text = cfg.mdadmConf;
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 = [ pkgs.mdadm ];
};
}