diff --git a/common/ntfy/default.nix b/common/ntfy/default.nix index b67d848..e5c8ac1 100644 --- a/common/ntfy/default.nix +++ b/common/ntfy/default.nix @@ -19,6 +19,12 @@ default = ""; description = "Extra arguments to pass to curl (e.g. --proxy http://host:port)."; }; + + ignoredUnits = lib.mkOption { + type = lib.types.listOf lib.types.str; + default = [ ]; + description = "Unit names to skip failure notifications for."; + }; }; config = lib.mkIf config.thisMachine.hasRole."ntfy" { diff --git a/common/ntfy/service-failure.nix b/common/ntfy/service-failure.nix index 66f63b8..b7f5ab1 100644 --- a/common/ntfy/service-failure.nix +++ b/common/ntfy/service-failure.nix @@ -14,6 +14,12 @@ in EnvironmentFile = "/run/agenix/ntfy-token"; ExecStart = "${pkgs.writeShellScript "ntfy-failure-notify" '' unit="$1" + ignored_units=(${lib.concatMapStringsSep " " (u: lib.escapeShellArg u) cfg.ignoredUnits}) + for ignored in "''${ignored_units[@]}"; do + if [[ "$unit" == "$ignored" ]]; then + exit 0 + fi + done logfile=$(mktemp) trap 'rm -f "$logfile"' EXIT ${pkgs.systemd}/bin/journalctl -u "$unit" -n 50 --no-pager -o short > "$logfile" 2>/dev/null \ diff --git a/machines/storage/s0/default.nix b/machines/storage/s0/default.nix index bf06eec..99bc512 100644 --- a/machines/storage/s0/default.nix +++ b/machines/storage/s0/default.nix @@ -9,6 +9,8 @@ networking.hostName = "s0"; + ntfy-alerts.ignoredUnits = [ "logrotate" ]; + # system.autoUpgrade.enable = true; nix.gc.automatic = lib.mkForce false; # allow the nix store to serve as a build cache