diff --git a/pkgs/applications/networking/cluster/terraform-providers/default.nix b/pkgs/applications/networking/cluster/terraform-providers/default.nix index d6426a2314c4..73fc6df024e6 100644 --- a/pkgs/applications/networking/cluster/terraform-providers/default.nix +++ b/pkgs/applications/networking/cluster/terraform-providers/default.nix @@ -8,24 +8,18 @@ let list = lib.importJSON ./providers.json; 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}"; - goPackagePath = "github.com/${owner}/${repo}"; + buildGoPackage { + pname = data.repo; + version = data.version; + goPackagePath = "github.com/${data.owner}/${data.repo}"; subPackages = [ "." ]; src = fetchFromGitHub { - inherit owner repo rev sha256; + inherit (data) owner repo rev sha256; }; # 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; - }; + postBuild = "mv $NIX_BUILD_TOP/go/bin/${data.repo}{,_v${data.version}}"; + passthru = data; }; # Google is now using the vendored go modules, which works a bit differently diff --git a/pkgs/applications/networking/cluster/terraform/default.nix b/pkgs/applications/networking/cluster/terraform/default.nix index 298d80bcbaa1..6153eaa145c9 100644 --- a/pkgs/applications/networking/cluster/terraform/default.nix +++ b/pkgs/applications/networking/cluster/terraform/default.nix @@ -62,21 +62,27 @@ let # 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; + inherit (pl) version GOOS GOARCH; + + 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" '' #!${runtimeShell} - exec ${pl}/bin/${repo}_v${version} \$@ + exec ${pl}/bin/${pname}_v${version} "$@" ''; 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)" cp ${shim} "$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" chmod +x "$TF_0_12_PROVIDER_PATH"