From a8ecc2cfa18eefe5dfd0b242deeec451233888af Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Tue, 15 Apr 2025 08:26:52 +0200 Subject: [PATCH] feat(services): add systemd email notification module Introduce a NixOS module for sending service status emails on failures via systemd. The module provides configurable options for email recipients and integrates with the `sendmail` utility to notify admins about service issues. --- .../services/systemd-email-notify/default.nix | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 modules/nixos/services/systemd-email-notify/default.nix diff --git a/modules/nixos/services/systemd-email-notify/default.nix b/modules/nixos/services/systemd-email-notify/default.nix new file mode 100644 index 0000000..2a812ee --- /dev/null +++ b/modules/nixos/services/systemd-email-notify/default.nix @@ -0,0 +1,73 @@ +{ + config, + lib, + pkgs, + ... +}: + +with lib; + +let + checkConditions = pkgs.writeScript "checkConditions" '' + #!/bin/sh + STATUS=$(systemctl status --full "$1") + + case "$STATUS" in + *"activating (auto-restart) (Result: timeout)"*) exit 1 ;; + *) exit 0 ;; + esac + ''; + + sendmail = pkgs.writeScript "sendmail" '' + #!/bin/sh + + ${pkgs.system-sendmail}/bin/sendmail -t <