Skip to content

Commit

Permalink
terraform/nix-build.sh: prevent error on empty nix_options
Browse files Browse the repository at this point in the history
currently, when `var.nix_options` is not set, the jq map action yields `null`, which ends up missing up.
using a conditional here, we may instead account for this case such as to set it to empty string and avoid the issue.
  • Loading branch information
KiaraGrouwstra authored and mergify[bot] committed Nov 15, 2024
1 parent d6869b0 commit 3458298
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion terraform/nix-build/nix-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ set -efu

declare file attribute nix_options
eval "$(jq -r '@sh "attribute=\(.attribute) file=\(.file) nix_options=\(.nix_options)"')"
options=$(echo "${nix_options}" | jq -r '.options | to_entries | map("--option \(.key) \(.value)") | join(" ")')
if [ "${nix_options}" != '{"options":{}}' ]; then
options=$(echo "${nix_options}" | jq -r '.options | to_entries | map("--option \(.key) \(.value)") | join(" ")')
else
options=""
fi
if [[ -n ${file-} ]] && [[ -e ${file-} ]]; then
# shellcheck disable=SC2086
out=$(nix build --no-link --json $options -f "$file" "$attribute")
Expand Down

0 comments on commit 3458298

Please sign in to comment.