about summary refs log tree commit diff
path: root/pkgs/applications/networking/cluster/terraform
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-02-08 19:41:58 +0300
committerGitHub <noreply@github.com>2022-02-08 17:41:58 +0100
commitf25944439889667110b7e0f4236234a0515d0365 (patch)
tree72820a4207f0a50a750e8761ee8d40477d1d7153 /pkgs/applications/networking/cluster/terraform
parent2fcfc72e682fa7d1e5c7dc33d5cda16188b48112 (diff)
terraform: fix overrideAttrs with passthru attributes (#158632)
If plugins are specified in a call to `terraform.withPlugins`, the
standard override functions do not act on the wrapper derivation that
a user sees but on the underlying Terraform derivation.

Due to this, overriding attributes does nothing as they are not passed
through to the "outer" wrapper derivation.

This change fixes this for at least passthru attributes, but other
applications of `.overrideAttrs` (and potentially of the other
overrides) will do nothing (except compute a bit internally).

This fixes #158620 at least partially.
Diffstat (limited to 'pkgs/applications/networking/cluster/terraform')
-rw-r--r--pkgs/applications/networking/cluster/terraform/default.nix29
1 files changed, 26 insertions, 3 deletions
diff --git a/pkgs/applications/networking/cluster/terraform/default.nix b/pkgs/applications/networking/cluster/terraform/default.nix
index 5c0a1d6691640..07302ddc1ef3f 100644
--- a/pkgs/applications/networking/cluster/terraform/default.nix
+++ b/pkgs/applications/networking/cluster/terraform/default.nix
@@ -86,7 +86,26 @@ let
               withPlugins (x: newplugins x ++ actualPlugins);
             full = withPlugins (p: lib.filter lib.isDerivation (lib.attrValues p));
 
-            # Ouch
+            # Expose wrappers around the override* functions of the terraform
+            # derivation.
+            #
+            # Note that this does not behave as anyone would expect if plugins
+            # are specified. The overrides are not on the user-visible wrapper
+            # derivation but instead on the function application that eventually
+            # generates the wrapper. This means:
+            #
+            # 1. When using overrideAttrs, only `passthru` attributes will
+            #    become visible on the wrapper derivation. Other overrides that
+            #    modify the derivation *may* still have an effect, but it can be
+            #    difficult to follow.
+            #
+            # 2. Other overrides may work if they modify the terraform
+            #    derivation, or they may have no effect, depending on what
+            #    exactly is being changed.
+            #
+            # 3. Specifying overrides on the wrapper is unsupported.
+            #
+            # See nixpkgs#158620 for details.
             overrideDerivation = f:
               (pluggable (terraform.overrideDerivation f)).withPlugins plugins;
             overrideAttrs = f:
@@ -105,6 +124,12 @@ let
             inherit (terraform) name meta;
             nativeBuildInputs = [ makeWrapper ];
 
+            # Expose the passthru set with the override functions
+            # defined above, as well as any passthru values already
+            # set on `terraform` at this point (relevant in case a
+            # user overrides attributes).
+            passthru = terraform.passthru // passthru;
+
             buildCommand = ''
               # Create wrappers for terraform plugins because Terraform only
               # walks inside of a tree of files.
@@ -128,8 +153,6 @@ let
                 --set NIX_TERRAFORM_PLUGIN_DIR $out/libexec/terraform-providers \
                 --prefix PATH : "${lib.makeBinPath wrapperInputs}"
             '';
-
-            inherit passthru;
           });
     in
     withPlugins (_: [ ]);