mirror of
https://git.sr.ht/~magic_rb/dotfiles
synced 2024-11-26 18:16:13 +01:00
ad6a5f6784
Signed-off-by: magic_rb <magic_rb@redalder.org>
77 lines
1.7 KiB
Nix
77 lines
1.7 KiB
Nix
{
|
|
lib,
|
|
pkgs,
|
|
config,
|
|
...
|
|
}: let
|
|
inherit (lib) concatMapStringsSep;
|
|
|
|
cfg = config.services.smartd;
|
|
|
|
smartdNotify = pkgs.writeShellScript "smartd-notify-matrix" ''
|
|
while [[ $# > 0 ]] ; do
|
|
case "$1" in
|
|
-i)
|
|
shift 2
|
|
;;
|
|
*)
|
|
;;
|
|
esac
|
|
done
|
|
|
|
{
|
|
${pkgs.coreutils}/bin/cat <<EOF
|
|
smartd on \`<blowhole>\`
|
|
|
|
$SMARTD_SUBJECT
|
|
|
|
\`\`\`
|
|
|
|
$SMARTD_FULLMESSAGE
|
|
\`\`\`
|
|
|
|
\`\`\`
|
|
|
|
$(${pkgs.smartmontools}/sbin/smartctl -a -d "$SMARTD_DEVICETYPE" "$SMARTD_DEVICE")
|
|
\`\`\`
|
|
EOF
|
|
} | ${pkgs.matrix-commander-rs}/bin/matrix-commander-rs -c /var/secrets/matrix-smartd.json -s /var/lib/matrix-commander --markdown -m -
|
|
'';
|
|
|
|
smartdConfig = pkgs.writeText "smartd.conf" ''
|
|
DEFAULT -m <nomailer> -M exec ${smartdNotify} -M test -a
|
|
|
|
${concatMapStringsSep "\n" (d: "${d.device} ${d.options}") cfg.devices}
|
|
'';
|
|
in {
|
|
services.smartd = {
|
|
# The module needs fixing
|
|
enable = false;
|
|
|
|
devices = map (x: {device = "/dev/disk/by-id/" + x;}) [
|
|
# Old Skyhawks
|
|
"ata-ST1000VX005-2EZ102_Z9CBQKCQ"
|
|
"ata-ST1000VX005-2EZ102_Z9CBQLDS"
|
|
|
|
# NAS WD Reds
|
|
"ata-WDC_WD40EFZX-68AWUN0_WD-WX82DA1C79SK"
|
|
"ata-WDC_WD40EFZX-68AWUN0_WD-WXA2DA1C9JKA"
|
|
|
|
# Boot SSD
|
|
"ata-Apacer_AS350_128GB_2021020103001990"
|
|
|
|
# Database SSDs
|
|
"nvme-KINGSTON_SA2000M8250G_50026B76844F4629"
|
|
"nvme-KINGSTON_SA2000M8250G_50026B76851B664C"
|
|
];
|
|
|
|
extraOptions = ["-M" "exec ${smartdNotify}" "-M" "test"];
|
|
};
|
|
|
|
systemd.services.smartd = {
|
|
description = "S.M.A.R.T. Daemon";
|
|
wantedBy = ["multi-user.target"];
|
|
serviceConfig.ExecStart = "${pkgs.smartmontools}/sbin/smartd --no-fork --configfile=${smartdConfig} -s /var/lib/smartd/";
|
|
};
|
|
}
|