pull-update: use writeShellApplication instead

This commit is contained in:
2026-04-16 15:02:08 -04:00
parent d2d25bbdfe
commit 982cc4aebc

View File

@@ -7,50 +7,53 @@
let let
deploy-url = "https://nix-cache.sigkill.computer/deploy/${hostname}"; deploy-url = "https://nix-cache.sigkill.computer/deploy/${hostname}";
pull-update = pkgs.writeShellScript "pull-update" '' pull-update = pkgs.writeShellApplication {
set -uo pipefail name = "pull-update";
export PATH=${
pkgs.lib.makeBinPath [
pkgs.curl
pkgs.coreutils
pkgs.nix
pkgs.systemd
pkgs.util-linux
]
}
# wait for actual connectivity, not just networkd "up" runtimeInputs = with pkgs; [
for i in $(seq 1 30); do pkgs.curl
if curl -sf --max-time 5 "${deploy-url}" >/dev/null; then pkgs.coreutils
break pkgs.nix
pkgs.systemd
pkgs.util-linux
];
text = ''
set -uo pipefail
# wait for actual connectivity, not just networkd "up"
for i in $(seq 1 30); do
if curl -sf --max-time 5 "${deploy-url}" >/dev/null; then
break
fi
echo "Waiting for network... ($i/30)"
sleep 2
done
STORE_PATH=$(curl -sf --max-time 30 "${deploy-url}" || true)
if [ -z "$STORE_PATH" ]; then
echo "Server unreachable or no deployment available, skipping"
exit 0
fi fi
echo "Waiting for network... ($i/30)"
sleep 2
done
STORE_PATH=$(curl -sf --max-time 30 "${deploy-url}" || true) CURRENT=$(readlink -f /nix/var/nix/profiles/system)
if [ "$CURRENT" = "$STORE_PATH" ]; then
echo "Already on latest configuration"
exit 0
fi
if [ -z "$STORE_PATH" ]; then echo "Update available: $CURRENT -> $STORE_PATH"
echo "Server unreachable or no deployment available, skipping"
exit 0
fi
CURRENT=$(readlink -f /nix/var/nix/profiles/system) nix-store -r "$STORE_PATH" || { echo "Failed to fetch closure"; exit 1; }
if [ "$CURRENT" = "$STORE_PATH" ]; then nix-env -p /nix/var/nix/profiles/system --set "$STORE_PATH" || { echo "Failed to set profile"; exit 1; }
echo "Already on latest configuration" "$STORE_PATH/bin/switch-to-configuration" boot || { echo "Failed to install boot entry"; exit 1; }
exit 0
fi
echo "Update available: $CURRENT -> $STORE_PATH" wall "System update installed. Rebooting in 10 seconds..."
sleep 10
nix-store -r "$STORE_PATH" || { echo "Failed to fetch closure"; exit 1; } systemctl reboot
nix-env -p /nix/var/nix/profiles/system --set "$STORE_PATH" || { echo "Failed to set profile"; exit 1; } '';
"$STORE_PATH/bin/switch-to-configuration" boot || { echo "Failed to install boot entry"; exit 1; } };
wall "System update installed. Rebooting in 10 seconds..."
sleep 10
systemctl reboot
'';
in in
{ {
systemd.services.pull-update = { systemd.services.pull-update = {