Commit 8c23553ed573
Changed files (7)
dots
home
common
desktop
sway
systems
kyushu
dots/.config/ntfy/acknowledge-notification.sh
@@ -0,0 +1,34 @@
+#!/usr/bin/env bash
+# Acknowledge (delete) the last ntfy notification
+# This script is called when right-clicking a notification in mako
+
+set -euo pipefail
+
+STATEFILE="/tmp/ntfy-last-message"
+LOGFILE="/tmp/ntfy-actions.log"
+
+# Log the action
+echo "[$(date '+%Y-%m-%d %H:%M:%S')] Acknowledge action triggered" >> "$LOGFILE"
+
+# Check if we have a message to acknowledge
+if [[ ! -f "$STATEFILE" ]]; then
+ echo "[$(date '+%Y-%m-%d %H:%M:%S')] ERROR: No message to acknowledge" >> "$LOGFILE"
+ notify-send -a ntfy "Error" "No message to acknowledge"
+ exit 1
+fi
+
+# Read message details
+# shellcheck source=/dev/null
+source "$STATEFILE"
+
+echo "[$(date '+%Y-%m-%d %H:%M:%S')] Acknowledging message: $TOPIC/$ID" >> "$LOGFILE"
+
+# Delete the message from ntfy server
+if curl -s -X DELETE "https://ntfy.sbr.pm/$TOPIC/$ID" \
+ -H "Authorization: Bearer $(passage show home/ntfy/token)" \
+ >> "$LOGFILE" 2>&1; then
+ echo "[$(date '+%Y-%m-%d %H:%M:%S')] Successfully deleted message" >> "$LOGFILE"
+ rm -f "$STATEFILE"
+else
+ echo "[$(date '+%Y-%m-%d %H:%M:%S')] Failed to delete message" >> "$LOGFILE"
+fi
dots/.config/ntfy/client.yml.in
@@ -0,0 +1,15 @@
+# ntfy client configuration for self-hosted instance
+# This is a template file - use ntfy-update-config to generate the actual client.yml
+
+# Default server for all commands
+default-host: https://ntfy.sbr.pm
+
+# Default authentication token (injected from passage)
+default-token: "passage::home/ntfy/token"
+
+# Subscribe configuration
+subscribe:
+ - topic: homelab
+ command: ~/.config/ntfy/handle-notification.sh
+ if:
+ priority: high,urgent
dots/.config/ntfy/handle-notification.sh
@@ -0,0 +1,22 @@
+#!/usr/bin/env bash
+# Handle incoming ntfy notification
+# This script is called by ntfy for each incoming message
+# It stores the message details and displays the notification
+
+set -euo pipefail
+
+# Store message details for later acknowledgment
+STATEFILE="/tmp/ntfy-last-message"
+
+# These variables (topic, id, title, message) are provided by ntfy as environment variables
+# shellcheck disable=SC2154
+cat >"$STATEFILE" <<EOF
+TOPIC=$topic
+ID=$id
+TITLE=$title
+MESSAGE=$message
+EOF
+
+# Display notification via mako
+# shellcheck disable=SC2154
+notify-send -a ntfy "$title" "$message"
dots/.config/ntfy/ntfy-update-config
@@ -0,0 +1,57 @@
+#!/usr/bin/env bash
+# Script to update the ntfy configuration from client.yml.in
+# Based on aichat-update-config pattern
+
+export PATH=$PATH:/run/current-system/sw/bin
+export PASSAGE_DIR=/home/vincent/.local/share/passage
+export PASSAGE_IDENTITIES_FILE=/home/vincent/.local/share/passage/identities
+
+# Define the input and output file names
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+INPUT_FILE="${SCRIPT_DIR}/client.yml.in"
+OUTPUT_FILE="${HOME}/.config/ntfy/client.yml"
+
+# Check if the input file exists
+if [ ! -f "$INPUT_FILE" ]; then
+ echo "Error: Input file '$INPUT_FILE' not found."
+ exit 1
+fi
+
+# Create the output directory if it doesn't exist
+mkdir -p "$(dirname "$OUTPUT_FILE")"
+
+# Create an empty output file
+: >"$OUTPUT_FILE"
+
+# Read the input file line by line
+while IFS= read -r line; do
+ # Regex to find "passage::" followed by characters that are NOT a double quote or whitespace,
+ # until a double quote or whitespace is encountered.
+ if [[ "$line" =~ passage::([^\"]+) ]]; then
+ # The full string that needs to be replaced in the line (including "passage::")
+ passage_full_string="passage::${BASH_REMATCH[1]}"
+
+ # The string to pass to the 'passage show' command (without "passage::" or quotes)
+ passage_string_for_command=$(echo "${BASH_REMATCH[1]%\"}" | xargs)
+
+ echo "Found passage key in line: $passage_full_string"
+ echo "Executing command: passage show \"$passage_string_for_command\""
+
+ # Execute the passage command and capture its output
+ if passage_output=$(passage show "$passage_string_for_command" 2>/dev/null | tr -d '\n\r' | xargs) && [ -n "$passage_output" ]; then
+ # Replace the passage placeholder with the actual value
+ modified_line="${line//"$passage_full_string"/"$passage_output"}"
+
+ echo "Modified line: $modified_line"
+ echo "$modified_line" >>"$OUTPUT_FILE"
+ else
+ echo "Warning: 'passage show $passage_string_for_command' failed or returned empty. Keeping original line."
+ echo "$line" >>"$OUTPUT_FILE"
+ fi
+ else
+ # If no "passage::" found, write the original line
+ echo "$line" >>"$OUTPUT_FILE"
+ fi
+done <"$INPUT_FILE"
+
+echo "Processing complete. ntfy client configuration written to '$OUTPUT_FILE'."
dots/Makefile
@@ -29,21 +29,19 @@ claude-plugins : ~/.config/claude/plugins/session-manager
claude-statusline : ~/.config/claude/statusline.sh
claude-compat : ~/.claude
+all += ntfy-config
+ntfy-config : ~/.config/ntfy/client.yml
+
# Backward compatibility: symlink ~/.claude to ~/.config/claude
~/.claude : force
@echo "๐ Creating backward compatibility symlink: ~/.claude -> ~/.config/claude"
@mkdir -p ~/.config
@ln -snf ~/.config/claude ~/.claude
-# Example: Override default rule to generate content instead of copying
-# Uncomment and customize this pattern for files that should be generated:
-#
-# ~/.config/example/generated.conf : force
-# @echo "โ๏ธ Generating $$@"
-# @mkdir -p $(@D)
-# @echo "# Generated on $$(date)" > $@
-# @echo "setting1=value1" >> $@
-# @echo "setting2=value2" >> $@
+# Generate ntfy client.yml from template with passage secrets injected
+~/.config/ntfy/client.yml : $(dotfiles)/.config/ntfy/client.yml.in $(dotfiles)/.config/ntfy/ntfy-update-config force
+ @echo "โ๏ธ Generating $$@ from template with passage secrets"
+ @$(dotfiles)/.config/ntfy/ntfy-update-config
all : $(all)
@echo "โ
All dotfiles installed!"
home/common/desktop/sway/mako.nix
@@ -8,7 +8,7 @@ _: {
width = 400;
on-button-left = "dismiss";
on-button-middle = "invoke-default-action";
- on-button-right = "dismiss";
+ on-button-right = "invoke-action=ack";
border-radius = 6;
border-size = 3;
border-color = "#db7508";
@@ -42,6 +42,14 @@ _: {
anchor = "center";
format = "<b>%s</b>\\n%b";
};
+ # ntfy notifications - distinct blue theme
+ "app-name=\"ntfy\"" = {
+ background-color = "#1a2332";
+ text-color = "#e0e0e0";
+ border-color = "#4a90e2";
+ border-size = 3;
+ default-timeout = 10000;
+ };
"mode=do-not-disturb" = {
invisible = 1;
};
systems/kyushu/home.nix
@@ -32,6 +32,7 @@ in
calibre
ntfy-sh
+ libnotify
monolith # TODO: move into =desktop= ?
@@ -82,4 +83,33 @@ in
darkTime = "19:00"; # Switch to dark mode at 7pm
};
+ # ntfy notification subscriber
+ systemd.user.services.ntfy-subscriber = {
+ Unit = {
+ Description = "ntfy notification subscriber";
+ Documentation = "https://ntfy.sh";
+ After = [
+ "graphical-session.target"
+ "network-online.target"
+ ];
+ Wants = [ "network-online.target" ];
+ };
+
+ Service = {
+ Type = "simple";
+ ExecStart = "${pkgs.ntfy-sh}/bin/ntfy subscribe --from-config";
+ Restart = "on-failure";
+ RestartSec = 10;
+ Environment = [
+ "PATH=${pkgs.bash}/bin:${pkgs.libnotify}/bin:${pkgs.ntfy-sh}/bin:${pkgs.xdg-utils}/bin:${pkgs.curl}/bin:${pkgs.passage}/bin"
+ "PASSAGE_DIR=/home/vincent/.local/share/passage"
+ "PASSAGE_IDENTITIES_FILE=/home/vincent/.local/share/passage/identities"
+ ];
+ };
+
+ Install = {
+ WantedBy = [ "graphical-session.target" ];
+ };
+ };
+
}