pull-update: use writeShellApplication instead
This commit is contained in:
@@ -7,50 +7,53 @@
|
||||
let
|
||||
deploy-url = "https://nix-cache.sigkill.computer/deploy/${hostname}";
|
||||
|
||||
pull-update = pkgs.writeShellScript "pull-update" ''
|
||||
set -uo pipefail
|
||||
export PATH=${
|
||||
pkgs.lib.makeBinPath [
|
||||
pkgs.curl
|
||||
pkgs.coreutils
|
||||
pkgs.nix
|
||||
pkgs.systemd
|
||||
pkgs.util-linux
|
||||
]
|
||||
}
|
||||
pull-update = pkgs.writeShellApplication {
|
||||
name = "pull-update";
|
||||
|
||||
# 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
|
||||
runtimeInputs = with pkgs; [
|
||||
pkgs.curl
|
||||
pkgs.coreutils
|
||||
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
|
||||
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 "Server unreachable or no deployment available, skipping"
|
||||
exit 0
|
||||
fi
|
||||
echo "Update available: $CURRENT -> $STORE_PATH"
|
||||
|
||||
CURRENT=$(readlink -f /nix/var/nix/profiles/system)
|
||||
if [ "$CURRENT" = "$STORE_PATH" ]; then
|
||||
echo "Already on latest configuration"
|
||||
exit 0
|
||||
fi
|
||||
nix-store -r "$STORE_PATH" || { echo "Failed to fetch closure"; exit 1; }
|
||||
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; }
|
||||
|
||||
echo "Update available: $CURRENT -> $STORE_PATH"
|
||||
|
||||
nix-store -r "$STORE_PATH" || { echo "Failed to fetch closure"; exit 1; }
|
||||
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
|
||||
'';
|
||||
wall "System update installed. Rebooting in 10 seconds..."
|
||||
sleep 10
|
||||
systemctl reboot
|
||||
'';
|
||||
};
|
||||
in
|
||||
{
|
||||
systemd.services.pull-update = {
|
||||
|
||||
Reference in New Issue
Block a user