From bae947de74ce617aed829fc71c50c2472caefb43 Mon Sep 17 00:00:00 2001 From: greysoh Date: Fri, 19 Jul 2024 14:29:50 -0400 Subject: [PATCH] fix: Fixes updater failing in certain cases. --- nixinfra/update.sh | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/nixinfra/update.sh b/nixinfra/update.sh index a01f9fd..0632209 100644 --- a/nixinfra/update.sh +++ b/nixinfra/update.sh @@ -1,15 +1,38 @@ -#!/usr/bin/env bash -if [[ "$NIX_BUILD_ID" == "" ]]; then +nix_bld_unset_err() { echo "ERROR: You have held a (potentially) broken install!" echo "NIX_BUILD_ID is not set (should be set by default!)" echo "Please set NIX_BUILD_ID manually. i.e:" echo "NIX_BUILD_ID=kitteh-node-1/agent updater" exit 1 +} + +if [[ "$NIX_BUILD_ID" == "" ]]; then + if [[ ! -f "/tmp/nixbuildid" ]]; then + nix_bld_unset_err + fi + + source /tmp/nixbuildid + + if [[ "$NIX_BUILD_ID" == "" ]]; then + nix_bld_unset_err + fi fi if [[ "$UID" != "0" ]]; then + # Hacky workaround for failing to read NIX_BUILD_ID when called like: + # ./update + # but this works: + # sudo ./update + + echo "NIX_BUILD_ID=$NIX_BUILD_ID" > /tmp/nixbuildid + chmod +x /tmp/nixbuildid + sudo $0 $@ - exit $? + STATUS_CODE=$? + + rm -rf /tmp/nixbuildid + + exit $STATUS_CODE fi pushd /etc/nixos 2> /dev/null > /dev/null