From cc2e44afefe1134b98ac162f340a0deaab52d2a7 Mon Sep 17 00:00:00 2001 From: Tomas Rivera Date: Fri, 15 May 2026 14:48:23 +0200 Subject: [PATCH] flake: autoupdate 2026-05-15T12-48-16Z --- flake.lock | 6 ++-- hosts/laptop/home.nix | 6 ++++ hostsModules/laptop/scripts/autoUpdate.nix | 40 +++++++++++++++++++++ hostsModules/laptop/scripts/checkMatrix.nix | 21 +++++++++++ modules/home-manager/hyprland.nix | 1 + 5 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 hostsModules/laptop/scripts/autoUpdate.nix create mode 100644 hostsModules/laptop/scripts/checkMatrix.nix diff --git a/flake.lock b/flake.lock index 8627806..d53e0c1 100755 --- a/flake.lock +++ b/flake.lock @@ -119,11 +119,11 @@ }, "nixpkgs-unstable": { "locked": { - "lastModified": 1778551015, - "narHash": "sha256-j299xXVjlKs5WtVkKSgEXZGvpTTw5X2iWwKs4KWv/Ag=", + "lastModified": 1778794387, + "narHash": "sha256-BL04pOS9453Awkeb9f90XBJXBSkWxN+vB7HIgnL0iMM=", "owner": "nixos", "repo": "nixpkgs", - "rev": "0a0bf409f3593f415d0a554f33acc63dc7dccb43", + "rev": "8a1b0127302ea51e05bf4ea5a291743fac442406", "type": "github" }, "original": { diff --git a/hosts/laptop/home.nix b/hosts/laptop/home.nix index 236732d..d23d07e 100755 --- a/hosts/laptop/home.nix +++ b/hosts/laptop/home.nix @@ -68,6 +68,12 @@ (pkgs.callPackage ../../modules/scripts/dontkillsteam.nix {}) # kill app (if it is steam put it in some background (pkgs.callPackage ../../hostsModules/laptop/scripts/batterynotify.nix {}) (pkgs.callPackage ../../hostsModules/laptop/scripts/batterywarning.nix {}) + + # checks if matrix-commander-rs is installed and logged in + (pkgs.callPackage ../../hostsModules/laptop/scripts/checkMatrix.nix {}) + # autoupdate the flake and send notification to system and to matrix + (pkgs.callPackage ../../hostsModules/laptop/scripts/autoUpdate.nix {}) + (pkgs.callPackage ../../modules/scripts/weather.nix {}) (pkgs.callPackage ../../modules/scripts/wallpaper.nix {}) (pkgs.callPackage ../../modules/scripts/mountkdrive.nix {}) diff --git a/hostsModules/laptop/scripts/autoUpdate.nix b/hostsModules/laptop/scripts/autoUpdate.nix new file mode 100644 index 0000000..cd80e8f --- /dev/null +++ b/hostsModules/laptop/scripts/autoUpdate.nix @@ -0,0 +1,40 @@ +{ + pkgs, + ... +}: +pkgs.writeShellApplication { + name = "custom-autoupdate"; + + runtimeInputs = with pkgs; [ + git + nixos-rebuild + matrix-commander-rs + libnotify + ]; + + text = '' + set -e + + FLAKE_DIR="/home/tomasr/nixos" + FLAKE="$FLAKE_DIR#laptop" + TIME=$(date -u +"%Y-%m-%dT%H-%M-%SZ") + + git -C "$FLAKE_DIR" pull + git -C "$FLAKE_DIR" tag "pre-autoupdate-$TIME" + + nix flake update --flake "$FLAKE_DIR" + + if sudo nixos-rebuild switch --flake "$FLAKE"; then + git -C "$FLAKE_DIR" add flake.lock + git -C "$FLAKE_DIR" commit -m "flake: autoupdate $TIME" + git -C "$FLAKE_DIR" push + + notify-send "Flake autoupdate" "Rebuild OK" + matrix-commander-rs -m "Flake rebuild OK" + else + notify-send -u critical "Flake autoupdate" "FAILED" + matrix-commander-rs -m "Flake rebuild FAILED" + git reset --hard "pre-autoupdate-$TIME" + fi + ''; +} diff --git a/hostsModules/laptop/scripts/checkMatrix.nix b/hostsModules/laptop/scripts/checkMatrix.nix new file mode 100644 index 0000000..177ca7a --- /dev/null +++ b/hostsModules/laptop/scripts/checkMatrix.nix @@ -0,0 +1,21 @@ +{ pkgs }: + +pkgs.writeShellApplication { + name = "custom-checkMatrix"; + + runtimeInputs = [ + pkgs.matrix-commander-rs + pkgs.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 + ''; +} diff --git a/modules/home-manager/hyprland.nix b/modules/home-manager/hyprland.nix index 4d9643b..4e08037 100644 --- a/modules/home-manager/hyprland.nix +++ b/modules/home-manager/hyprland.nix @@ -218,6 +218,7 @@ in { "custom-mountkdrive" #"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