2022-04-27 09:35:20 +00:00
|
|
|
{ config, pkgs, lib, ... }: let
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-04-27 09:35:20 +00:00
|
|
|
cfg = config.boot.initrd.services.swraid;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-04-27 09:35:20 +00:00
|
|
|
in {
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-04-27 09:35:20 +00:00
|
|
|
options.boot.initrd.services.swraid = {
|
|
|
|
enable = (lib.mkEnableOption "swraid support using mdadm") // {
|
|
|
|
visible = false; # only has effect when the new stage 1 is in place
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-04-27 09:35:20 +00:00
|
|
|
mdadmConf = lib.mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Contents of {file}`/etc/mdadm.conf` in initrd.";
|
2022-04-27 09:35:20 +00:00
|
|
|
type = lib.types.lines;
|
|
|
|
default = "";
|
|
|
|
};
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-04-27 09:35:20 +00:00
|
|
|
config = {
|
|
|
|
environment.systemPackages = [ pkgs.mdadm ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-04-27 09:35:20 +00:00
|
|
|
services.udev.packages = [ pkgs.mdadm ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-04-27 09:35:20 +00:00
|
|
|
systemd.packages = [ pkgs.mdadm ];
|
|
|
|
|
|
|
|
boot.initrd.availableKernelModules = lib.mkIf (config.boot.initrd.systemd.enable -> cfg.enable) [ "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/
|
|
|
|
'';
|
|
|
|
|
|
|
|
boot.initrd.systemd = lib.mkIf cfg.enable {
|
|
|
|
contents."/etc/mdadm.conf" = lib.mkIf (cfg.mdadmConf != "") {
|
|
|
|
text = cfg.mdadmConf;
|
|
|
|
};
|
|
|
|
|
|
|
|
packages = [ pkgs.mdadm ];
|
|
|
|
initrdBin = [ pkgs.mdadm ];
|
|
|
|
};
|
|
|
|
|
|
|
|
boot.initrd.services.udev.packages = lib.mkIf cfg.enable [ pkgs.mdadm ];
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
}
|