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