setup agenix and migrate from matrix-commander-rs to ntfy for phone notifications

This commit is contained in:
2026-07-26 15:53:57 +02:00
parent 2107d23209
commit 5db8135dd5
6 changed files with 99 additions and 62 deletions
-1
View File
@@ -289,7 +289,6 @@
"custom-checkKdrive && custom-mountkdrive" # checks if the remote works and mount it
#"waybar"
"custom-gitnotify"
"custom-checkMatrix" # checks if matrix-commander-rs is connected which is important for other stuff
#"custom-obsidianbackup" # backups the obsidian notes to kdrive and to a timed hidden dir (~/.Notes.backup/)
#"QS-notifycache" # builds the cache that will be used for the notification history
"sleep 4 & caelestia-shell" #works better if it sleeps a bit before
+8 -5
View File
@@ -48,11 +48,12 @@
name = "custom-checkKdrive";
runtimeInputs = with pkgs; [
rclone
matrix-commander-rs
curl
libnotify
];
text = ''
# shellcheck disable=SC1091
source /run/agenix/ntfy
# waits for an internet connection. It pings both Google DNS and Cloudfare dns in case one of them is down
until ping -c1 -W1 1.1.1.1 >/dev/null 2>&1 || \
ping -c1 -W1 8.8.8.8 >/dev/null 2>&1
@@ -72,9 +73,11 @@
else
echo "kdrive rclone failed with error: $output"
notify-send "rclone kdrive failed" "$output"
matrix-commander-rs --verbose -m "rclone kdrive failed.<br>Error: <pre>$output</pre><br><a href=\"https://matrix.to/#/@notificationbot_0000:matrix.org\">@notificationbot_0000</a>" \
--html \
-r "\!BXRRokBmEdNOyYdfOF:matrix.org"
curl \
-u ":$NTFY_TOKEN" \
-d "Rclone couldnt access kdrive (rclone lsd kdrive). Error: $output" \
-H "Title: Rclone kdrive" \
"$NTFY_SERVER/Alerts"
fi
'';
};
+42 -14
View File
@@ -2,8 +2,12 @@
flake.nixosModules.autoCleanup-laptop = {
pkgs,
pkgs-unstable,
config,
...
}: {
age.secrets.ntfy = {
file = ../../secrets/ntfy.age;
};
# Ensure your script is available system-wide
environment.systemPackages = [
self.packages.${pkgs.system}.custom-cleanNix-laptop
@@ -17,6 +21,9 @@
description = "NixOS configuration auto cleanup";
serviceConfig = {
Environment = [
"NTFY_SECRET=${config.age.secrets.ntfy.path}"
];
Type = "oneshot";
ExecStart = "/run/current-system/sw/bin/custom-cleanNix";
@@ -54,8 +61,12 @@
flake.nixosModules.autoCleanup-desktop = {
pkgs,
pkgs-unstable,
config,
...
}: {
age.secrets.ntfy = {
file = ../../secrets/ntfy.age;
};
# Ensure your script is available system-wide
environment.systemPackages = [
self.packages.${pkgs.system}.custom-cleanNix-desktop
@@ -69,6 +80,9 @@
description = "NixOS configuration auto cleanup";
serviceConfig = {
Environment = [
"NTFY_SECRET=${config.age.secrets.ntfy.path}"
];
Type = "oneshot";
ExecStart = "/run/current-system/sw/bin/custom-cleanNix";
@@ -108,7 +122,7 @@
runtimeInputs = with pkgs; [
git
nixos-rebuild
matrix-commander-rs
curl
libnotify
alejandra
deadnix
@@ -117,6 +131,9 @@
text = ''
set -e
# shellcheck disable=SC1090
source "$NTFY_SECRET"
FLAKE_DIR="/home/tomasr/nixos"
FLAKE="$FLAKE_DIR#laptop"
TIME=$(date -u +"%Y-%m-%dT%H-%M-%SZ")
@@ -148,9 +165,11 @@
notify-send "Nix auto cleanup" "Everything OK"
matrix-commander-rs --verbose -m "Nix auto cleanup. Everything OK.<br><a href=\"https://matrix.to/#/@notificationbot_0000:matrix.org\">@notificationbot_0000</a>" \
--html \
-r "\!BXRRokBmEdNOyYdfOF:matrix.org"
curl \
-u ":$NTFY_TOKEN" \
-d "Everything OK" \
-H "Title: Laptop Nix auto cleanup" \
"$NTFY_SERVER/Alerts"
else
notify-send "Nix auto cleanup" "No changes"
git -C "$FLAKE_DIR" push
@@ -161,9 +180,11 @@
notify-send -u critical "Nix auto cleanup" "FAILED"
matrix-commander-rs --verbose -m "Nix auto cleanup failed.<br>Error: <pre>$ERROR_MSG</pre><br><a href=\"https://matrix.to/#/@notificationbot_0000:matrix.org\">@notificationbot_0000</a>" \
--html \
-r "\!BXRRokBmEdNOyYdfOF:matrix.org"
curl \
-u ":$NTFY_TOKEN" \
-d "Nix auto cleanup failed. Error: $ERROR_MSG" \
-H "Title: Laptop Nix auto cleanup" \
"$NTFY_SERVER/Alerts"
git -C "$FLAKE_DIR" reset --hard "pre-cleanup-$TIME"
fi
@@ -178,7 +199,7 @@
runtimeInputs = with pkgs; [
git
nixos-rebuild
matrix-commander-rs
curl
libnotify
alejandra
deadnix
@@ -187,6 +208,9 @@
text = ''
set -e
# shellcheck disable=SC1090
source "$NTFY_SECRET"
FLAKE_DIR="/home/tomasr/nixos"
FLAKE="$FLAKE_DIR#desktop"
TIME=$(date -u +"%Y-%m-%dT%H-%M-%SZ")
@@ -218,9 +242,11 @@
notify-send "Nix auto cleanup" "Everything OK"
matrix-commander-rs --verbose -m "Nix auto cleanup. Everything OK.<br><a href=\"https://matrix.to/#/@notificationbot_0000:matrix.org\">@notificationbot_0000</a>" \
--html \
-r "\!BXRRokBmEdNOyYdfOF:matrix.org"
curl \
-u ":$NTFY_TOKEN" \
-d "Everything OK" \
-H "Title: Desktop Nix auto cleanup" \
"$NTFY_SERVER/Alerts"
else
notify-send "Nix auto cleanup" "No changes"
git -C "$FLAKE_DIR" push
@@ -231,9 +257,11 @@
notify-send -u critical "Nix auto cleanup" "FAILED"
matrix-commander-rs --verbose -m "Nix auto cleanup failed.<br>Error: <pre>$ERROR_MSG</pre><br><a href=\"https://matrix.to/#/@notificationbot_0000:matrix.org\">@notificationbot_0000</a>" \
--html \
-r "\!BXRRokBmEdNOyYdfOF:matrix.org"
curl \
-u ":$NTFY_TOKEN" \
-d "Nix auto cleanup failed. Error: $ERROR_MSG" \
-H "Title: Desktop Nix auto cleanup" \
"$NTFY_SERVER/Alerts"
git -C "$FLAKE_DIR" reset --hard "pre-cleanup-$TIME"
fi
+25 -12
View File
@@ -103,6 +103,8 @@
];
text = ''
# shellcheck disable=SC1090
source "$NTFY_SECRET"
set -e
FLAKE_DIR="/home/tomasr/nixos"
@@ -128,9 +130,11 @@
notify-send "Flake autoupdate" "Rebuild OK"
matrix-commander-rs --verbose -m "Flake rebuild succesfull.<br><a href=\"https://matrix.to/#/@notificationbot_0000:matrix.org\">@notificationbot_0000</a>" \
--html \
-r "\!BXRRokBmEdNOyYdfOF:matrix.org"
curl \
-u ":$NTFY_TOKEN" \
-d "Laptop Flake rebuild successful" \
-H "Title: Flake autoupdate" \
"$NTFY_SERVER/Alerts"
else
notify-send "Flake autoupdate" "No changes"
git -C "$FLAKE_DIR" push
@@ -141,9 +145,12 @@
notify-send -u critical "Flake autoupdate" "FAILED"
matrix-commander-rs --verbose -m "Flake rebuild failed.<br>Error: <pre>$ERROR_MSG</pre><br><a href=\"https://matrix.to/#/@notificationbot_0000:matrix.org\">@notificationbot_0000</a>" \
--html \
-r "\!BXRRokBmEdNOyYdfOF:matrix.org"
curl \
-u ":$NTFY_TOKEN" \
-d "Laptop Flake rebuild failed. Error: $ERROR_MSG" \
-H "Title: Flake autoupdate FAILED" \
-H "Priority: urgent" \
"$NTFY_SERVER/Alerts"
git -C "$FLAKE_DIR" reset --hard "pre-autoupdate-$TIME"
fi
@@ -189,9 +196,12 @@
notify-send "Flake autoupdate" "Rebuild OK"
matrix-commander-rs --verbose -m "Flake rebuild succesfull.<br><a href=\"https://matrix.to/#/@notificationbot_0000:matrix.org\">@notificationbot_0000</a>" \
--html \
-r "\!BXRRokBmEdNOyYdfOF:matrix.org"
curl \
-u ":$NTFY_TOKEN" \
-d "Flake rebuild successful" \
-H "Title: Desktop Flake autoupdate" \
"$NTFY_SERVER/Alerts"
else
notify-send "Flake autoupdate" "No changes"
git -C "$FLAKE_DIR" push
@@ -202,9 +212,12 @@
notify-send -u critical "Flake autoupdate" "FAILED"
matrix-commander-rs --verbose -m "Flake rebuild failed.<br>Error: <pre>$ERROR_MSG</pre><br><a href=\"https://matrix.to/#/@notificationbot_0000:matrix.org\">@notificationbot_0000</a>" \
--html \
-r "\!BXRRokBmEdNOyYdfOF:matrix.org"
curl \
-u ":$NTFY_TOKEN" \
-d "Flake rebuild failed. Error: $ERROR_MSG" \
-H "Title: Desktop Flake autoupdate FAILED" \
-H "Priority: urgent" \
"$NTFY_SERVER/Alerts"
git -C "$FLAKE_DIR" reset --hard "pre-autoupdate-$TIME"
fi
@@ -3,44 +3,26 @@
environment.systemPackages = with pkgs; [
libnotify # Library that sends desktop notifications to a notification daemon
socat # Utility for bidirectional data transfer between two independent data channels (used to communicate between hyprland and awww to change wallpapers dinamically)
matrix-commander-rs # matrix client used to send notifications from scripts to my phone
# battery notifications
self.packages.${pkgs.system}.custom-batterynotify
self.packages.${pkgs.system}.custom-batterywarning
# checks if matrix-commander-rs is installed and logged in
self.packages.${pkgs.system}.custom-checkMatrix
self.packages.${pkgs.system}.custom-gitnotify # checks if git is set up
self.packages.${pkgs.system}.custom-checkKdrive # check if kdrive is set up with rclone
zoom-us
];
};
perSystem = {pkgs, ...}: {
packages.custom-checkMatrix = pkgs.writeShellApplication {
name = "custom-checkMatrix";
runtimeInputs = with pkgs; [
matrix-commander-rs
libnotify
];
text = ''
expected="@totorile1:unredacted.org"
current="$(matrix-commander-rs --whoami | tr -d '\n')"
if [ "$current" != "$expected" ]; then
notify-send "matrix-commander-rs" \
"You are not logged in as @totorile1:unredacted.org\nLog:\n$current"
fi
'';
};
packages.custom-gitnotify = pkgs.writeShellApplication {
name = "custom-gitnotify";
runtimeInputs = with pkgs; [
git
libnotify
curl
];
text = ''
# shellcheck disable=SC1091
source /run/agenix/ntfy
# Check if git is installed
if ! command -v git >/dev/null 2>&1; then
exit 0
@@ -53,9 +35,10 @@
notify-send \
"Git not configured" \
"Set your identity\n or remove this warning by removing the custom-gitnotify line in\n ~/nixos/modules/applications/hyprland.nix"
matrix-commander-rs --verbose -m "Git not configured.<br>Set your identify or remove this warning by removing the custom-gitnotify in ~/nixos/modules/applications/hyprland.nix<br><a href=\"https://matrix.to/#/@notificationbot_0000:matrix.org\">@notificationbot_0000</a>" \
--html \
-r "\!BXRRokBmEdNOyYdfOF:matrix.org"
curl \
-u ":$NTFY_TOKEN" \
-d "Git not configured" \
"$NTFY_SERVER/Alerts"
fi
'';
};
+16 -5
View File
@@ -1,5 +1,8 @@
{self, ...}: {
flake.nixosModules.gitBackup = {pkgs, ...}: {
flake.nixosModules.gitBackup = {pkgs, config, ...}: {
age.secrets.ntfy = {
file = ../../secrets/ntfy.age;
};
environment.systemPackages = [
self.packages.${pkgs.system}.custom-gitBackup
];
@@ -9,6 +12,9 @@
serviceConfig = {
Type = "oneshot";
Environment = [
"NTFY_SECRET=${config.age.secrets.ntfy.path}"
];
ExecStart = "/run/current-system/sw/bin/custom-gitBackup";
@@ -41,11 +47,14 @@
name = "custom-gitBackup";
runtimeInputs = with pkgs; [
rsync
matrix-commander-rs
curl
libnotify
self.packages.${pkgs.system}.custom-checkKdrive
];
text = ''
# shellcheck disable=SC1090
source "$NTFY_SECRET"
# checks if kdrive is available
custom-checkKdrive
@@ -69,9 +78,11 @@
notify_error() {
local message="$1"
notify-send "Git Backup Failed" "$message"
matrix-commander-rs --verbose -m "Git Backup Failed: $message <br><a href=\"https://matrix.to/#/@notificationbot_0000:matrix.org\">@notificationbot_0000</a>" \
--html \
-r "\!BXRRokBmEdNOyYdfOF:matrix.org"
curl \
-u ":$NTFY_TOKEN" \
-d "Git backup failed. Error: $message" \
-H "Title: Git Backup" \
"$NTFY_SERVER/Alerts"
}