-
-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
Trying to resholve this script.
notifyScript = resholve.writeScript "matterhorn-notify-script" {
inputs = [jq libnotify coreutils which];
interpreter = "${bash}/bin/bash";
} (builtins.readFile ./notifyV2);jq and notify-send are not substituted in has function call, leading to script failure (jq/notify-send are not found obviously). Tried to use fix but it does nothing. Currently using keep and replaceStrings as a fallback, but it's quite hacky. Is this a bug?
Invalid output
#!/nix/store/vqvj60h076bhqj6977caz0pfxs6543nb-bash-5.2-p15/bin/bash
# This is the sample Linux notifier for V2 notifications.
# The notification payload is a JSON object presented to standard input,
# having the fields version, sender, message and mentioned. Note that
# the JSON data is always UTF-8 encoded. The script is responsible for
# decoding it to Unicode.
# This script depends upon `jq(1)` to extract fields from the JSON
# notification and upon `notify-send(1)` to invoke the system notifier.
# See docs/notification-scripts.md for further details.
PGM="`/nix/store/apn3p2b40xvirn7w740wv2gy330ppib5-coreutils-9.3/bin/basename $0`"
function fail {
echo $PGM: "$@" >/dev/stderr
exit 1
}
# Confirm presence of `jq(1)` and `notify-send(1)`.'
function has {
/nix/store/zw7zyp8nng1gqwbn1wc16yrwf3zg2zcc-which-2.21/bin/which $1 >/dev/null 2>&1
}
has jq || fail 'jq(1) is required but not present'
has notify-send || fail 'notify-send(1) is required but not present'
# Extract the data to be notified. The data is in a JSON payload at stdin.
json=`/nix/store/apn3p2b40xvirn7w740wv2gy330ppib5-coreutils-9.3/bin/cat`
version=`echo $json|/nix/store/aj8lqifsyynq8iknivvxkrsqnblj7qzs-jq-1.6-bin/bin/jq -Mr .version`
[ "$version" = 2 ] || fail 'JSON payload has wrong version'
sender=`echo $json|/nix/store/aj8lqifsyynq8iknivvxkrsqnblj7qzs-jq-1.6-bin/bin/jq -Mr .from`
message=`echo $json|/nix/store/aj8lqifsyynq8iknivvxkrsqnblj7qzs-jq-1.6-bin/bin/jq -Mr .message`
mentioned=`echo $json|/nix/store/aj8lqifsyynq8iknivvxkrsqnblj7qzs-jq-1.6-bin/bin/jq -Mr .mention`
# Now prepare the notification. The logic is essentially the same as for
# the V1 notifier.
# Configure the notifier.
ns_URGENCY_GENERAL=normal # none, low, normal or critical
ns_URGENCY_MENTIONED=normal # none, low, normal or critical
ns_CATEGORY=im.received
ns_HEADER="Matterhorn message from @$sender"
ns_BODY="$message"
case "$mentioned" in
false) ns_URGENCY=$ns_URGENCY_GENERAL ;;
true) ns_URGENCY=$ns_URGENCY_MENTIONED ;;
*) fail "mentioned: invalid value: $mentioned" ;;
esac
# Emit the notification.
case "$ns_URGENCY" in
none) ;;
low|normal|critical)
/nix/store/5xx01m9hw51zd6pm1vp7rpdkp9fng4by-libnotify-0.8.2/bin/notify-send -u $ns_URGENCY -c $ns_CATEGORY -- "$ns_HEADER" "$ns_BODY" ;;
*) fail "urgency not recognized: $ns_URGENCY" ;;
esac
# Log the JSON notification payload. To enable, define NOTIFY_JSON_LOG as
# a path to a file. The file need not exist; the directory must be writable.
NOTIFY_JSON_LOG=
[ -n "$NOTIFY_JSON_LOG" ] && {
echo `/nix/store/apn3p2b40xvirn7w740wv2gy330ppib5-coreutils-9.3/bin/date -Iminutes` $json >> $NOTIFY_JSON_LOG
}
true
### resholve directives (auto-generated) ## format_version: 3
# resholve: keep /nix/store/5xx01m9hw51zd6pm1vp7rpdkp9fng4by-libnotify-0.8.2/bin/notify-send
# resholve: keep /nix/store/aj8lqifsyynq8iknivvxkrsqnblj7qzs-jq-1.6-bin/bin/jq
# resholve: keep /nix/store/apn3p2b40xvirn7w740wv2gy330ppib5-coreutils-9.3/bin/basename
# resholve: keep /nix/store/apn3p2b40xvirn7w740wv2gy330ppib5-coreutils-9.3/bin/cat
# resholve: keep /nix/store/apn3p2b40xvirn7w740wv2gy330ppib5-coreutils-9.3/bin/date
# resholve: keep /nix/store/zw7zyp8nng1gqwbn1wc16yrwf3zg2zcc-which-2.21/bin/which
Metadata
Metadata
Assignees
Labels
No labels