aboutsummaryrefslogtreecommitdiff
path: root/modules/scripts/pushover/default.nix
diff options
context:
space:
mode:
authortdback <tyler@tdback.net>2024-12-21 15:32:13 -0500
committertdback <tyler@tdback.net>2024-12-21 15:32:13 -0500
commit0a5754541bb01e96021ca7ee74f1256a8ee68bc4 (patch)
tree2d0b8089e98239963a1e240cff676b1515fc8431 /modules/scripts/pushover/default.nix
initial commit to self-hosted git
Diffstat (limited to 'modules/scripts/pushover/default.nix')
-rw-r--r--modules/scripts/pushover/default.nix47
1 files changed, 47 insertions, 0 deletions
diff --git a/modules/scripts/pushover/default.nix b/modules/scripts/pushover/default.nix
new file mode 100644
index 0000000..f20a5be
--- /dev/null
+++ b/modules/scripts/pushover/default.nix
@@ -0,0 +1,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 ];
+}