summary refs log tree commit diff
path: root/pkgs/applications/networking/cluster/terraform/default.nix
diff options
context:
space:
mode:
authorDan Peebles <pumpkin@me.com>2017-08-30 18:53:14 -0400
committerDan Peebles <pumpkin@me.com>2017-08-30 18:53:46 -0400
commit11753b3273ac492a4efdd44ae98f1969f554b126 (patch)
tree189d7b6b0f695022fd400c72fd57845ddb676c89 /pkgs/applications/networking/cluster/terraform/default.nix
parentb291ead4aaf58170a0bb3640c7340ebcbbe0e632 (diff)
downloadnixlib-11753b3273ac492a4efdd44ae98f1969f554b126.tar
nixlib-11753b3273ac492a4efdd44ae98f1969f554b126.tar.gz
nixlib-11753b3273ac492a4efdd44ae98f1969f554b126.tar.bz2
nixlib-11753b3273ac492a4efdd44ae98f1969f554b126.tar.lz
nixlib-11753b3273ac492a4efdd44ae98f1969f554b126.tar.xz
nixlib-11753b3273ac492a4efdd44ae98f1969f554b126.tar.zst
nixlib-11753b3273ac492a4efdd44ae98f1969f554b126.zip
terraform: noop 0.10 plugins mechanism when unused
Diffstat (limited to 'pkgs/applications/networking/cluster/terraform/default.nix')
-rw-r--r--pkgs/applications/networking/cluster/terraform/default.nix48
1 files changed, 29 insertions, 19 deletions
diff --git a/pkgs/applications/networking/cluster/terraform/default.nix b/pkgs/applications/networking/cluster/terraform/default.nix
index efff9282bd3a..8589eed12bbc 100644
--- a/pkgs/applications/networking/cluster/terraform/default.nix
+++ b/pkgs/applications/networking/cluster/terraform/default.nix
@@ -40,25 +40,35 @@ let
 
   pluggable = terraform:
     let
-      withPlugins = plugins: stdenv.mkDerivation {
-        name = "${terraform.name}-with-plugins";
-        buildInputs = [ makeWrapper ];
-
-        buildCommand = ''
-          mkdir -p $out/bin/
-          makeWrapper "${terraform.bin}/bin/terraform" "$out/bin/terraform" \
-            --set NIX_TERRAFORM_PLUGIN_DIR "${buildEnv { name = "tf-plugin-env"; paths = plugins terraform.plugins; }}/bin"
-        '';
-
-        passthru = {
-          withPlugins = newplugins: withPlugins (x: newplugins x ++ plugins x);
-
-          # Ouch
-          overrideDerivation = f: (pluggable (terraform.overrideDerivation f)).withPlugins plugins;
-          overrideAttrs = f: (pluggable (terraform.overrideAttrs f)).withPlugins plugins;
-          override = x: (pluggable (terraform.override x)).withPlugins plugins;
-        };
-      };
+      withPlugins = plugins:
+        let
+          actualPlugins = plugins terraform.plugins;
+
+          passthru = {
+            withPlugins = newplugins: withPlugins (x: newplugins x ++ actualPlugins);
+
+            # Ouch
+            overrideDerivation = f: (pluggable (terraform.overrideDerivation f)).withPlugins plugins;
+            overrideAttrs = f: (pluggable (terraform.overrideAttrs f)).withPlugins plugins;
+            override = x: (pluggable (terraform.override x)).withPlugins plugins;
+          };
+        in
+          # Don't bother wrapping unless we actually have plugins, since the wrapper will stop automatic downloading
+          # of plugins, which might be counterintuitive if someone just wants a vanilla Terraform.
+          if actualPlugins == []
+            then terraform.overrideAttrs (orig: { passthru = orig.passthru // passthru; })
+            else stdenv.mkDerivation {
+              name = "${terraform.name}-with-plugins";
+              buildInputs = [ makeWrapper ];
+
+              buildCommand = ''
+                mkdir -p $out/bin/
+                makeWrapper "${terraform.bin}/bin/terraform" "$out/bin/terraform" \
+                  --set NIX_TERRAFORM_PLUGIN_DIR "${buildEnv { name = "tf-plugin-env"; paths = actualPlugins; }}/bin"
+              '';
+
+              inherit passthru;
+            };
     in withPlugins (_: []);
 
   plugins = {