From 7bea060e8142cbbf46942fe17838f5748a9b7d06 Mon Sep 17 00:00:00 2001 From: Felix Buehler Date: Sun, 19 Mar 2023 16:14:20 +0100 Subject: [PATCH] service/drive: init from legacy and enable mail on error --- legacy/modules/hardware-base.nix | 5 ---- machines/newton/hardware-configuration.nix | 7 +++++ machines/serverle/hardware-configuration.nix | 7 +++++ machines/thinkman/hardware-configuration.nix | 4 +++ modules/hardware/default.nix | 1 + modules/hardware/drive-monitor/default.nix | 29 ++++++++++++++++++++ modules/services/backup/default.nix | 2 +- 7 files changed, 49 insertions(+), 6 deletions(-) delete mode 100644 legacy/modules/hardware-base.nix create mode 100644 modules/hardware/drive-monitor/default.nix diff --git a/legacy/modules/hardware-base.nix b/legacy/modules/hardware-base.nix deleted file mode 100644 index 9c040f3..0000000 --- a/legacy/modules/hardware-base.nix +++ /dev/null @@ -1,5 +0,0 @@ -{ config, lib, pkgs, ... }: - -{ - services.smartd.enable = true; -} diff --git a/machines/newton/hardware-configuration.nix b/machines/newton/hardware-configuration.nix index 62869a1..55ea9ac 100644 --- a/machines/newton/hardware-configuration.nix +++ b/machines/newton/hardware-configuration.nix @@ -16,4 +16,11 @@ boot.extraModulePackages = [ ]; hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; + + my.hardware = { + drive-monitor = { + enable = true; + OnFailureMail = "server@buehler.rocks"; + }; + }; } diff --git a/machines/serverle/hardware-configuration.nix b/machines/serverle/hardware-configuration.nix index 7f5faa9..60b6c8b 100644 --- a/machines/serverle/hardware-configuration.nix +++ b/machines/serverle/hardware-configuration.nix @@ -31,4 +31,11 @@ # Fix wifi disconnect networking.networkmanager.wifi.powersave = false; + + my.hardware = { + drive-monitor = { + enable = true; + OnFailureMail = "server@buehler.rocks"; + }; + }; } diff --git a/machines/thinkman/hardware-configuration.nix b/machines/thinkman/hardware-configuration.nix index d0b2239..a587254 100644 --- a/machines/thinkman/hardware-configuration.nix +++ b/machines/thinkman/hardware-configuration.nix @@ -12,6 +12,10 @@ in my.hardware = { bluetooth.enable = true; debug.enable = true; + drive-monitor = { + enable = true; + OnFailureMail = "server@buehler.rocks"; + }; firmware = { enable = true; cpuFlavor = cpuFlavor; diff --git a/modules/hardware/default.nix b/modules/hardware/default.nix index 15c047c..3033a40 100644 --- a/modules/hardware/default.nix +++ b/modules/hardware/default.nix @@ -5,6 +5,7 @@ imports = [ ./bluetooth ./debug + ./drive-monitor ./firmware ./graphics ./keychron diff --git a/modules/hardware/drive-monitor/default.nix b/modules/hardware/drive-monitor/default.nix new file mode 100644 index 0000000..3afc6e0 --- /dev/null +++ b/modules/hardware/drive-monitor/default.nix @@ -0,0 +1,29 @@ +{ config, lib, pkgs, ... }: +let + cfg = config.my.hardware.drive-monitor; +in +{ + options.my.hardware.drive-monitor = with lib; { + enable = mkEnableOption "drive-monitor configuration"; + + OnFailureMail = mkOption { + type = types.nullOr (types.str); + description = lib.mdDoc "Mail adress where to send the error report"; + default = null; + example = "alarm@mail.com"; + }; + }; + + config = lib.mkIf cfg.enable { + services = { + postfix.enable = lib.mkIf (cfg.OnFailureMail != null) true; + smartd = { + enable = true; + notifications.mail = lib.mkIf (cfg.OnFailureMail != null) { + enable = true; + recipient = cfg.OnFailureMail; + }; + }; + }; + }; +} diff --git a/modules/services/backup/default.nix b/modules/services/backup/default.nix index d11dce4..09c2d7b 100644 --- a/modules/services/backup/default.nix +++ b/modules/services/backup/default.nix @@ -81,7 +81,7 @@ in config = lib.mkIf cfg.enable { # mails can only be delivered if postfix is available - services.postfix.enable = cfg.OnFailureMail != null; + services.postfix.enable = lib.mkIf (cfg.OnFailureMail != null) true; services.borgbackup.jobs.hetzner = { # always backup everything and only define excludes