From e322e039f3218f250be1f6cfe410204990a3db11 Mon Sep 17 00:00:00 2001 From: Victor Engmark Date: Thu, 9 Mar 2023 10:23:20 +1300 Subject: [PATCH 1/4] fix: Quote variable reference As recommended by ShellCheck. --- install-nix.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install-nix.sh b/install-nix.sh index 03447c3..d6a09c9 100755 --- a/install-nix.sh +++ b/install-nix.sh @@ -54,7 +54,7 @@ else add_config "build-users-group =" sudo mkdir -p /etc/nix sudo chmod 0755 /etc/nix - sudo cp $workdir/nix.conf /etc/nix/nix.conf + sudo cp "$workdir/nix.conf" /etc/nix/nix.conf fi if [[ $INPUT_INSTALL_OPTIONS != "" ]]; then From ef4bcbc79cac9d9fcf83eb1a1ea442d662a40f28 Mon Sep 17 00:00:00 2001 From: Victor Engmark Date: Thu, 9 Mar 2023 10:24:48 +1300 Subject: [PATCH 2/4] refactor: De-dupe Nix path detection --- install-nix.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install-nix.sh b/install-nix.sh index d6a09c9..5388092 100755 --- a/install-nix.sh +++ b/install-nix.sh @@ -1,8 +1,8 @@ #!/usr/bin/env bash set -euo pipefail -if type -p nix &>/dev/null ; then - echo "Aborting: Nix is already installed at $(type -p nix)" +if nix_path="$(type -p nix)" ; then + echo "Aborting: Nix is already installed at ${nix_path}" exit fi From ac5ee67104b4f4e15e0bbb93d75f18fdc9f93431 Mon Sep 17 00:00:00 2001 From: Victor Engmark Date: Thu, 9 Mar 2023 10:26:30 +1300 Subject: [PATCH 3/4] refactor: Simplify appending to file Avoids one extra command, and removes the need for `tee`. --- install-nix.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install-nix.sh b/install-nix.sh index 5388092..089ff6a 100755 --- a/install-nix.sh +++ b/install-nix.sh @@ -15,7 +15,7 @@ trap 'rm -rf "$workdir"' EXIT # Configure Nix add_config() { - echo "$1" | tee -a "$workdir/nix.conf" >/dev/null + echo "$1" >> "$workdir/nix.conf" } # Set jobs to number of cores add_config "max-jobs = auto" From 3bdded02da966d4d6f43c2c1abdb2877174df625 Mon Sep 17 00:00:00 2001 From: Victor Engmark Date: Thu, 9 Mar 2023 10:30:16 +1300 Subject: [PATCH 4/4] refactor: Use consistent emptiness check --- install-nix.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/install-nix.sh b/install-nix.sh index 089ff6a..7d9a6ef 100755 --- a/install-nix.sh +++ b/install-nix.sh @@ -28,7 +28,7 @@ elif [[ -n "${GITHUB_TOKEN:-}" ]]; then add_config "access-tokens = github.com=$GITHUB_TOKEN" fi # Append extra nix configuration if provided -if [[ $INPUT_EXTRA_NIX_CONFIG != "" ]]; then +if [[ -n "${INPUT_EXTRA_NIX_CONFIG:-}" ]]; then add_config "$INPUT_EXTRA_NIX_CONFIG" fi if [[ ! $INPUT_EXTRA_NIX_CONFIG =~ "experimental-features" ]]; then @@ -57,7 +57,7 @@ else sudo cp "$workdir/nix.conf" /etc/nix/nix.conf fi -if [[ $INPUT_INSTALL_OPTIONS != "" ]]; then +if [[ -n "${INPUT_INSTALL_OPTIONS:-}" ]]; then IFS=' ' read -r -a extra_installer_options <<< "$INPUT_INSTALL_OPTIONS" installer_options=("${extra_installer_options[@]}" "${installer_options[@]}") fi @@ -91,7 +91,7 @@ echo "/nix/var/nix/profiles/default/bin" >> "$GITHUB_PATH" # new path for nix 2.14 echo "$HOME/.nix-profile/bin" >> "$GITHUB_PATH" -if [[ $INPUT_NIX_PATH != "" ]]; then +if [[ -n "${INPUT_NIX_PATH:-}" ]]; then echo "NIX_PATH=${INPUT_NIX_PATH}" >> "$GITHUB_ENV" fi