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 43909cf
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 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
9 changes: 6 additions & 3 deletions terraform/nix-build/nix-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ 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
# shellcheck disable=SC2086
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")
# shellcheck disable=SC2086
out=$(nix build --no-link --json $options "$attribute")
printf '%s' "$out" | jq -c '.[].outputs'
fi
2 changes: 1 addition & 1 deletion terraform/nix-build/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ variable "file" {
variable "nix_options" {
type = map(string)
description = "the options of nix"
default = null
default = {}
}

0 comments on commit 43909cf

Please sign in to comment.