From 11753b3273ac492a4efdd44ae98f1969f554b126 Mon Sep 17 00:00:00 2001 From: Dan Peebles Date: Wed, 30 Aug 2017 18:53:14 -0400 Subject: terraform: noop 0.10 plugins mechanism when unused --- .../networking/cluster/terraform/default.nix | 48 +++++++++++++--------- 1 file changed, 29 insertions(+), 19 deletions(-) (limited to 'pkgs/applications/networking/cluster/terraform/default.nix') 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 = { -- cgit 1.4.1