From f3fa6bfe96a03323e8e180889ddb6f5a688290e9 Mon Sep 17 00:00:00 2001 From: zimbatm Date: Thu, 13 Jan 2022 21:56:07 +0100 Subject: [PATCH] terraform-providers.mkProvider: cleanup Remove the layer of indirection. Expose what parameters are expected from the function call. --- .../cluster/terraform-providers/default.nix | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/pkgs/applications/networking/cluster/terraform-providers/default.nix b/pkgs/applications/networking/cluster/terraform-providers/default.nix index a9a5ca93711c..109951dfdd1c 100644 --- a/pkgs/applications/networking/cluster/terraform-providers/default.nix +++ b/pkgs/applications/networking/cluster/terraform-providers/default.nix @@ -7,34 +7,40 @@ , cdrtools # libvirt }: let - list = lib.importJSON ./providers.json; - - buildWithGoModule = data: + # Our generic constructor to build new providers. + # + # Is designed to combine with the terraform.withPlugins implementation. + mkProvider = + { owner + , repo + , rev + , version + , sha256 + , vendorSha256 ? throw "vendorSha256 missing: please use `buildGoModule`" /* added 2022/01 */ + , deleteVendor ? false + , proxyVendor ? false + , provider-source-address + }@attrs: buildGoModule { - pname = data.repo; - inherit (data) vendorSha256 version; + pname = repo; + inherit vendorSha256 version deleteVendor proxyVendor; subPackages = [ "." ]; doCheck = false; # https://github.com/hashicorp/terraform-provider-scaffolding/blob/a8ac8375a7082befe55b71c8cbb048493dd220c2/.goreleaser.yml # goreleaser (used for builds distributed via terraform registry) requires that CGO is disabled CGO_ENABLED = 0; - ldflags = [ "-s" "-w" "-X main.version=${data.version}" "-X main.commit=${data.rev}" ]; + ldflags = [ "-s" "-w" "-X main.version=${version}" "-X main.commit=${rev}" ]; src = fetchFromGitHub { - inherit (data) owner repo rev sha256; + inherit owner repo rev sha256; }; - deleteVendor = data.deleteVendor or false; - proxyVendor = data.proxyVendor or false; # 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/${data.repo}{,_v${data.version}}"; - passthru = data; + postBuild = "mv $NIX_BUILD_TOP/go/bin/${repo}{,_v${version}}"; + passthru = attrs; }; - # Our generic constructor to build new providers - mkProvider = attrs: - (if (lib.hasAttr "vendorSha256" attrs) then buildWithGoModule else throw /* added 2022/01 */ "vendorSha256 missing: please use `buildGoModule`") - attrs; + list = lib.importJSON ./providers.json; # These providers are managed with the ./update-all script automated-providers = lib.mapAttrs (_: attrs: mkProvider attrs) list;