Skip to content

Commit

Permalink
terraform: noop 0.10 plugins mechanism when unused
Browse files Browse the repository at this point in the history
  • Loading branch information
copumpkin committed Aug 30, 2017
1 parent b291ead commit 11753b3
Showing 1 changed file with 29 additions and 19 deletions.
48 changes: 29 additions & 19 deletions pkgs/applications/networking/cluster/terraform/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit 11753b3

Please sign in to comment.