summaryrefslogtreecommitdiff
path: root/modules/flake
diff options
context:
space:
mode:
Diffstat (limited to 'modules/flake')
-rw-r--r--modules/flake/configurations.nix8
-rw-r--r--modules/flake/terranix.nix92
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];
+ };
+ };
+ });
+ };
+}