2024-12-06 16:46:10 +00:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
config,
|
|
|
|
namespace,
|
|
|
|
...
|
|
|
|
}:
|
2024-08-29 13:14:27 +00:00
|
|
|
let
|
2024-12-06 16:46:10 +00:00
|
|
|
cfg = config.${namespace}.raid;
|
2024-08-29 13:14:27 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
|
|
|
|
options = {
|
2024-12-06 16:46:10 +00:00
|
|
|
${namespace}.raid = {
|
2024-08-29 13:14:27 +00:00
|
|
|
enable = lib.mkEnableOption "Enables RAID support.";
|
2024-09-17 14:42:09 +00:00
|
|
|
storage = {
|
|
|
|
enable = lib.mkEnableOption "Enables support for the storage array.";
|
|
|
|
mailAddr = lib.mkOption {
|
|
|
|
default = "";
|
|
|
|
type = lib.types.str;
|
|
|
|
description = "Address to email in case of issues.";
|
|
|
|
example = "admin@example.com";
|
|
|
|
};
|
|
|
|
keyFile = lib.mkOption {
|
|
|
|
default = "";
|
2024-09-18 14:15:06 +00:00
|
|
|
type = lib.types.str;
|
2024-09-17 14:42:09 +00:00
|
|
|
description = "Path to the key file to use to auto-unlock the array.";
|
2024-09-18 14:15:06 +00:00
|
|
|
example = "/home/user/storage.key";
|
2024-09-17 14:42:09 +00:00
|
|
|
};
|
|
|
|
};
|
2024-08-29 13:14:27 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkMerge [
|
|
|
|
(lib.mkIf cfg.enable { boot.swraid.enable = true; })
|
2024-09-06 19:26:40 +00:00
|
|
|
(lib.mkIf cfg.storage.enable {
|
2024-12-06 16:46:10 +00:00
|
|
|
${namespace}.raid.enable = true;
|
2024-08-29 13:14:27 +00:00
|
|
|
boot.swraid.mdadmConf = ''
|
|
|
|
ARRAY /dev/md/Sapana metadata=1.2 UUID=51076daf:efdb34dd:bce48342:3b549fcb
|
2024-09-17 14:42:09 +00:00
|
|
|
MAILADDR ${cfg.storage.mailAddr}
|
2024-08-29 13:14:27 +00:00
|
|
|
'';
|
2024-09-08 15:58:56 +00:00
|
|
|
|
2024-09-08 17:17:40 +00:00
|
|
|
# Auto-unlock RAID array with a key file
|
2024-09-18 14:15:06 +00:00
|
|
|
environment.etc."crypttab" = lib.mkIf (cfg.storage.keyFile != "") {
|
|
|
|
text = "storage /dev/md/Sapana ${cfg.storage.keyFile} nofail,keyfile-timeout=5s";
|
|
|
|
};
|
2024-09-08 17:17:40 +00:00
|
|
|
fileSystems."/storage" = {
|
|
|
|
device = "/dev/mapper/storage";
|
|
|
|
# Keep booting even if the array fails to unlock
|
2024-09-08 17:42:01 +00:00
|
|
|
options = [ "nofail" ];
|
2024-09-08 17:17:40 +00:00
|
|
|
};
|
|
|
|
|
2024-09-08 15:58:56 +00:00
|
|
|
# Automatically scrub the array monthly
|
|
|
|
systemd = {
|
|
|
|
services."raid-scrub" = {
|
|
|
|
description = "Periodically scrub RAID volumes for errors.";
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
User = "root";
|
|
|
|
};
|
|
|
|
script = "echo check > /sys/block/md127/md/sync_action";
|
|
|
|
};
|
|
|
|
timers."raid-scrub" = {
|
|
|
|
description = "Periodically scrub RAID volumes for errors.";
|
|
|
|
wantedBy = [ "timers.target" ];
|
|
|
|
timerConfig = {
|
|
|
|
OnCalendar = "monthly";
|
|
|
|
Persistent = true;
|
|
|
|
Unit = "raid-scrub.service";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2024-08-29 13:14:27 +00:00
|
|
|
})
|
|
|
|
];
|
|
|
|
}
|