From 999c3b78be5d427234dfeaa26136e2882ed690e1 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sun, 30 Jul 2017 18:22:55 +0200 Subject: Send mail when nixos-upgrade failed --- ymir.nix | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/ymir.nix b/ymir.nix index 3c0db516..9a9dc7d8 100644 --- a/ymir.nix +++ b/ymir.nix @@ -898,4 +898,33 @@ in rec { git -C /etc/nixos pull git -C /etc/nixos submodule update ''; + systemd.services."nixos-upgrade".onFailure = "unit-status-mail@%n.service"; + + systemd.services."unit-status-mail@" = { + scriptArgs = "%I %H %m %b"; + script = '' + #!${stdenv.shell} + MAILTO="root" + MAILFROM="unit-status-mailer" + UNIT=$1 + + EXTRA="" + for e in "${@:2}"; do + EXTRA+="$e"$'\n' + done + + UNITSTATUS=$(systemctl status $UNIT) + + sendmail $MAILTO <