Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions terraform/nix-build/main.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
locals {
nix_argstrs = jsonencode({
argstrs = { for k, v in var.nix_argstrs : k => v }
})
nix_options = jsonencode({
options = { for k, v in var.nix_options : k => v }
})
Expand All @@ -8,6 +11,7 @@ data "external" "nix-build" {
query = {
attribute = var.attribute
file = var.file
nix_argstrs = local.nix_argstrs
nix_options = local.nix_options
special_args = jsonencode(var.special_args)
}
Expand Down
11 changes: 8 additions & 3 deletions terraform/nix-build/nix-build.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
#!/usr/bin/env bash
set -efu

declare file attribute nix_options special_args
eval "$(jq -r '@sh "attribute=\(.attribute) file=\(.file) nix_options=\(.nix_options) special_args=\(.special_args)"')"
declare file attribute nix_argstrs nix_options special_args
eval "$(jq -r '@sh "attribute=\(.attribute) file=\(.file) nix_argstrs=\(.nix_argstrs) nix_options=\(.nix_options) special_args=\(.special_args)"')"
if [ "${nix_argstrs}" != '{"argstrs":{}}' ]; then
argstrs=$(echo "${nix_argstrs}" | jq -r '.argstrs | to_entries | map("--argstr \(.key) \(.value)") | join(" ")')
else
argstrs=""
fi
if [ "${nix_options}" != '{"options":{}}' ]; then
options=$(echo "${nix_options}" | jq -r '.options | to_entries | map("--option \(.key) \(.value)") | join(" ")')
else
Expand All @@ -12,7 +17,7 @@ if [[ ${special_args-} == "{}" ]]; then
# no special arguments, proceed as normal
if [[ -n ${file-} ]] && [[ -e ${file-} ]]; then
# shellcheck disable=SC2086
out=$(nix build --no-link --json $options -f "$file" "$attribute")
out=$(nix build --no-link --json $argstrs $options -f "$file" "$attribute")
else
# shellcheck disable=SC2086
out=$(nix build --no-link --json ${options} "$attribute")
Expand Down
6 changes: 6 additions & 0 deletions terraform/nix-build/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ variable "file" {
default = null
}

variable "nix_argstrs" {
type = map(string)
description = "the argstrs of nix"
default = {}
}

variable "nix_options" {
type = map(string)
description = "the options of nix"
Expand Down
Loading