diff --git a/features/homey-alert/default.nix b/features/homey-alert/default.nix new file mode 100644 index 0000000..c3783f8 --- /dev/null +++ b/features/homey-alert/default.nix @@ -0,0 +1,84 @@ +{...}: { + config.flake.modules.homeManager.homey-alert = { + lib, + config, + pkgs, + ... + }: { + options.azos.homey-alert.enable = lib.mkOption { + default = false; + example = true; + type = lib.types.bool; + }; + + config = lib.mkIf config.azos.homey-alert.enable { + home.packages = [ + (pkgs.writeShellApplication { + name = "homey-alert"; + runtimeInputs = with pkgs; [curl pass]; + text = '' + usage() { + cat <&2; usage >&2; exit 1 ;; + *) break ;; + esac + done + + if [[ $# -gt 0 ]]; then + MESSAGE="$*" + elif [[ ! -t 0 ]]; then + MESSAGE="$(cat)" + else + echo "homey-alert: no message provided" >&2 + usage >&2 + exit 1 + fi + + TOKEN="$(pass zakobar-homecenter/ntfy-token)" + + HEADERS=( + -H "Authorization: Bearer $TOKEN" + -H "Priority: $PRIORITY" + ) + + [[ -n "$TITLE" ]] && HEADERS+=(-H "Title: $TITLE") + [[ -n "$TAGS" ]] && HEADERS+=(-H "Tags: $TAGS") + + curl -sf "''${HEADERS[@]}" \ + -d "$MESSAGE" \ + https://ntfy.zakobar.com/alerts + ''; + }) + ]; + }; + }; +} diff --git a/home-manager/home.nix b/home-manager/home.nix index 733512c..be486f4 100755 --- a/home-manager/home.nix +++ b/home-manager/home.nix @@ -34,6 +34,7 @@ suiteModules.homeManager.roam-backup suiteModules.homeManager.ytdl suiteModules.homeManager.chess + suiteModules.homeManager.homey-alert ]; programs.home-manager.enable = true; @@ -59,6 +60,7 @@ ]; azos.roam-backup.enable = true; + azos.homey-alert.enable = true; home = { username = "aner";