Skip to content

Commit

Permalink
fix: format to json format
Browse files Browse the repository at this point in the history
  • Loading branch information
misumisumi committed Jun 15, 2024
1 parent 4f4b15f commit 5bc817e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion terraform/nix-build/main.tf
Original file line number Diff line number Diff line change
@@ -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" ]
Expand Down
7 changes: 4 additions & 3 deletions terraform/nix-build/nix-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5bc817e

Please sign in to comment.