diff --git a/pkgs/applications/networking/cluster/terraform-providers/default.nix b/pkgs/applications/networking/cluster/terraform-providers/default.nix index c70e1b6ae11..d6426a2314c 100644 --- a/pkgs/applications/networking/cluster/terraform-providers/default.nix +++ b/pkgs/applications/networking/cluster/terraform-providers/default.nix @@ -2,11 +2,16 @@ , buildGoPackage , fetchFromGitHub , callPackage +, runtimeShell }: let list = lib.importJSON ./providers.json; - toDrv = data: + toDrv = name: data: + let + fallbackProviderSourceAddress = "nixpkgs/${data.owner}/${name}"; + providerSourceAddress = data.provider-source-address or fallbackProviderSourceAddress; + in buildGoPackage rec { inherit (data) owner repo rev version sha256; name = "${repo}-${version}"; @@ -18,6 +23,9 @@ let # Terraform allow checking the provider versions, but this breaks # if the versions are not provided via file paths. postBuild = "mv $NIX_BUILD_TOP/go/bin/${repo}{,_v${version}}"; + passthru = { + inherit providerSourceAddress; + }; }; # Google is now using the vendored go modules, which works a bit differently @@ -48,7 +56,7 @@ let }); # These providers are managed with the ./update-all script - automated-providers = lib.mapAttrs (_: toDrv) list; + automated-providers = lib.mapAttrs (toDrv) list; # These are the providers that don't fall in line with the default model special-providers = { diff --git a/pkgs/applications/networking/cluster/terraform/default.nix b/pkgs/applications/networking/cluster/terraform/default.nix index b531055a1bf..5f2ef78b495 100644 --- a/pkgs/applications/networking/cluster/terraform/default.nix +++ b/pkgs/applications/networking/cluster/terraform/default.nix @@ -1,5 +1,5 @@ { stdenv, lib, buildEnv, buildGoPackage, fetchFromGitHub, makeWrapper, coreutils -, runCommand, writeText, terraform-providers, fetchpatch }: +, runCommand, runtimeShell, writeText, terraform-providers, fetchpatch }: let goPackagePath = "github.com/hashicorp/terraform"; @@ -59,6 +59,29 @@ let let actualPlugins = plugins terraform.plugins; + # Make providers available in Terraform 0.13 and 0.12 search paths. + pluginDir = lib.concatMapStrings (pl: let + inherit (pl) repo version GOOS GOARCH; + inherit (pl.passthru) providerSourceAddress; + + shim = writeText "shim" '' + #!${runtimeShell} + exec ${pl}/bin/${repo}_v${version} \$@ + ''; + in '' + TF_0_13_PROVIDER_PATH=$out/plugins/${providerSourceAddress}/${version}/${GOOS}_${GOARCH}/${repo}_v${version} + mkdir -p "$(dirname $TF_0_13_PROVIDER_PATH)" + + cp ${shim} "$TF_0_13_PROVIDER_PATH" + chmod +x "$TF_0_13_PROVIDER_PATH" + + TF_0_12_PROVIDER_PATH=$out/plugins/${repo}_v${version} + + cp ${shim} "$TF_0_12_PROVIDER_PATH" + chmod +x "$TF_0_12_PROVIDER_PATH" + '' + ) actualPlugins; + # Wrap PATH of plugins propagatedBuildInputs, plugins may have runtime dependencies on external binaries wrapperInputs = lib.unique (lib.flatten (lib.catAttrs "propagatedBuildInputs" @@ -87,15 +110,10 @@ let inherit (terraform) name; buildInputs = [ makeWrapper ]; - buildCommand = '' + buildCommand = pluginDir + '' mkdir -p $out/bin/ makeWrapper "${terraform}/bin/terraform" "$out/bin/terraform" \ - --set NIX_TERRAFORM_PLUGIN_DIR "${ - buildEnv { - name = "tf-plugin-env"; - paths = actualPlugins; - } - }/bin" \ + --set NIX_TERRAFORM_PLUGIN_DIR $out/plugins \ --prefix PATH : "${lib.makeBinPath wrapperInputs}" '';