From 3458298587d881e723100d8e0f4f1acfb40568f9 Mon Sep 17 00:00:00 2001 From: Kiara Grouwstra Date: Thu, 31 Oct 2024 20:08:54 +0100 Subject: [PATCH] terraform/nix-build.sh: prevent error on empty nix_options 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. --- terraform/nix-build/nix-build.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/terraform/nix-build/nix-build.sh b/terraform/nix-build/nix-build.sh index 8e5babca..07d47286 100755 --- a/terraform/nix-build/nix-build.sh +++ b/terraform/nix-build/nix-build.sh @@ -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")