@@ -40,25 +40,35 @@ let
4040
4141 pluggable = terraform:
4242 let
43− withPlugins = plugins: stdenv.mkDerivation {
44− name = "${terraform.name}-with-plugins";
45− buildInputs = [ makeWrapper ];
46−
47− buildCommand = ''
48− mkdir -p $out/bin/
49− makeWrapper "${terraform.bin}/bin/terraform" "$out/bin/terraform" \
50− --set NIX_TERRAFORM_PLUGIN_DIR "${buildEnv { name = "tf-plugin-env"; paths = plugins terraform.plugins; }}/bin"
51− '';
52−
53− passthru = {
54− withPlugins = newplugins: withPlugins (x: newplugins x ++ plugins x);
55−
56− # Ouch
57− overrideDerivation = f: (pluggable (terraform.overrideDerivation f)).withPlugins plugins;
58− overrideAttrs = f: (pluggable (terraform.overrideAttrs f)).withPlugins plugins;
59− override = x: (pluggable (terraform.override x)).withPlugins plugins;
60− };
61− };
43+ withPlugins = plugins:
44+ let
45+ actualPlugins = plugins terraform.plugins;
46+
47+ passthru = {
48+ withPlugins = newplugins: withPlugins (x: newplugins x ++ actualPlugins);
49+
50+ # Ouch
51+ overrideDerivation = f: (pluggable (terraform.overrideDerivation f)).withPlugins plugins;
52+ overrideAttrs = f: (pluggable (terraform.overrideAttrs f)).withPlugins plugins;
53+ override = x: (pluggable (terraform.override x)).withPlugins plugins;
54+ };
55+ in
56+ # Don't bother wrapping unless we actually have plugins, since the wrapper will stop automatic downloading
57+ # of plugins, which might be counterintuitive if someone just wants a vanilla Terraform.
58+ if actualPlugins == []
59+ then terraform.overrideAttrs (orig: { passthru = orig.passthru // passthru; })
60+ else stdenv.mkDerivation {
61+ name = "${terraform.name}-with-plugins";
62+ buildInputs = [ makeWrapper ];
63+
64+ buildCommand = ''
65+ mkdir -p $out/bin/
66+ makeWrapper "${terraform.bin}/bin/terraform" "$out/bin/terraform" \
67+ --set NIX_TERRAFORM_PLUGIN_DIR "${buildEnv { name = "tf-plugin-env"; paths = actualPlugins; }}/bin"
68+ '';
69+
70+ inherit passthru;
71+ };
6272 in withPlugins (_: []);
6373
6474 plugins = {