mirror of
https://github.com/tomasriveral/nixos.git
synced 2026-08-12 10:30:44 +02:00
setup agenix and migrate from matrix-commander-rs to ntfy for phone notifications
This commit is contained in:
@@ -289,7 +289,6 @@
|
|||||||
"custom-checkKdrive && custom-mountkdrive" # checks if the remote works and mount it
|
"custom-checkKdrive && custom-mountkdrive" # checks if the remote works and mount it
|
||||||
#"waybar"
|
#"waybar"
|
||||||
"custom-gitnotify"
|
"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/)
|
#"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
|
#"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
|
"sleep 4 & caelestia-shell" #works better if it sleeps a bit before
|
||||||
|
|||||||
@@ -48,11 +48,12 @@
|
|||||||
name = "custom-checkKdrive";
|
name = "custom-checkKdrive";
|
||||||
runtimeInputs = with pkgs; [
|
runtimeInputs = with pkgs; [
|
||||||
rclone
|
rclone
|
||||||
matrix-commander-rs
|
curl
|
||||||
libnotify
|
libnotify
|
||||||
];
|
];
|
||||||
text = ''
|
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
|
# 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 || \
|
until ping -c1 -W1 1.1.1.1 >/dev/null 2>&1 || \
|
||||||
ping -c1 -W1 8.8.8.8 >/dev/null 2>&1
|
ping -c1 -W1 8.8.8.8 >/dev/null 2>&1
|
||||||
@@ -72,9 +73,11 @@
|
|||||||
else
|
else
|
||||||
echo "kdrive rclone failed with error: $output"
|
echo "kdrive rclone failed with error: $output"
|
||||||
notify-send "rclone kdrive failed" "$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>" \
|
curl \
|
||||||
--html \
|
-u ":$NTFY_TOKEN" \
|
||||||
-r "\!BXRRokBmEdNOyYdfOF:matrix.org"
|
-d "Rclone couldnt access kdrive (rclone lsd kdrive). Error: $output" \
|
||||||
|
-H "Title: Rclone kdrive" \
|
||||||
|
"$NTFY_SERVER/Alerts"
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,8 +2,12 @@
|
|||||||
flake.nixosModules.autoCleanup-laptop = {
|
flake.nixosModules.autoCleanup-laptop = {
|
||||||
pkgs,
|
pkgs,
|
||||||
pkgs-unstable,
|
pkgs-unstable,
|
||||||
|
config,
|
||||||
...
|
...
|
||||||
}: {
|
}: {
|
||||||
|
age.secrets.ntfy = {
|
||||||
|
file = ../../secrets/ntfy.age;
|
||||||
|
};
|
||||||
# Ensure your script is available system-wide
|
# Ensure your script is available system-wide
|
||||||
environment.systemPackages = [
|
environment.systemPackages = [
|
||||||
self.packages.${pkgs.system}.custom-cleanNix-laptop
|
self.packages.${pkgs.system}.custom-cleanNix-laptop
|
||||||
@@ -17,6 +21,9 @@
|
|||||||
description = "NixOS configuration auto cleanup";
|
description = "NixOS configuration auto cleanup";
|
||||||
|
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
|
Environment = [
|
||||||
|
"NTFY_SECRET=${config.age.secrets.ntfy.path}"
|
||||||
|
];
|
||||||
Type = "oneshot";
|
Type = "oneshot";
|
||||||
|
|
||||||
ExecStart = "/run/current-system/sw/bin/custom-cleanNix";
|
ExecStart = "/run/current-system/sw/bin/custom-cleanNix";
|
||||||
@@ -54,8 +61,12 @@
|
|||||||
flake.nixosModules.autoCleanup-desktop = {
|
flake.nixosModules.autoCleanup-desktop = {
|
||||||
pkgs,
|
pkgs,
|
||||||
pkgs-unstable,
|
pkgs-unstable,
|
||||||
|
config,
|
||||||
...
|
...
|
||||||
}: {
|
}: {
|
||||||
|
age.secrets.ntfy = {
|
||||||
|
file = ../../secrets/ntfy.age;
|
||||||
|
};
|
||||||
# Ensure your script is available system-wide
|
# Ensure your script is available system-wide
|
||||||
environment.systemPackages = [
|
environment.systemPackages = [
|
||||||
self.packages.${pkgs.system}.custom-cleanNix-desktop
|
self.packages.${pkgs.system}.custom-cleanNix-desktop
|
||||||
@@ -69,6 +80,9 @@
|
|||||||
description = "NixOS configuration auto cleanup";
|
description = "NixOS configuration auto cleanup";
|
||||||
|
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
|
Environment = [
|
||||||
|
"NTFY_SECRET=${config.age.secrets.ntfy.path}"
|
||||||
|
];
|
||||||
Type = "oneshot";
|
Type = "oneshot";
|
||||||
|
|
||||||
ExecStart = "/run/current-system/sw/bin/custom-cleanNix";
|
ExecStart = "/run/current-system/sw/bin/custom-cleanNix";
|
||||||
@@ -108,7 +122,7 @@
|
|||||||
runtimeInputs = with pkgs; [
|
runtimeInputs = with pkgs; [
|
||||||
git
|
git
|
||||||
nixos-rebuild
|
nixos-rebuild
|
||||||
matrix-commander-rs
|
curl
|
||||||
libnotify
|
libnotify
|
||||||
alejandra
|
alejandra
|
||||||
deadnix
|
deadnix
|
||||||
@@ -117,6 +131,9 @@
|
|||||||
text = ''
|
text = ''
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
# shellcheck disable=SC1090
|
||||||
|
source "$NTFY_SECRET"
|
||||||
|
|
||||||
FLAKE_DIR="/home/tomasr/nixos"
|
FLAKE_DIR="/home/tomasr/nixos"
|
||||||
FLAKE="$FLAKE_DIR#laptop"
|
FLAKE="$FLAKE_DIR#laptop"
|
||||||
TIME=$(date -u +"%Y-%m-%dT%H-%M-%SZ")
|
TIME=$(date -u +"%Y-%m-%dT%H-%M-%SZ")
|
||||||
@@ -148,9 +165,11 @@
|
|||||||
|
|
||||||
notify-send "Nix auto cleanup" "Everything OK"
|
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>" \
|
curl \
|
||||||
--html \
|
-u ":$NTFY_TOKEN" \
|
||||||
-r "\!BXRRokBmEdNOyYdfOF:matrix.org"
|
-d "Everything OK" \
|
||||||
|
-H "Title: Laptop Nix auto cleanup" \
|
||||||
|
"$NTFY_SERVER/Alerts"
|
||||||
else
|
else
|
||||||
notify-send "Nix auto cleanup" "No changes"
|
notify-send "Nix auto cleanup" "No changes"
|
||||||
git -C "$FLAKE_DIR" push
|
git -C "$FLAKE_DIR" push
|
||||||
@@ -161,9 +180,11 @@
|
|||||||
|
|
||||||
notify-send -u critical "Nix auto cleanup" "FAILED"
|
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>" \
|
curl \
|
||||||
--html \
|
-u ":$NTFY_TOKEN" \
|
||||||
-r "\!BXRRokBmEdNOyYdfOF:matrix.org"
|
-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"
|
git -C "$FLAKE_DIR" reset --hard "pre-cleanup-$TIME"
|
||||||
fi
|
fi
|
||||||
@@ -178,7 +199,7 @@
|
|||||||
runtimeInputs = with pkgs; [
|
runtimeInputs = with pkgs; [
|
||||||
git
|
git
|
||||||
nixos-rebuild
|
nixos-rebuild
|
||||||
matrix-commander-rs
|
curl
|
||||||
libnotify
|
libnotify
|
||||||
alejandra
|
alejandra
|
||||||
deadnix
|
deadnix
|
||||||
@@ -187,6 +208,9 @@
|
|||||||
text = ''
|
text = ''
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
# shellcheck disable=SC1090
|
||||||
|
source "$NTFY_SECRET"
|
||||||
|
|
||||||
FLAKE_DIR="/home/tomasr/nixos"
|
FLAKE_DIR="/home/tomasr/nixos"
|
||||||
FLAKE="$FLAKE_DIR#desktop"
|
FLAKE="$FLAKE_DIR#desktop"
|
||||||
TIME=$(date -u +"%Y-%m-%dT%H-%M-%SZ")
|
TIME=$(date -u +"%Y-%m-%dT%H-%M-%SZ")
|
||||||
@@ -218,9 +242,11 @@
|
|||||||
|
|
||||||
notify-send "Nix auto cleanup" "Everything OK"
|
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>" \
|
curl \
|
||||||
--html \
|
-u ":$NTFY_TOKEN" \
|
||||||
-r "\!BXRRokBmEdNOyYdfOF:matrix.org"
|
-d "Everything OK" \
|
||||||
|
-H "Title: Desktop Nix auto cleanup" \
|
||||||
|
"$NTFY_SERVER/Alerts"
|
||||||
else
|
else
|
||||||
notify-send "Nix auto cleanup" "No changes"
|
notify-send "Nix auto cleanup" "No changes"
|
||||||
git -C "$FLAKE_DIR" push
|
git -C "$FLAKE_DIR" push
|
||||||
@@ -231,9 +257,11 @@
|
|||||||
|
|
||||||
notify-send -u critical "Nix auto cleanup" "FAILED"
|
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>" \
|
curl \
|
||||||
--html \
|
-u ":$NTFY_TOKEN" \
|
||||||
-r "\!BXRRokBmEdNOyYdfOF:matrix.org"
|
-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"
|
git -C "$FLAKE_DIR" reset --hard "pre-cleanup-$TIME"
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -118,7 +118,7 @@
|
|||||||
text = ''
|
text = ''
|
||||||
# shellcheck disable=SC1090
|
# shellcheck disable=SC1090
|
||||||
source "$NTFY_SECRET"
|
source "$NTFY_SECRET"
|
||||||
set -ex
|
set -e
|
||||||
|
|
||||||
FLAKE_DIR="/home/tomasr/nixos"
|
FLAKE_DIR="/home/tomasr/nixos"
|
||||||
FLAKE="$FLAKE_DIR#laptop"
|
FLAKE="$FLAKE_DIR#laptop"
|
||||||
@@ -145,7 +145,7 @@
|
|||||||
|
|
||||||
curl \
|
curl \
|
||||||
-u ":$NTFY_TOKEN" \
|
-u ":$NTFY_TOKEN" \
|
||||||
-d "Flake rebuild successful" \
|
-d "Laptop Flake rebuild successful" \
|
||||||
-H "Title: Flake autoupdate" \
|
-H "Title: Flake autoupdate" \
|
||||||
"$NTFY_SERVER/Alerts"
|
"$NTFY_SERVER/Alerts"
|
||||||
else
|
else
|
||||||
@@ -160,7 +160,7 @@
|
|||||||
|
|
||||||
curl \
|
curl \
|
||||||
-u ":$NTFY_TOKEN" \
|
-u ":$NTFY_TOKEN" \
|
||||||
-d "Flake rebuild failed. Error: $ERROR_MSG" \
|
-d "Laptop Flake rebuild failed. Error: $ERROR_MSG" \
|
||||||
-H "Title: Flake autoupdate FAILED" \
|
-H "Title: Flake autoupdate FAILED" \
|
||||||
-H "Priority: urgent" \
|
-H "Priority: urgent" \
|
||||||
"$NTFY_SERVER/Alerts"
|
"$NTFY_SERVER/Alerts"
|
||||||
@@ -215,7 +215,7 @@
|
|||||||
curl \
|
curl \
|
||||||
-u ":$NTFY_TOKEN" \
|
-u ":$NTFY_TOKEN" \
|
||||||
-d "Flake rebuild successful" \
|
-d "Flake rebuild successful" \
|
||||||
-H "Title: Flake autoupdate" \
|
-H "Title: Desktop Flake autoupdate" \
|
||||||
"$NTFY_SERVER/Alerts"
|
"$NTFY_SERVER/Alerts"
|
||||||
|
|
||||||
else
|
else
|
||||||
@@ -231,7 +231,7 @@
|
|||||||
curl \
|
curl \
|
||||||
-u ":$NTFY_TOKEN" \
|
-u ":$NTFY_TOKEN" \
|
||||||
-d "Flake rebuild failed. Error: $ERROR_MSG" \
|
-d "Flake rebuild failed. Error: $ERROR_MSG" \
|
||||||
-H "Title: Flake autoupdate FAILED" \
|
-H "Title: Desktop Flake autoupdate FAILED" \
|
||||||
-H "Priority: urgent" \
|
-H "Priority: urgent" \
|
||||||
"$NTFY_SERVER/Alerts"
|
"$NTFY_SERVER/Alerts"
|
||||||
|
|
||||||
|
|||||||
@@ -3,44 +3,26 @@
|
|||||||
environment.systemPackages = with pkgs; [
|
environment.systemPackages = with pkgs; [
|
||||||
libnotify # Library that sends desktop notifications to a notification daemon
|
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)
|
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
|
# battery notifications
|
||||||
self.packages.${pkgs.system}.custom-batterynotify
|
self.packages.${pkgs.system}.custom-batterynotify
|
||||||
self.packages.${pkgs.system}.custom-batterywarning
|
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-gitnotify # checks if git is set up
|
||||||
self.packages.${pkgs.system}.custom-checkKdrive # check if kdrive is set up with rclone
|
self.packages.${pkgs.system}.custom-checkKdrive # check if kdrive is set up with rclone
|
||||||
zoom-us
|
zoom-us
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
perSystem = {pkgs, ...}: {
|
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 {
|
packages.custom-gitnotify = pkgs.writeShellApplication {
|
||||||
name = "custom-gitnotify";
|
name = "custom-gitnotify";
|
||||||
runtimeInputs = with pkgs; [
|
runtimeInputs = with pkgs; [
|
||||||
git
|
git
|
||||||
libnotify
|
libnotify
|
||||||
|
curl
|
||||||
];
|
];
|
||||||
text = ''
|
text = ''
|
||||||
|
# shellcheck disable=SC1091
|
||||||
|
source /run/agenix/ntfy
|
||||||
|
|
||||||
# Check if git is installed
|
# Check if git is installed
|
||||||
if ! command -v git >/dev/null 2>&1; then
|
if ! command -v git >/dev/null 2>&1; then
|
||||||
exit 0
|
exit 0
|
||||||
@@ -53,9 +35,10 @@
|
|||||||
notify-send \
|
notify-send \
|
||||||
"Git not configured" \
|
"Git not configured" \
|
||||||
"Set your identity\n or remove this warning by removing the custom-gitnotify line in\n ~/nixos/modules/applications/hyprland.nix"
|
"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>" \
|
curl \
|
||||||
--html \
|
-u ":$NTFY_TOKEN" \
|
||||||
-r "\!BXRRokBmEdNOyYdfOF:matrix.org"
|
-d "Git not configured" \
|
||||||
|
"$NTFY_SERVER/Alerts"
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
{self, ...}: {
|
{self, ...}: {
|
||||||
flake.nixosModules.gitBackup = {pkgs, ...}: {
|
flake.nixosModules.gitBackup = {pkgs, config, ...}: {
|
||||||
|
age.secrets.ntfy = {
|
||||||
|
file = ../../secrets/ntfy.age;
|
||||||
|
};
|
||||||
environment.systemPackages = [
|
environment.systemPackages = [
|
||||||
self.packages.${pkgs.system}.custom-gitBackup
|
self.packages.${pkgs.system}.custom-gitBackup
|
||||||
];
|
];
|
||||||
@@ -9,6 +12,9 @@
|
|||||||
|
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "oneshot";
|
Type = "oneshot";
|
||||||
|
Environment = [
|
||||||
|
"NTFY_SECRET=${config.age.secrets.ntfy.path}"
|
||||||
|
];
|
||||||
|
|
||||||
ExecStart = "/run/current-system/sw/bin/custom-gitBackup";
|
ExecStart = "/run/current-system/sw/bin/custom-gitBackup";
|
||||||
|
|
||||||
@@ -41,11 +47,14 @@
|
|||||||
name = "custom-gitBackup";
|
name = "custom-gitBackup";
|
||||||
runtimeInputs = with pkgs; [
|
runtimeInputs = with pkgs; [
|
||||||
rsync
|
rsync
|
||||||
matrix-commander-rs
|
curl
|
||||||
libnotify
|
libnotify
|
||||||
self.packages.${pkgs.system}.custom-checkKdrive
|
self.packages.${pkgs.system}.custom-checkKdrive
|
||||||
];
|
];
|
||||||
text = ''
|
text = ''
|
||||||
|
# shellcheck disable=SC1090
|
||||||
|
source "$NTFY_SECRET"
|
||||||
|
|
||||||
# checks if kdrive is available
|
# checks if kdrive is available
|
||||||
custom-checkKdrive
|
custom-checkKdrive
|
||||||
|
|
||||||
@@ -69,9 +78,11 @@
|
|||||||
notify_error() {
|
notify_error() {
|
||||||
local message="$1"
|
local message="$1"
|
||||||
notify-send "Git Backup Failed" "$message"
|
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>" \
|
curl \
|
||||||
--html \
|
-u ":$NTFY_TOKEN" \
|
||||||
-r "\!BXRRokBmEdNOyYdfOF:matrix.org"
|
-d "Git backup failed. Error: $message" \
|
||||||
|
-H "Title: Git Backup" \
|
||||||
|
"$NTFY_SERVER/Alerts"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user