aboutsummaryrefslogtreecommitdiff
path: root/modules/scripts/pushover/default.nix
blob: f20a5be1e3adda24e854baf8b5c5e561f549e714 (plain)
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
{ inputs, config, pkgs, ... }:
let
  pushover =
    pkgs.writeShellScriptBin "pushover" ''
      #!/bin/sh

      die() { echo "$0: $*" >&2; exit 111; }

      APP=$(cat ${config.age.secrets.pushoverAppToken.path})
      USER=$(cat ${config.age.secrets.pushoverUserToken.path})

      while getopts ":t:" args; do
        case "$args" in
          t)
            TITLE="$OPTARG"
            ;;
          :)
            die "missing option argument for -$OPTARG"
            ;;
          *)
            die "invalid option -$OPTARG"
            ;;
        esac
      done
      shift $((OPTIND - 1))

      MESSAGE="$*"
      if [ -z "$MESSAGE" ] || [ "$MESSAGE" = " " ]; then
        MESSAGE="No errors to report."
      fi

      /run/current-system/sw/bin/curl -s \
        --form-string "token=$APP" \
        --form-string "user=$USER" \
        --form-string "title=$TITLE" \
        --form-string "message=$MESSAGE" \
        https://api.pushover.net/1/messages.json
    '';
in
{
  age.secrets = {
    pushoverAppToken.file = "${inputs.self}/secrets/pushoverAppToken.age";
    pushoverUserToken.file = "${inputs.self}/secrets/pushoverUserToken.age";
  };

  environment.systemPackages = [ pushover ];
}