Merge pull request #115 from zimbatm/bash-cleanup

Bash cleanup
This commit is contained in:
Domen Kožar 2021-11-17 20:21:23 -06:00 committed by GitHub
commit d045d9f5d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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"
@ -18,7 +22,7 @@ add_config "trusted-users = root $USER"
if [[ $INPUT_EXTRA_NIX_CONFIG != "" ]]; then
add_config "$INPUT_EXTRA_NIX_CONFIG"
fi
if [[ ! $INPUT_EXTRA_NIX_CONFIG =~ "experimental-features" ]]; then
if [[ ! $INPUT_EXTRA_NIX_CONFIG =~ "experimental-features" ]]; then
add_config "experimental-features = nix-command flakes"
fi
@ -26,14 +30,14 @@ 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
if [[ $OSTYPE =~ darwin || -e /run/systemd/system ]]; then
installer_options+=(
--daemon
--daemon-user-count `python -c 'import multiprocessing as mp; print(mp.cpu_count() * 2)'`
--daemon-user-count "$(python -c 'import multiprocessing as mp; print(mp.cpu_count() * 2)')"
)
else
# "fix" the following error when running nix*
@ -42,20 +46,25 @@ else
fi
if [[ $INPUT_INSTALL_OPTIONS != "" ]]; then
IFS=' ' read -r -a extra_installer_options <<< $INPUT_INSTALL_OPTIONS
IFS=' ' read -r -a extra_installer_options <<< "$INPUT_INSTALL_OPTIONS"
installer_options=("${extra_installer_options[@]}" "${installer_options[@]}")
fi
echo "installer options: ${installer_options[@]}"
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}"
curl_retries=5
while ! curl -o "$workdir/install" -v --fail -L "${INPUT_INSTALL_URL:-https://nixos.org/nix/install}"
do
sleep 1
((curl_retries--))
if [[ $curl_retries -le 0 ]]; then
echo "curl retries failed" >&2
exit 1
fi
done
chmod +x /tmp/install
sh /tmp/install "${installer_options[@]}"
sh "$workdir/install" "${installer_options[@]}"
if [[ $OSTYPE =~ darwin ]]; then
# macOS needs certificates hints