terraform: fix withPlugins

Move the providerSourceAddress fallback to the terraform.withPlugins
function. Since plugins can be arbitrary derivations, there is no
guarantee that this attribute will be exposed.

While doing that I also cleaned the toDrv function to only pass
attributes to the builder which are required by the build.

The Terraform 0.13 fallback slug has changed from
`nixpkgs/<provider-owner>/<provider-name>` to `nixpkgs/<provider-name>`
as the owner is also not always available. As a nixpkgs user, all I know
is that the provider is in nixpkgs and his name, the owner information
is not necessarily easy to get by.
gstqt5
zimbatm 2020-10-09 12:44:23 +02:00
parent 3f49e5ba03
commit c79ff8ddca
No known key found for this signature in database
GPG Key ID: 71BAF6D40C1D63D7
2 changed files with 18 additions and 18 deletions

View File

@ -8,24 +8,18 @@ let
list = lib.importJSON ./providers.json; list = lib.importJSON ./providers.json;
toDrv = name: data: toDrv = name: data:
let buildGoPackage {
fallbackProviderSourceAddress = "nixpkgs/${data.owner}/${name}"; pname = data.repo;
providerSourceAddress = data.provider-source-address or fallbackProviderSourceAddress; version = data.version;
in goPackagePath = "github.com/${data.owner}/${data.repo}";
buildGoPackage rec {
inherit (data) owner repo rev version sha256;
name = "${repo}-${version}";
goPackagePath = "github.com/${owner}/${repo}";
subPackages = [ "." ]; subPackages = [ "." ];
src = fetchFromGitHub { src = fetchFromGitHub {
inherit owner repo rev sha256; inherit (data) owner repo rev sha256;
}; };
# Terraform allow checking the provider versions, but this breaks # Terraform allow checking the provider versions, but this breaks
# if the versions are not provided via file paths. # if the versions are not provided via file paths.
postBuild = "mv $NIX_BUILD_TOP/go/bin/${repo}{,_v${version}}"; postBuild = "mv $NIX_BUILD_TOP/go/bin/${data.repo}{,_v${data.version}}";
passthru = { passthru = data;
inherit providerSourceAddress;
};
}; };
# Google is now using the vendored go modules, which works a bit differently # Google is now using the vendored go modules, which works a bit differently

View File

@ -62,21 +62,27 @@ let
# Make providers available in Terraform 0.13 and 0.12 search paths. # Make providers available in Terraform 0.13 and 0.12 search paths.
pluginDir = lib.concatMapStrings (pl: let pluginDir = lib.concatMapStrings (pl: let
inherit (pl) repo version GOOS GOARCH; inherit (pl) version GOOS GOARCH;
inherit (pl.passthru) providerSourceAddress;
pname = pl.pname or (throw "${pl.name} is missing a pname attribute");
# This is just the name, without the terraform-provider- prefix
plugin_name = lib.removePrefix "terraform-provider-" pname;
slug = pl.passthru.provider-source-address or "registry.terraform.io/nixpkgs/${plugin_name}";
shim = writeText "shim" '' shim = writeText "shim" ''
#!${runtimeShell} #!${runtimeShell}
exec ${pl}/bin/${repo}_v${version} \$@ exec ${pl}/bin/${pname}_v${version} "$@"
''; '';
in '' in ''
TF_0_13_PROVIDER_PATH=$out/plugins/${providerSourceAddress}/${version}/${GOOS}_${GOARCH}/${repo}_v${version} TF_0_13_PROVIDER_PATH=$out/plugins/${slug}/${version}/${GOOS}_${GOARCH}/${pname}_v${version}
mkdir -p "$(dirname $TF_0_13_PROVIDER_PATH)" mkdir -p "$(dirname $TF_0_13_PROVIDER_PATH)"
cp ${shim} "$TF_0_13_PROVIDER_PATH" cp ${shim} "$TF_0_13_PROVIDER_PATH"
chmod +x "$TF_0_13_PROVIDER_PATH" chmod +x "$TF_0_13_PROVIDER_PATH"
TF_0_12_PROVIDER_PATH=$out/plugins/${repo}_v${version} TF_0_12_PROVIDER_PATH=$out/plugins/${pname}_v${version}
cp ${shim} "$TF_0_12_PROVIDER_PATH" cp ${shim} "$TF_0_12_PROVIDER_PATH"
chmod +x "$TF_0_12_PROVIDER_PATH" chmod +x "$TF_0_12_PROVIDER_PATH"