Skip to content

Commit

Permalink
Merge pull request #115 from zimbatm/bash-cleanup
Browse files Browse the repository at this point in the history
Bash cleanup
  • Loading branch information
domenkozar authored Nov 18, 2021
2 parents 46187b3 + 802bde5 commit d045d9f
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions lib/install-nix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -18,22 +22,22 @@ 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

# Nix installer flags
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*
Expand All @@ -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
Expand Down

0 comments on commit d045d9f

Please sign in to comment.