diff --git a/terraform/nix-build/main.tf b/terraform/nix-build/main.tf index e9570f5b..daf10c36 100644 --- a/terraform/nix-build/main.tf +++ b/terraform/nix-build/main.tf @@ -1,5 +1,5 @@ locals { - nix_options = var.nix_options == null ? "" : join(" ", [for k, v in var.nix_options : "--option ${k} ${v}"]) +nix_options = "{\"options\": {${join(", ", [for k, v in var.nix_options : "\"${k}\": \"${v}\""])} } }" } data "external" "nix-build" { program = [ "${path.module}/nix-build.sh" ] diff --git a/terraform/nix-build/nix-build.sh b/terraform/nix-build/nix-build.sh index f41fdbe3..a5aa0f31 100755 --- a/terraform/nix-build/nix-build.sh +++ b/terraform/nix-build/nix-build.sh @@ -3,10 +3,11 @@ set -efu declare file attribute nix_options eval "$(jq -r '@sh "attribute=\(.attribute) file=\(.file) nix_options=\(.nix_options)"')" -if [[ -n ${file-} ]] && [[ -e ${file-} ]]; then - out=$(nix build --no-link --json $(echo "$nix_options") -f "$file" "$attribute") +options=$(echo ${nix_options} | jq -r '.options | to_entries | map("--option \(.key) \(.value)") | join(" ")') +if [[ -n ${file-} ]] && [[ -e ${fileh-} ]]; then + out=$(nix build --no-link --json $options -f "$file" "$attribute") printf '%s' "$out" | jq -c '.[].outputs' else - out=$(nix build --no-link --json $(echo "$nix_options") "$attribute") + out=$(nix build --no-link --json $options "$attribute") printf '%s' "$out" | jq -c '.[].outputs' fi