aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hosts/sagittarius/auto-update.nix16
1 files changed, 14 insertions, 2 deletions
diff --git a/hosts/sagittarius/auto-update.nix b/hosts/sagittarius/auto-update.nix
index 4e8c2ac..fbc7dae 100644
--- a/hosts/sagittarius/auto-update.nix
+++ b/hosts/sagittarius/auto-update.nix
@@ -29,7 +29,7 @@ in
enableStrictShellChecks = true;
script = ''
#!/bin/sh
- set -xeu
+ set -eu
SRCREPO="$1"
if [ -z "$SRCREPO" ]; then
@@ -43,7 +43,7 @@ in
pushd "$TEMPDIR"
TAGS="$(git tag --sort tag --list 'v*')"
- LATESTTAG="$(echo "$TAGS" | head --lines 1)"
+ LATESTTAG="$(echo "$TAGS" | tail --lines 1)"
if [ -z "$LATESTTAG" ]; then
echo "Error: no release tags defined." >&2
@@ -53,6 +53,18 @@ in
git fetch "$SRCREPO" "$LATESTTAG"
git checkout FETCH_HEAD
+ CURRENT_REV="$(git rev-parse HEAD)"
+ mkdir -p /var/lib/auto-update/
+
+ if [ -e /var/lib/auto-update/last-commit ]; then
+ LAST_REV="$(cat /var/lib/auto-update/last-commit)"
+ if [ "$CURRENT_REV" = "$LAST_REV" ]; then
+ echo "System is already up to date. Exiting." >&2
+ exit 0
+ fi
+ fi
+ echo -n "$CURRENT_REV" > /var/lib/auto-update/last-commit
+
nixos-rebuild switch --flake .#
popd