fix: Fixes updater failing in certain cases.

This commit is contained in:
greysoh 2024-07-19 14:29:50 -04:00
parent 254658dfca
commit bae947de74
Signed by: imterah
GPG key ID: 8FA7DD57BA6CEA37

View file

@ -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