blob: 294ee2b010e2f67a9388d5b16b1cc54294e5ea53 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
{
lib,
flake-parts-lib,
inputs,
...
}: let
namespace = "terranix";
inherit
(lib)
literalExpression
mdDoc
mkOption
mkPackageOption
types
;
inherit
(flake-parts-lib)
mkPerSystemOption
;
in {
options = {
perSystem = mkPerSystemOption ({
config,
pkgs,
system,
self',
...
}: let
cfg = config.${namespace};
in {
options.${namespace} = {
modules = mkOption {
type = types.listOf types.unspecified;
default = [];
example = literalExpression "[ ./terranix ]";
description = mdDoc ''
Modules to use in this terranixConfiguration
'';
};
configuration = mkOption {
type = types.pathInStore;
readOnly = true;
description = mdDoc ''
Final configuration created by terranix
'';
};
package = mkPackageOption pkgs "opentofu" {
default = ["opentofu"];
example = literalExpression "pkgs.opentofu.withPlugins (plugins: [ plugins.tailscale ] )";
};
};
config = {
terranix.configuration = inputs.terranix.lib.terranixConfiguration {
inherit system;
inherit (cfg) modules;
};
apps.gen-terranix = {
program = pkgs.writeShellApplication {
name = "gen-tf";
text = ''
config_file="config.tf.json"
[ -e "$config_file" ] && rm -f "$config_file"
cp ${cfg.configuration} "$config_file"
'';
};
};
devShells.terranix = pkgs.mkShellNoCC {
shellHook = ''
${self'.apps.gen-terranix.program}
'';
packages = [pkgs.just cfg.package];
};
};
});
};
}
|