Skip to content

Commit 3ee0220

Browse files
committed
nix-build: add debug_logging option
1 parent 0a8ab32 commit 3ee0220

File tree

4 files changed

+29
-17
lines changed

4 files changed

+29
-17
lines changed

terraform/all-in-one/main.tf

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
module "system-build" {
2-
source = "../nix-build"
3-
attribute = var.nixos_system_attr
4-
file = var.file
5-
nix_options = var.nix_options
6-
special_args = var.special_args
2+
source = "../nix-build"
3+
attribute = var.nixos_system_attr
4+
debug_logging = var.debug_logging
5+
file = var.file
6+
nix_options = var.nix_options
7+
special_args = var.special_args
78
}
89

910
module "partitioner-build" {
10-
source = "../nix-build"
11-
attribute = var.nixos_partitioner_attr
12-
file = var.file
13-
nix_options = var.nix_options
14-
special_args = var.special_args
11+
source = "../nix-build"
12+
attribute = var.nixos_partitioner_attr
13+
debug_logging = var.debug_logging
14+
file = var.file
15+
nix_options = var.nix_options
16+
special_args = var.special_args
1517
}
1618

1719
locals {

terraform/nix-build/main.tf

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ locals {
66
data "external" "nix-build" {
77
program = ["${path.module}/nix-build.sh"]
88
query = {
9-
attribute = var.attribute
10-
file = var.file
11-
nix_options = local.nix_options
12-
special_args = jsonencode(var.special_args)
9+
attribute = var.attribute
10+
file = var.file
11+
nix_options = local.nix_options
12+
debug_logging = var.debug_logging
13+
special_args = jsonencode(var.special_args)
1314
}
1415
}
1516
output "result" {

terraform/nix-build/nix-build.sh

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

4-
declare file attribute nix_options special_args
5-
eval "$(jq -r '@sh "attribute=\(.attribute) file=\(.file) nix_options=\(.nix_options) special_args=\(.special_args)"')"
4+
declare file attribute nix_options special_args debug_logging
5+
eval "$(jq -r '@sh "attribute=\(.attribute) file=\(.file) nix_options=\(.nix_options) special_args=\(.special_args) debug_logging=\(.debug_logging)"')"
6+
if [ "${debug_logging}" = "true" ]; then
7+
set -x
8+
fi
69
if [ "${nix_options}" != '{"options":{}}' ]; then
710
options=$(echo "${nix_options}" | jq -r '.options | to_entries | map("--option \(.key) \(.value)") | join(" ")')
811
else
@@ -41,7 +44,7 @@ else
4144
# substitute variables into the template
4245
nix_expr="(builtins.getFlake ''${flake_url}'').${config_path}.extendModules { specialArgs = builtins.fromJSON ''${special_args}''; }"
4346
# inject `special_args` into nixos config's `specialArgs`
44-
47+
4548
# shellcheck disable=SC2086
4649
out=$(nix build --no-link --json ${options} --expr "${nix_expr}" "${config_attribute}")
4750
fi

terraform/nix-build/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,9 @@ variable "special_args" {
2020
default = {}
2121
description = "A map exposed as NixOS's `specialArgs` thru a file."
2222
}
23+
24+
variable "debug_logging" {
25+
type = bool
26+
default = false
27+
description = "Enable debug logging"
28+
}

0 commit comments

Comments
 (0)