aboutsummaryrefslogtreecommitdiff
path: root/modules/notifications/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'modules/notifications/default.nix')
-rw-r--r--modules/notifications/default.nix50
1 files changed, 50 insertions, 0 deletions
diff --git a/modules/notifications/default.nix b/modules/notifications/default.nix
new file mode 100644
index 0000000..8447a1e
--- /dev/null
+++ b/modules/notifications/default.nix
@@ -0,0 +1,50 @@
+{ pkgs, lib, ... }:
+let
+ ntfyCfg = {
+ default-host = "http://192.168.0.117:3142";
+ subscribe = [
+ {
+ topic = "media_update";
+ command = ''${notify} "$title" "$message"'';
+ }
+ {
+ topic = "ping";
+ command = ''${notify} "PING: $title" "$message"'';
+ }
+ {
+ topic = "jellyseer";
+ command = ''${notify} "$(echo "$m" | ${jq} -r .title)" "$(echo "$m" | ${jq} -r .body)"'';
+ }
+ {
+ topic = "grafana_alert";
+ command = ''${notify} "Grafana alert" "$message"'';
+ }
+ ];
+ };
+ sudo = "${pkgs.sudo}/bin/sudo";
+ jq = "${pkgs.jq}/bin/jq";
+ notify = "${sudo} -u imsohexy ${pkgs.libnotify}/bin/notify-send -a ntfy";
+in
+{
+ environment.systemPackages = with pkgs; [ ntfy-sh ];
+
+ systemd.services.ntfy-client = {
+ unitConfig = {
+ Description = "ntfy client";
+ After = "network.service";
+ };
+
+ serviceConfig = let
+ ntfyCfgFile = pkgs.writeText "client.yml" (lib.generators.toYAML {} ntfyCfg);
+ in {
+ ExecStart = "${pkgs.ntfy-sh}/bin/ntfy subscribe --config ${ntfyCfgFile} --from-config";
+ Restart = "on-failure";
+ Environment = lib.concatStringsSep " " [
+ "PATH=${pkgs.dbus}/bin:${pkgs.libnotify}/bin:/bin:/usr/bin"
+ "DISPLAY=:0"
+ ];
+ };
+
+ wantedBy = ["multi-user.target"];
+ };
+}