diff options
| author | seth <[email protected]> | 2024-02-02 16:14:08 -0500 |
|---|---|---|
| committer | seth <[email protected]> | 2024-02-02 19:22:07 -0500 |
| commit | ac3021bc818c6525db108639645780393c3d762f (patch) | |
| tree | 0e3feccb2579824ae3bff767a4fe860248632ef2 /modules | |
| parent | 1e32ab22f3fc2a4959f90ded95d7318bd4e23623 (diff) | |
terranix: use new flakeModule
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/flake/configurations.nix | 8 | ||||
| -rw-r--r-- | modules/flake/terranix.nix | 92 |
2 files changed, 96 insertions, 4 deletions
diff --git a/modules/flake/configurations.nix b/modules/flake/configurations.nix index 3d2d512..ef1ae4e 100644 --- a/modules/flake/configurations.nix +++ b/modules/flake/configurations.nix @@ -156,8 +156,8 @@ example = literalExpression '' { foo = { - system = "aarch64-${kernelFor type}"; - }; + system = "aarch64-${kernelFor type}"; + }; } ''; description = mdDoc '' @@ -192,8 +192,8 @@ in { example = literalExpression '' { john = { - pkgs = inputs.nixpkgs.legacyPackages.aarch64-linux; - }; + pkgs = inputs.nixpkgs.legacyPackages.aarch64-linux; + }; } ''; description = mdDoc '' diff --git a/modules/flake/terranix.nix b/modules/flake/terranix.nix new file mode 100644 index 0000000..66f79b9 --- /dev/null +++ b/modules/flake/terranix.nix @@ -0,0 +1,92 @@ +{ + lib, + flake-parts-lib, + ... +}: 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} = { + builder = mkOption { + type = types.functionTo (types.lazyAttrsOf types.raw); + example = literalExpression "inputs.terranix.lib.terranixConfiguration"; + description = mdDoc '' + Function used to build this terranixConfiguration + ''; + }; + + 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 = cfg.builder { + 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]; + }; + }; + }); + }; +} |
