Skip to content

Commit caa6191

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

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

deploy_nixos/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ see also:
106106
| extra\_build\_args | List of arguments to pass to the nix builder | `list(string)` | `[]` | no |
107107
| extra\_eval\_args | List of arguments to pass to the nix evaluation | `list(string)` | `[]` | no |
108108
| hermetic | Treat the provided nixos configuration as a hermetic expression and do not evaluate using the ambient system nixpkgs. Useful if you customize eval-modules or use a pinned nixpkgs. | `bool` | false | no |
109+
| arguments | Attribute set passed to hermetic configuration if it is a function. | `map(any)` | `{}` | no |
109110
| keys | A map of filename to content to upload as secrets in /var/keys | `map(string)` | `{}` | no |
110111
| nixos\_config | Path to a NixOS configuration | `string` | `""` | no |
111112
| ssh\_agent | Whether to use an SSH agent. True if not ssh\_private\_key is passed | `bool` | `null` | no |

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)