From 413045c20be81b4e95e7113378ed5e24c11374a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vili=20Sinerv=C3=A4?= Date: Fri, 6 Sep 2024 22:07:26 +0300 Subject: [PATCH] Add ntfy notifications for nixos services --- base.nix | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/base.nix b/base.nix index 51bdf70..932a84f 100644 --- a/base.nix +++ b/base.nix @@ -145,6 +145,37 @@ }; }; + # Define systemd template unit for reporting status via ntfy + systemd.services = + let + services = [ + "nixos-upgrade" + "nix-gc" + "nix-optimize" + ]; + in + { + "notify-push@" = { + environment.SERVICE_ID = "%i"; + path = [ + "/run/wrappers" + "/run/current-system/sw" + ]; + script = '' + curl \ + -H "Title:$(hostname) $SERVICE_ID $(systemctl show --property=Result $SERVICE_ID)" \ + -d "$(journalctl --output cat -n 10 -u $SERVICE_ID)" \ + https://ntfy.vsinerva.fi/service-notifs + ''; + }; + + # Merge attributes for all monitored services + } + // (pkgs.lib.attrsets.genAttrs services (name: { + onFailure = pkgs.lib.mkBefore [ "notify-push@%i.service" ]; + onSuccess = pkgs.lib.mkBefore [ "notify-push@%i.service" ]; + })); + ######################################## Misc. ################################################## nixpkgs.config.allowUnfree = true;