Update git-auto-update.nix

This commit is contained in:
ska
2026-01-06 20:06:50 +00:00
parent 3a3bc3a9e5
commit f4024aa40b

View File

@@ -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
else
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
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";