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.
main
Vincent Ambo 2 years ago committed by GitHub
parent 2fcfc72e68
commit f259444398
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 29
      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 (_: [ ]);

Loading…
Cancel
Save