Add ntfy notifications for nixos services
This commit is contained in:
parent
60975bdacc
commit
413045c20b
1 changed files with 31 additions and 0 deletions
31
base.nix
31
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;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue