diff --git a/git-auto-update.nix b/git-auto-update.nix index 53da1d2..d24948f 100644 --- a/git-auto-update.nix +++ b/git-auto-update.nix @@ -5,7 +5,7 @@ mode = "0700"; text = '' #!/run/current-system/sw/bin/bash - set -e + set -euo pipefail export PATH="/run/current-system/sw/bin:/nix/var/nix/profiles/default/bin" export NIX_PATH="nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos" @@ -17,24 +17,19 @@ mkdir -p "$LOCAL_PATH" chmod 700 "$LOCAL_PATH" git clone "$REPO_URL" "$LOCAL_PATH" - exit 0 - fi - - cd "$LOCAL_PATH" - - git fetch origin - LOCAL_HEAD=$(git rev-parse HEAD) - REMOTE_HEAD=$(git rev-parse origin/main) - - if [ "$LOCAL_HEAD" != "$REMOTE_HEAD" ]; then + else + cd "$LOCAL_PATH" + git fetch origin git reset --hard origin/main - nixos-rebuild boot -I nixos-config="$LOCAL_PATH/configuration.nix" fi + + # Always rebuild — nixos-rebuild will do nothing if system is already up-to-date + nixos-rebuild boot -I nixos-config="$LOCAL_PATH/configuration.nix" ''; }; systemd.services.nix-git-auto-update = { - description = "Automatically update NixOS from Git"; + description = "Automatically update NixOS from Git (always rebuild)"; script = "/etc/nix-git-auto-update.sh"; serviceConfig = { Type = "oneshot"; @@ -48,7 +43,7 @@ }; systemd.timers.nix-git-auto-update = { - description = "Periodic NixOS Git update check"; + description = "Periodic NixOS Git update check (always rebuild)"; wantedBy = [ "timers.target" ]; timerConfig = { OnBootSec = "60s";