Update git-auto-update.nix
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
mode = "0700";
|
mode = "0700";
|
||||||
text = ''
|
text = ''
|
||||||
#!/run/current-system/sw/bin/bash
|
#!/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 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"
|
export NIX_PATH="nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos"
|
||||||
@@ -17,24 +17,19 @@
|
|||||||
mkdir -p "$LOCAL_PATH"
|
mkdir -p "$LOCAL_PATH"
|
||||||
chmod 700 "$LOCAL_PATH"
|
chmod 700 "$LOCAL_PATH"
|
||||||
git clone "$REPO_URL" "$LOCAL_PATH"
|
git clone "$REPO_URL" "$LOCAL_PATH"
|
||||||
exit 0
|
else
|
||||||
fi
|
cd "$LOCAL_PATH"
|
||||||
|
git fetch origin
|
||||||
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
|
git reset --hard origin/main
|
||||||
nixos-rebuild boot -I nixos-config="$LOCAL_PATH/configuration.nix"
|
|
||||||
fi
|
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 = {
|
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";
|
script = "/etc/nix-git-auto-update.sh";
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "oneshot";
|
Type = "oneshot";
|
||||||
@@ -48,7 +43,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
systemd.timers.nix-git-auto-update = {
|
systemd.timers.nix-git-auto-update = {
|
||||||
description = "Periodic NixOS Git update check";
|
description = "Periodic NixOS Git update check (always rebuild)";
|
||||||
wantedBy = [ "timers.target" ];
|
wantedBy = [ "timers.target" ];
|
||||||
timerConfig = {
|
timerConfig = {
|
||||||
OnBootSec = "60s";
|
OnBootSec = "60s";
|
||||||
|
|||||||
Reference in New Issue
Block a user