aboutsummaryrefslogtreecommitdiff
path: root/modules/scripts/pushover/default.nix
blob: a5644e487797fa316d7791e0ac9c45f233f5ed62 (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
{ inputs, config, pkgs, ... }:
let
  pushover = pkgs.writeShellScriptBin "pushover" ''
    set -e

    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"
          ;;
        :)
          echo "missing option argument for -$OPTARG" >&2
          exit 1
          ;;
        *)
          echo "invalid option -$OPTARG" >&2
          exit 1
          ;;
      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 ];
}