install-nix.sh: use a temporary workdir

Don't leave temporary files around
This commit is contained in:
zimbatm 2021-11-17 21:55:09 +01:00
parent 1b5d414ec3
commit 06a240d7b6
No known key found for this signature in database
GPG Key ID: 71BAF6D40C1D63D7

View File

@ -6,9 +6,13 @@ if type -p nix &>/dev/null ; then
exit
fi
# Create a temporary workdir
workdir=$(mktemp -d)
trap 'rm -rf "$workdir"' EXIT
# Configure Nix
add_config() {
echo "$1" | tee -a /tmp/nix.conf >/dev/null
echo "$1" | tee -a "$workdir/nix.conf" >/dev/null
}
# Set jobs to number of cores
add_config "max-jobs = auto"
@ -26,7 +30,7 @@ fi
installer_options=(
--no-channel-add
--darwin-use-unencrypted-nix-store-volume
--nix-extra-conf-file /tmp/nix.conf
--nix-extra-conf-file "$workdir/nix.conf"
)
# only use the nix-daemon settings if on darwin (which get ignored) or systemd is supported
@ -49,13 +53,13 @@ fi
echo "installer options: ${installer_options[@]}"
# There is --retry-on-errors, but only newer curl versions support that
until curl -o /tmp/install -v --fail --retry 5 --retry-connrefused -L "${INPUT_INSTALL_URL:-https://nixos.org/nix/install}"
until curl -o "$workdir/install" -v --fail --retry 5 --retry-connrefused -L "${INPUT_INSTALL_URL:-https://nixos.org/nix/install}"
do
sleep 1
done
chmod +x /tmp/install
sh /tmp/install "${installer_options[@]}"
chmod +x "$workdir/install"
sh "$workdir/install" "${installer_options[@]}"
if [[ $OSTYPE =~ darwin ]]; then
# macOS needs certificates hints