diff --git a/hosts/yarn/default.nix b/hosts/yarn/default.nix index 777b4d4..65217fe 100644 --- a/hosts/yarn/default.nix +++ b/hosts/yarn/default.nix @@ -98,15 +98,26 @@ pkgs.nix ] } + STORE_PATH=$(curl -sf --max-time 30 "https://nix-cache.sigkill.computer/deploy/yarn" || true) if [ -z "$STORE_PATH" ]; then echo "server unreachable" exit 1 fi - echo "applying $STORE_PATH" - nix-store -r "$STORE_PATH" || { echo "fetch failed"; exit 1; } - nix-env -p /nix/var/nix/profiles/system --set "$STORE_PATH" || { echo "profile set failed"; exit 1; } - "$STORE_PATH/bin/switch-to-configuration" boot || { echo "boot entry failed"; exit 1; } + + CURRENT=$(readlink -f /nix/var/nix/profiles/system) + if [ "$CURRENT" = "$STORE_PATH" ]; then + echo "already up to date: $STORE_PATH" + exit 0 + fi + + echo "applying $STORE_PATH (was $CURRENT)" + nix-store -r --add-root /nix/var/nix/gcroots/pull-update-apply-latest --indirect "$STORE_PATH" \ + || { echo "fetch failed"; exit 1; } + nix-env -p /nix/var/nix/profiles/system --set "$STORE_PATH" \ + || { echo "profile set failed"; exit 1; } + "$STORE_PATH/bin/switch-to-configuration" boot \ + || { echo "boot entry failed"; exit 1; } echo "update applied; reboot required" ''; };