git.iko.soy/typeable/nixpkgs
on master help sign in
terraform.withPlugins: clean and remove 0.12 support (#155477)

Now that the terraform 0.12 compatibility is not needed anymore, the `terraform.withPlugins` and `terraform-providers.mkProvider` implementations can be simplified. Instead of building a bunch of bin wrappers on instantiation, the providers are now stored in `$out/libexec/terraform-providers/<registry>/<owner>/<name>/<version>/<os>_<arch>/terraform-provider-<name>_v<version>` and then a simple `buildEnv` can be used to merge them. This breaks back-compat so it's not possible to mix-and-match with previous versions of nixpkgs. In exchange, it now becomes possible to use the providers from [nixpkgs-terraform-providers-bin](https://github.com/numtide/nixpkgs-terraform-providers-bin) directly.

commite7dbfd7ece0e8f11ef0617919cc5597258eda90f authorJonas Chevalier <zimbatm@zimbatm.com> dateMon 24 Jan 2022, 12:53 (5 years ago) parente70ba29
4 files changed+41−45
nixos/doc/manual/from_md/release-notes/rl-2205.section.xml+18 nixos/doc/manual/release-notes/rl-2205.section.md+5 pkgs/applications/networking/cluster/terraform-providers/default.nix+11−4 pkgs/applications/networking/cluster/terraform/default.nix+7−41
nixos/doc/manual/from_md/release-notes/rl-2205.section.xml+18
@@ -397,6 +397,24 @@
397397 <literal>~/.local/share/polymc/polymc.cfg</literal>.
398398 </para>
399399 </listitem>
400+ <listitem>
401+ <para>
402+ The terraform 0.12 compatibility has been removed and the
403+ <literal>terraform.withPlugins</literal> and
404+ <literal>terraform-providers.mkProvider</literal>
405+ implementations simplified. Providers now need to be stored
406+ under
407+ <literal>$out/libexec/terraform-providers/&lt;registry&gt;/&lt;owner&gt;/&lt;name&gt;/&lt;version&gt;/&lt;os&gt;_&lt;arch&gt;/terraform-provider-&lt;name&gt;_v&lt;version&gt;</literal>
408+ (which mkProvider does).
409+ </para>
410+ <para>
411+ This breaks back-compat so it’s not possible to mix-and-match
412+ with previous versions of nixpkgs. In exchange, it now becomes
413+ possible to use the providers from
414+ <link xlink:href="https://github.com/numtide/nixpkgs-terraform-providers-bin">nixpkgs-terraform-providers-bin</link>
415+ directly.
416+ </para>
417+ </listitem>
400418 <listitem>
401419 <para>
402420 <literal>pkgs.noto-fonts-cjk</literal> is now deprecated in
nixos/doc/manual/release-notes/rl-2205.section.md+5
@@ -124,6 +124,11 @@ In addition to numerous new and upgraded packages, this release has the followin
124124
125125- MultiMC has been replaced with the fork PolyMC due to upstream developers being hostile to 3rd party package maintainers. PolyMC removes all MultiMC branding and is aimed at providing proper 3rd party packages like the one contained in Nixpkgs. This change affects the data folder where game instances and other save and configuration files are stored. Users with existing installations should rename `~/.local/share/multimc` to `~/.local/share/polymc`. The main config file's path has also moved from `~/.local/share/multimc/multimc.cfg` to `~/.local/share/polymc/polymc.cfg`.
126126
127+- The terraform 0.12 compatibility has been removed and the `terraform.withPlugins` and `terraform-providers.mkProvider` implementations simplified. Providers now need to be stored under
128+`$out/libexec/terraform-providers/<registry>/<owner>/<name>/<version>/<os>_<arch>/terraform-provider-<name>_v<version>` (which mkProvider does).
129+
130+ This breaks back-compat so it's not possible to mix-and-match with previous versions of nixpkgs. In exchange, it now becomes possible to use the providers from [nixpkgs-terraform-providers-bin](https://github.com/numtide/nixpkgs-terraform-providers-bin) directly.
131+
127132- `pkgs.noto-fonts-cjk` is now deprecated in favor of `pkgs.noto-fonts-cjk-sans`
128133 and `pkgs.noto-fonts-cjk-serif` because they each have different release
129134 schedules. To maintain compatibility with prior releases of Nixpkgs,
pkgs/applications/networking/cluster/terraform-providers/default.nix+11−4
@@ -19,7 +19,8 @@ let
1919 , vendorSha256 ? throw "vendorSha256 missing: please use `buildGoModule`" /* added 2022/01 */
2020 , deleteVendor ? false
2121 , proxyVendor ? false
22− , provider-source-address
22+ , # Looks like "registry.terraform.io/vancluever/acme"
23+ provider-source-address
2324 }@attrs:
2425 buildGoModule {
2526 pname = repo;
@@ -34,9 +35,15 @@ let
3435 inherit owner repo rev sha256;
3536 };
3637
37− # Terraform allow checking the provider versions, but this breaks
38− # if the versions are not provided via file paths.
39− postBuild = "mv $NIX_BUILD_TOP/go/bin/${repo}{,_v${version}}";
38+ # Move the provider to libexec
39+ postInstall = ''
40+ dir=$out/libexec/terraform-providers/${provider-source-address}/${version}/''${GOOS}_''${GOARCH}
41+ mkdir -p "$dir"
42+ mv $out/bin/* "$dir/terraform-provider-$(basename ${provider-source-address})_${version}"
43+ rmdir $out/bin
44+ '';
45+
46+ # Keep the attributes around for later consumption
4047 passthru = attrs;
4148 };
4249
pkgs/applications/networking/cluster/terraform/default.nix+7−41
@@ -1,5 +1,6 @@
11{ stdenv
22, lib
3+, buildEnv
34, buildGoModule
45, fetchFromGitHub
56, makeWrapper
@@ -62,9 +63,9 @@ let
6263 babariviere
6364 kalbasit
6465 marsam
66+ maxeaubrey
6567 timstott
6668 zimbatm
67− maxeaubrey
6869 zowoq
6970 ];
7071 };
@@ -76,39 +77,6 @@ let
7677 let
7778 actualPlugins = plugins terraform.plugins;
7879
79− # Make providers available in Terraform 0.13 and 0.12 search paths.
80− pluginDir = lib.concatMapStrings
81− (pl:
82− let
83− inherit (pl) version GOOS GOARCH;
84−
85− pname = pl.pname or (throw "${pl.name} is missing a pname attribute");
86−
87− # This is just the name, without the terraform-provider- prefix
88− plugin_name = lib.removePrefix "terraform-provider-" pname;
89−
90− slug = pl.passthru.provider-source-address or "registry.terraform.io/nixpkgs/${plugin_name}";
91−
92− shim = writeText "shim" ''
93− #!${runtimeShell}
94− exec ${pl}/bin/${pname}_v${version} "$@"
95− '';
96− in
97− ''
98− TF_0_13_PROVIDER_PATH=$out/plugins/${slug}/${version}/${GOOS}_${GOARCH}/${pname}_v${version}
99− mkdir -p "$(dirname $TF_0_13_PROVIDER_PATH)"
100−
101− cp ${shim} "$TF_0_13_PROVIDER_PATH"
102− chmod +x "$TF_0_13_PROVIDER_PATH"
103−
104− TF_0_12_PROVIDER_PATH=$out/plugins/${pname}_v${version}
105−
106− cp ${shim} "$TF_0_12_PROVIDER_PATH"
107− chmod +x "$TF_0_12_PROVIDER_PATH"
108− ''
109− )
110− actualPlugins;
111−
11280 # Wrap PATH of plugins propagatedBuildInputs, plugins may have runtime dependencies on external binaries
11381 wrapperInputs = lib.unique (lib.flatten
11482 (lib.catAttrs "propagatedBuildInputs"
@@ -134,18 +102,16 @@ let
134102 terraform.overrideAttrs
135103 (orig: { passthru = orig.passthru // passthru; })
136104 else
137− lib.appendToName "with-plugins" (stdenv.mkDerivation {
105+ lib.appendToName "with-plugins" (buildEnv {
138106 inherit (terraform) name meta;
107+ paths = actualPlugins;
139108 nativeBuildInputs = [ makeWrapper ];
140−
141− buildCommand = pluginDir + ''
142− mkdir -p $out/bin/
109+ postBuild = ''
110+ mkdir -p $out/bin
143111 makeWrapper "${terraform}/bin/terraform" "$out/bin/terraform" \
144− --set NIX_TERRAFORM_PLUGIN_DIR $out/plugins \
112+ --set NIX_TERRAFORM_PLUGIN_DIR $out/libexec/terraform-providers \
145113 --prefix PATH : "${lib.makeBinPath wrapperInputs}"
146114 '';
147−
148− inherit passthru;
149115 });
150116 in
151117 withPlugins (_: [ ]);