Skip to content

Commit 5ccebbc

Browse files
misumisumimergify[bot]
authored andcommitted
Accept nix-option in terraform
1 parent 54cbf9b commit 5ccebbc

File tree

5 files changed

+23
-5
lines changed

5 files changed

+23
-5
lines changed

terraform/all-in-one/main.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ module "system-build" {
22
source = "../nix-build"
33
attribute = var.nixos_system_attr
44
file = var.file
5+
nix_options = var.nix_options
56
}
67

78
module "partitioner-build" {
89
source = "../nix-build"
910
attribute = var.nixos_partitioner_attr
1011
file = var.file
12+
nix_options = var.nix_options
1113
}
1214

1315
locals {
@@ -37,7 +39,7 @@ module "nixos-rebuild" {
3739
module.install
3840
]
3941

40-
# Do not execute this step if var.stop_after_disko == true
42+
# Do not execute this step if var.stop_after_disko == true
4143
count = var.stop_after_disko ? 0 : 1
4244

4345
source = "../nixos-rebuild"

terraform/all-in-one/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,9 @@ variable "no_reboot" {
101101
description = "Do not reboot after installation"
102102
default = false
103103
}
104+
105+
variable "nix_options" {
106+
type = map(string)
107+
description = "the options of nix"
108+
default = null
109+
}

terraform/nix-build/main.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
locals {
2+
nix_options = var.nix_options == null ? "" : join(" ", [for k, v in var.nix_options : "--option ${k} ${v}"])
3+
}
14
data "external" "nix-build" {
25
program = [ "${path.module}/nix-build.sh" ]
36
query = {
47
attribute = var.attribute
58
file = var.file
9+
nix_options = local.nix_options
610
}
711
}
812
output "result" {

terraform/nix-build/nix-build.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/usr/bin/env bash
22
set -efu
33

4-
declare file attribute
5-
eval "$(jq -r '@sh "attribute=\(.attribute) file=\(.file)"')"
4+
declare file attribute nix_options
5+
eval "$(jq -r '@sh "attribute=\(.attribute) file=\(.file) nix_options=\(.nix_options)"')"
66
if [[ -n ${file-} ]] && [[ -e ${file-} ]]; then
7-
out=$(nix build --no-link --json -f "$file" "$attribute")
7+
out=$(nix build --no-link --json $(echo "$nix_options") -f "$file" "$attribute")
88
printf '%s' "$out" | jq -c '.[].outputs'
99
else
10-
out=$(nix build --no-link --json "$attribute")
10+
out=$(nix build --no-link --json $(echo "$nix_options") "$attribute")
1111
printf '%s' "$out" | jq -c '.[].outputs'
1212
fi

terraform/nix-build/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,9 @@ variable "file" {
88
description = "the nix file to evaluate, if not run in flake mode"
99
default = null
1010
}
11+
12+
variable "nix_options" {
13+
type = map(string)
14+
description = "the options of nix"
15+
default = null
16+
}

0 commit comments

Comments
 (0)