Skip to content

Commit 8d095e9

Browse files
committed
Allow to pass arguments to hermetic configuration if it's a function
1 parent c7459ec commit 8d095e9

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

deploy_nixos/main.tf

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ variable "triggers" {
8181
default = {}
8282
}
8383

84+
variable "arguments" {
85+
type = map(any)
86+
description = "A map of values to pass to the Nix expression. It only works form 'hermetic' configurations. For secrets, use 'keys' instead."
87+
default = {}
88+
}
89+
8490
variable "keys" {
8591
type = map(string)
8692
description = "A map of filename to content to upload as secrets in /var/keys"
@@ -129,7 +135,8 @@ data "external" "nixos-instantiate" {
129135
# end of positional arguments
130136
# start of pass-through arguments
131137
"--argstr", "system", var.target_system,
132-
"--arg", "hermetic", var.hermetic
138+
"--arg", "hermetic", var.hermetic,
139+
"--argstr", "argumentsJson", jsonencode(var.arguments)
133140
],
134141
var.extra_eval_args,
135142
)
@@ -197,4 +204,3 @@ output "id" {
197204
description = "random ID that changes on every nixos deployment"
198205
value = null_resource.deploy_nixos.id
199206
}
200-

deploy_nixos/nixos-instantiate.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,19 @@ shift 3
99

1010

1111
command=(nix-instantiate --show-trace --expr '
12-
{ system, configuration, hermetic ? false, ... }:
12+
{ system, configuration, hermetic ? false, argumentsJson, ... }:
1313
let
14+
arguments = builtins.fromJSON argumentsJson;
15+
1416
os =
1517
if hermetic
16-
then import configuration
18+
then
19+
let
20+
config = import configuration;
21+
in
22+
if builtins.isFunction config
23+
then config arguments
24+
else config
1725
else import <nixpkgs/nixos> { inherit system configuration; };
1826
in {
1927
inherit (builtins) currentSystem;

0 commit comments

Comments
 (0)