From 5bc817ebf931c4e414f58799e9ce0f8f9f0504b9 Mon Sep 17 00:00:00 2001 From: misumisumi Date: Sun, 16 Jun 2024 01:45:55 +0900 Subject: [PATCH] fix: format to json format --- terraform/nix-build/main.tf | 2 +- terraform/nix-build/nix-build.sh | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) 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