aboutsummaryrefslogtreecommitdiff
path: root/modules/notifications/default.nix
blob: 8447a1e0a812fc749f284eef20b8722bdfc8dd70 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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"];
  };
}