Skip to content

Commit 1e93f9f

Browse files
misumisumimergify[bot]
authored andcommitted
fix: format to json format
1 parent 1fdbe4c commit 1e93f9f

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

terraform/nix-build/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
locals {
2-
nix_options = var.nix_options == null ? "" : join(" ", [for k, v in var.nix_options : "--option ${k} ${v}"])
2+
nix_options = "{\"options\": {${join(", ", [for k, v in var.nix_options : "\"${k}\": \"${v}\""])} } }"
33
}
44
data "external" "nix-build" {
55
program = [ "${path.module}/nix-build.sh" ]

terraform/nix-build/nix-build.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ set -efu
33

44
declare file attribute nix_options
55
eval "$(jq -r '@sh "attribute=\(.attribute) file=\(.file) nix_options=\(.nix_options)"')"
6-
if [[ -n ${file-} ]] && [[ -e ${file-} ]]; then
7-
out=$(nix build --no-link --json $(echo "$nix_options") -f "$file" "$attribute")
6+
options=$(echo "${nix_options}" | jq -r '.options | to_entries | map("--option \(.key) \(.value)") | join(" ")')
7+
if [[ -n ${file-} ]] && [[ -e ${fileh-} ]]; then
8+
# shellcheck disable=SC2086
9+
out=$(nix build --no-link --json $options -f "$file" "$attribute")
810
printf '%s' "$out" | jq -c '.[].outputs'
911
else
10-
out=$(nix build --no-link --json $(echo "$nix_options") "$attribute")
12+
# shellcheck disable=SC2086
13+
out=$(nix build --no-link --json $options "$attribute")
1114
printf '%s' "$out" | jq -c '.[].outputs'
1215
fi

terraform/nix-build/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ variable "file" {
1212
variable "nix_options" {
1313
type = map(string)
1414
description = "the options of nix"
15-
default = null
15+
default = {}
1616
}

0 commit comments

Comments
 (0)