diff --git a/terranixConfigurations.nix b/terranixConfigurations.nix index 9dd1c8f..c546cbf 100644 --- a/terranixConfigurations.nix +++ b/terranixConfigurations.nix @@ -1,22 +1,17 @@ { inputs, ... }: -let - lib = inputs.nixpkgs.lib; - utils = import ./utils.nix { inherit inputs lib; }; - inherit (utils) mkTerranixDerivation; - - configs = { - # Example: - # myconfig = { - # modules = [ ./terraform/myconfig.nix ]; - # }; - }; -in - { - perSystem = - { system, ... }: - { - packages = mkTerranixDerivation { inherit system configs; }; + imports = [ + inputs.terranix.flakeModule + ]; + + perSystem = { + terranix.terranixConfigurations = { + # Example: + # myconfig = { + # modules = [ ./terraform/myconfig.nix ]; + # extraArgs = { }; # optional + # }; }; + }; } diff --git a/utils.nix b/utils.nix index fb92954..38cf968 100644 --- a/utils.nix +++ b/utils.nix @@ -7,7 +7,6 @@ let nixpkgs-stable home-manager agenix - terranix ; in @@ -191,66 +190,4 @@ in }; in lib.mapAttrs (_: lib.recursiveUpdate commonVHostConfig) domains; - - # Terranix configuration system - mkTerranixDerivation = - { - system, - configs, - }: - lib.mapAttrs ( - name: cfg: - let - pkgs = nixpkgs.legacyPackages.${system}; - modules = cfg.modules; - extraArgs = cfg.extraArgs or { }; - - terraformConfiguration = terranix.lib.terranixConfiguration { - inherit system modules; - extraArgs = { - inherit lib pkgs; - } // extraArgs; - }; - - tf-json = pkgs.writeShellScriptBin "default" '' - cat ${terraformConfiguration} | ${pkgs.jq}/bin/jq - ''; - - apply = pkgs.writeShellScriptBin "apply" '' - if [[ -e config.tf.json ]]; then rm -f config.tf.json; fi - cp ${terraformConfiguration} config.tf.json \ - && ${pkgs.terraform}/bin/terraform init \ - && ${pkgs.terraform}/bin/terraform apply - ''; - - plan = pkgs.writeShellScriptBin "plan" '' - if [[ -e config.tf.json ]]; then rm -f config.tf.json; fi - cp ${terraformConfiguration} config.tf.json \ - && ${pkgs.terraform}/bin/terraform init \ - && ${pkgs.terraform}/bin/terraform plan - ''; - - destroy = pkgs.writeShellScriptBin "destroy" '' - if [[ -e config.tf.json ]]; then rm -f config.tf.json; fi - cp ${terraformConfiguration} config.tf.json \ - && ${pkgs.terraform}/bin/terraform init \ - && ${pkgs.terraform}/bin/terraform destroy - ''; - - create-state-bucket = pkgs.writeShellScriptBin "create-state-bucket" '' - BUCKET_NAME=''${1:-"terraform-state-bucket"} - ACCOUNT_ID=''${2:?"Error: Cloudflare account ID required as second argument"} - R2_ENDPOINT="https://$ACCOUNT_ID.r2.cloudflarestorage.com" - - echo "Creating R2 bucket $BUCKET_NAME..." - ${pkgs.awscli}/bin/aws s3api create-bucket \ - --bucket "$BUCKET_NAME" \ - --endpoint-url "$R2_ENDPOINT" - echo "Bucket created successfully at $R2_ENDPOINT" - ''; - in - tf-json // { - inherit apply plan destroy create-state-bucket; - } - ) configs; }