commit ea523aa824ec9aa0060f9fb82cfd9cf57ad65a65
parent ab2b2ba8a84cc70ee62abe628a3e1a4029d3596a
Author: Leah (ctucx) <leah@ctu.cx>
Date: Mon, 12 Sep 2022 22:21:09 +0200
parent ab2b2ba8a84cc70ee62abe628a3e1a4029d3596a
Author: Leah (ctucx) <leah@ctu.cx>
Date: Mon, 12 Sep 2022 22:21:09 +0200
modules: add module email-notify (moved code from configurations)
7 files changed, 43 insertions(+), 40 deletions(-)
diff --git a/configurations/notify-failure.nix b/configurations/notify-failure.nix @@ -1,30 +0,0 @@ -{ config, lib, pkgs, ... }: - -{ - - age.secrets.password-leah-at-f2k1-de.file = ../secrets/passwords/leah-at-f2k1-de.age; - - programs.msmtp = { - enable = true; - accounts = { - default = { - auth = true; - tls = true; - host = "rx300.kunbox.net"; - port = 587; - user = "leah@f2k1.de"; - from = "${config.networking.fqdn} <leah@f2k1.de>"; - passwordeval = "cat ${config.age.secrets.password-leah-at-f2k1-de.path}"; - }; - }; - }; - - systemd.services."notify-failure@" = { - serviceConfig = { - ExecStart = '' - ${pkgs.runtimeShell} -c "{ echo -n 'Subject:[${config.networking.fqdn}] Service failed: %i\n\n' & ${pkgs.systemd}/bin/systemctl status %i;} | ${pkgs.msmtp}/bin/msmtp -v notify@ctu.cx" - ''; - }; - }; - -}
diff --git a/machines/desastro/configuration.nix b/machines/desastro/configuration.nix @@ -9,8 +9,6 @@ imports = [ ./hardware-configuration.nix - ../../configurations/notify-failure.nix - ../../configurations/services/prometheus-node-exporter.nix ../../configurations/services/restic-server.nix @@ -83,7 +81,8 @@ }; services = { - vnstat.enable = true; + email-notify.enable = true; + vnstat.enable = true; deluge = { enable = false; openFirewall = true;
diff --git a/machines/hector/configuration.nix b/machines/hector/configuration.nix @@ -9,8 +9,6 @@ imports = [ ./hardware-configuration.nix - ../../configurations/notify-failure.nix - ../../configurations/services/prometheus-node-exporter.nix ../../configurations/services/restic-server.nix ]; @@ -47,6 +45,8 @@ firewall.enable = true; }; + services.email-notify.enable = true; + systemd.services.restic.serviceConfig.ReadWritePaths = [ "/data/restic" ]; system.stateVersion = "21.11";
diff --git a/machines/lollo/configuration.nix b/machines/lollo/configuration.nix @@ -9,8 +9,6 @@ imports = [ ./hardware-configuration.nix - ../../configurations/notify-failure.nix - ../../configurations/services/prometheus-node-exporter.nix ./router ./smarthome @@ -18,6 +16,7 @@ ../../configurations/programs/usbmuxd.nix + ../../configurations/services/prometheus-node-exporter.nix ../../configurations/services/restic-server.nix ./syncthing.nix ./restic-vnstat.nix @@ -40,6 +39,7 @@ domain = "ctu.cx"; useDHCP = false; }; + services.email-notify.enable = true; users.users.leah.extraGroups = [ "audio" ];
diff --git a/machines/osterei/configuration.nix b/machines/osterei/configuration.nix @@ -9,8 +9,6 @@ imports = [ ./hardware-configuration.nix - ../../configurations/notify-failure.nix - # dns server ../../configurations/services/bind @@ -77,6 +75,7 @@ networking = { hostName = "osterei"; domain = "ctu.cx"; + services.email-notify.enable = true; useDHCP = false;
diff --git a/modules/default.nix b/modules/default.nix @@ -4,10 +4,11 @@ imports = (builtins.concatLists [ (if (currentSystem == "x86_64-linux") then [ + inputs.agenix.nixosModule ./restic-backups.nix ./vnstati ./desktop-speakers.nix - inputs.agenix.nixosModule + ./email-notify.nix ] else []) (if (currentSystem == "aarch64-darwin") then [ ./darwin/quirks.nix
diff --git a/modules/email-notify.nix b/modules/email-notify.nix @@ -0,0 +1,34 @@ +{ pkgs, lib, config, ... }: + +{ + + options.services.email-notify.enable = lib.mkEnableOption "Enable a service which can be used to send emails"; + + config = lib.mkIf config.services.email-notify.enable { + age.secrets.password-leah-at-f2k1-de.file = ../secrets/passwords/leah-at-f2k1-de.age; + + programs.msmtp = { + enable = true; + accounts = { + default = { + auth = true; + tls = true; + host = "rx300.kunbox.net"; + port = 587; + user = "leah@f2k1.de"; + from = "${config.networking.fqdn} <leah@f2k1.de>"; + passwordeval = "cat ${config.age.secrets.password-leah-at-f2k1-de.path}"; + }; + }; + }; + + systemd.services."email-notify@" = { + serviceConfig = { + ExecStart = '' + ${pkgs.runtimeShell} -c "{ echo -n 'Subject:[${config.networking.fqdn}] Service failed: %i\n\n' & ${pkgs.systemd}/bin/systemctl status %i;} | ${pkgs.msmtp}/bin/msmtp -v notify@ctu.cx" + ''; + }; + }; + }; + +}