2022-04-15 18:28:41 +03:00
|
|
|
{ config, pkgs, lib, ... }: let
|
2009-03-06 15:27:30 +03:00
|
|
|
|
2023-07-10 21:20:08 +03:00
|
|
|
cfg = config.boot.swraid;
|
2007-01-11 03:40:28 +03:00
|
|
|
|
2023-09-09 22:38:16 +03:00
|
|
|
mdadm_conf = config.environment.etc."mdadm.conf";
|
|
|
|
|
2022-04-15 18:28:41 +03:00
|
|
|
in {
|
2023-07-15 04:46:04 +03:00
|
|
|
imports = [
|
|
|
|
(lib.mkRenamedOptionModule [ "boot" "initrd" "services" "swraid" "enable" ] [ "boot" "swraid" "enable" ])
|
|
|
|
(lib.mkRenamedOptionModule [ "boot" "initrd" "services" "swraid" "mdadmConf" ] [ "boot" "swraid" "mdadmConf" ])
|
|
|
|
];
|
|
|
|
|
2011-09-14 22:20:50 +04:00
|
|
|
|
2023-07-10 21:20:08 +03:00
|
|
|
options.boot.swraid = {
|
2023-07-03 15:41:38 +03:00
|
|
|
enable = lib.mkEnableOption (lib.mdDoc "swraid support using mdadm") // {
|
2022-07-28 15:34:44 +03:00
|
|
|
description = lib.mdDoc ''
|
2023-07-10 21:20:08 +03:00
|
|
|
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.
|
2023-07-03 15:41:38 +03:00
|
|
|
'';
|
2022-07-28 15:34:44 +03:00
|
|
|
default = lib.versionOlder config.system.stateVersion "23.11";
|
|
|
|
defaultText = lib.mdDoc "`true` if stateVersion is older than 23.11";
|
2022-04-15 18:28:41 +03:00
|
|
|
};
|
2009-12-29 13:04:54 +03:00
|
|
|
|
2022-04-15 18:28:41 +03:00
|
|
|
mdadmConf = lib.mkOption {
|
2023-07-10 21:20:08 +03:00
|
|
|
description = lib.mdDoc "Contents of {file}`/etc/mdadm.conf`.";
|
2022-04-15 18:28:41 +03:00
|
|
|
type = lib.types.lines;
|
|
|
|
default = "";
|
|
|
|
};
|
|
|
|
};
|
2019-07-25 16:36:16 +03:00
|
|
|
|
2022-07-28 15:34:44 +03:00
|
|
|
config = lib.mkIf cfg.enable {
|
2023-09-09 22:38:16 +03:00
|
|
|
warnings = lib.mkIf
|
|
|
|
((builtins.match ".*(MAILADDR|PROGRAM).*" mdadm_conf.text) == null)
|
|
|
|
[ "mdadm: Neither MAILADDR nor PROGRAM has been set. This will cause the `mdmon` service to crash." ];
|
|
|
|
|
2022-04-15 18:28:41 +03:00
|
|
|
environment.systemPackages = [ pkgs.mdadm ];
|
2011-09-14 22:20:50 +04:00
|
|
|
|
2023-09-09 22:38:16 +03:00
|
|
|
environment.etc."mdadm.conf".text = lib.mkAfter cfg.mdadmConf;
|
|
|
|
|
2022-04-15 18:28:41 +03:00
|
|
|
services.udev.packages = [ pkgs.mdadm ];
|
2014-11-11 00:08:10 +03:00
|
|
|
|
2022-04-15 18:28:41 +03:00
|
|
|
systemd.packages = [ pkgs.mdadm ];
|
|
|
|
|
2023-07-10 21:20:08 +03:00
|
|
|
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/
|
|
|
|
'';
|
|
|
|
|
2023-07-10 21:31:13 +03:00
|
|
|
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
|
|
|
|
'';
|
|
|
|
|
2023-09-09 22:38:16 +03:00
|
|
|
extraFiles."/etc/mdadm.conf" = mdadm_conf;
|
2022-04-15 18:28:41 +03:00
|
|
|
|
2023-07-10 21:20:08 +03:00
|
|
|
systemd = {
|
2023-09-09 22:38:16 +03:00
|
|
|
contents."/etc/mdadm.conf".text = mdadm_conf.text;
|
2022-04-15 18:28:41 +03:00
|
|
|
|
2023-07-10 21:20:08 +03:00
|
|
|
packages = [ pkgs.mdadm ];
|
|
|
|
initrdBin = [ pkgs.mdadm ];
|
2022-04-15 18:28:41 +03:00
|
|
|
};
|
|
|
|
|
2023-07-10 21:20:08 +03:00
|
|
|
services.udev.packages = [ pkgs.mdadm ];
|
2022-04-15 18:28:41 +03:00
|
|
|
};
|
|
|
|
};
|
2007-01-11 03:40:28 +03:00
|
|
|
}
|