diff --git a/nixos/systems/blowhole/default.nix b/nixos/systems/blowhole/default.nix index 17146d5..aabc452 100644 --- a/nixos/systems/blowhole/default.nix +++ b/nixos/systems/blowhole/default.nix @@ -44,6 +44,7 @@ in ./watchdog.nix ./nixpkgs.nix ./users.nix + ./disk_monitoring.nix ./sol.nix ../../common/remote_access.nix ./microvms.nix diff --git a/nixos/systems/blowhole/disk_monitoring.nix b/nixos/systems/blowhole/disk_monitoring.nix new file mode 100644 index 0000000..88a8ec4 --- /dev/null +++ b/nixos/systems/blowhole/disk_monitoring.nix @@ -0,0 +1,76 @@ +{ + 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 <\` + + $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 -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/"; + }; +} diff --git a/nixos/systems/blowhole/filesystems.nix b/nixos/systems/blowhole/filesystems.nix index e2efd25..457c22c 100644 --- a/nixos/systems/blowhole/filesystems.nix +++ b/nixos/systems/blowhole/filesystems.nix @@ -82,6 +82,14 @@ in device = "blowhole-zpool/persist/vault"; fsType = "zfs"; }; + "/var/lib/matrix-commander" = { + device = "blowhole-zpool/persist/matrix-commander"; + fsType = "zfs"; + }; + "/var/lib/smartd" = { + device = "blowhole-zpool/persist/smartd"; + fsType = "zfs"; + }; } // secret.mounts.blowhole or {}; }