about summary refs log tree commit diff
path: root/pkgs/applications/networking/cluster/terraform
diff options
context:
space:
mode:
authorJonas Chevalier <zimbatm@zimbatm.com>2022-01-24 12:53:05 +0100
committerGitHub <noreply@github.com>2022-01-24 12:53:05 +0100
commite7dbfd7ece0e8f11ef0617919cc5597258eda90f (patch)
tree02567ae58a36f2ac5ea3c4f8a25ddf24990f8d82 /pkgs/applications/networking/cluster/terraform
parente70ba2998d36c8817d7b06b9854d4fcaa91443f5 (diff)
terraform.withPlugins: clean and remove 0.12 support (#155477)
Now that the terraform 0.12 compatibility is not needed anymore, the
`terraform.withPlugins` and `terraform-providers.mkProvider`
implementations can be simplified.

Instead of building a bunch of bin wrappers on instantiation, the
providers are now stored in
`$out/libexec/terraform-providers/<registry>/<owner>/<name>/<version>/<os>_<arch>/terraform-provider-<name>_v<version>`
and then a simple `buildEnv` can be used to merge them.

This breaks back-compat so it's not possible to mix-and-match with
previous versions of nixpkgs. In exchange, it now becomes possible to
use the providers from
[nixpkgs-terraform-providers-bin](https://github.com/numtide/nixpkgs-terraform-providers-bin)
directly.
Diffstat (limited to 'pkgs/applications/networking/cluster/terraform')
-rw-r--r--pkgs/applications/networking/cluster/terraform/default.nix48
1 files changed, 7 insertions, 41 deletions
diff --git a/pkgs/applications/networking/cluster/terraform/default.nix b/pkgs/applications/networking/cluster/terraform/default.nix
index bc179ea55eb16..a5e92bedef6a3 100644
--- a/pkgs/applications/networking/cluster/terraform/default.nix
+++ b/pkgs/applications/networking/cluster/terraform/default.nix
@@ -1,5 +1,6 @@
 { stdenv
 , lib
+, buildEnv
 , buildGoModule
 , fetchFromGitHub
 , makeWrapper
@@ -62,9 +63,9 @@ let
           babariviere
           kalbasit
           marsam
+          maxeaubrey
           timstott
           zimbatm
-          maxeaubrey
           zowoq
         ];
       };
@@ -76,39 +77,6 @@ let
         let
           actualPlugins = plugins terraform.plugins;
 
-          # Make providers available in Terraform 0.13 and 0.12 search paths.
-          pluginDir = lib.concatMapStrings
-            (pl:
-              let
-                inherit (pl) version GOOS GOARCH;
-
-                pname = pl.pname or (throw "${pl.name} is missing a pname attribute");
-
-                # This is just the name, without the terraform-provider- prefix
-                plugin_name = lib.removePrefix "terraform-provider-" pname;
-
-                slug = pl.passthru.provider-source-address or "registry.terraform.io/nixpkgs/${plugin_name}";
-
-                shim = writeText "shim" ''
-                  #!${runtimeShell}
-                  exec ${pl}/bin/${pname}_v${version} "$@"
-                '';
-              in
-              ''
-                TF_0_13_PROVIDER_PATH=$out/plugins/${slug}/${version}/${GOOS}_${GOARCH}/${pname}_v${version}
-                mkdir -p "$(dirname $TF_0_13_PROVIDER_PATH)"
-
-                cp ${shim} "$TF_0_13_PROVIDER_PATH"
-                chmod +x "$TF_0_13_PROVIDER_PATH"
-
-                TF_0_12_PROVIDER_PATH=$out/plugins/${pname}_v${version}
-
-                cp ${shim} "$TF_0_12_PROVIDER_PATH"
-                chmod +x "$TF_0_12_PROVIDER_PATH"
-              ''
-            )
-            actualPlugins;
-
           # Wrap PATH of plugins propagatedBuildInputs, plugins may have runtime dependencies on external binaries
           wrapperInputs = lib.unique (lib.flatten
             (lib.catAttrs "propagatedBuildInputs"
@@ -134,18 +102,16 @@ let
           terraform.overrideAttrs
             (orig: { passthru = orig.passthru // passthru; })
         else
-          lib.appendToName "with-plugins" (stdenv.mkDerivation {
+          lib.appendToName "with-plugins" (buildEnv {
             inherit (terraform) name meta;
+            paths = actualPlugins;
             nativeBuildInputs = [ makeWrapper ];
-
-            buildCommand = pluginDir + ''
-              mkdir -p $out/bin/
+            postBuild = ''
+              mkdir -p $out/bin
               makeWrapper "${terraform}/bin/terraform" "$out/bin/terraform" \
-                --set NIX_TERRAFORM_PLUGIN_DIR $out/plugins \
+                --set NIX_TERRAFORM_PLUGIN_DIR $out/libexec/terraform-providers \
                 --prefix PATH : "${lib.makeBinPath wrapperInputs}"
             '';
-
-            inherit passthru;
           });
     in
     withPlugins (_: [ ]);