Add ntfy notifications for nixos services

This commit is contained in:
Vili Sinervä 2024-09-06 22:07:26 +03:00
parent 60975bdacc
commit 413045c20b
No known key found for this signature in database
GPG key ID: DF8FEAF54EFAC996

View file

@ -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. ################################################## ######################################## Misc. ##################################################
nixpkgs.config.allowUnfree = true; nixpkgs.config.allowUnfree = true;