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.
main
Jonas Chevalier 2 years ago committed by GitHub
parent e70ba2998d
commit e7dbfd7ece
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      nixos/doc/manual/from_md/release-notes/rl-2205.section.xml
  2. 5
      nixos/doc/manual/release-notes/rl-2205.section.md
  3. 15
      pkgs/applications/networking/cluster/terraform-providers/default.nix
  4. 48
      pkgs/applications/networking/cluster/terraform/default.nix

@ -397,6 +397,24 @@
<literal>~/.local/share/polymc/polymc.cfg</literal>.
</para>
</listitem>
<listitem>
<para>
The terraform 0.12 compatibility has been removed and the
<literal>terraform.withPlugins</literal> and
<literal>terraform-providers.mkProvider</literal>
implementations simplified. Providers now need to be stored
under
<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>
(which mkProvider does).
</para>
<para>
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
<link xlink:href="https://github.com/numtide/nixpkgs-terraform-providers-bin">nixpkgs-terraform-providers-bin</link>
directly.
</para>
</listitem>
<listitem>
<para>
<literal>pkgs.noto-fonts-cjk</literal> is now deprecated in

@ -124,6 +124,11 @@ In addition to numerous new and upgraded packages, this release has the followin
- 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`.
- 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
`$out/libexec/terraform-providers/<registry>/<owner>/<name>/<version>/<os>_<arch>/terraform-provider-<name>_v<version>` (which mkProvider does).
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.
- `pkgs.noto-fonts-cjk` is now deprecated in favor of `pkgs.noto-fonts-cjk-sans`
and `pkgs.noto-fonts-cjk-serif` because they each have different release
schedules. To maintain compatibility with prior releases of Nixpkgs,

@ -19,7 +19,8 @@ let
, vendorSha256 ? throw "vendorSha256 missing: please use `buildGoModule`" /* added 2022/01 */
, deleteVendor ? false
, proxyVendor ? false
, provider-source-address
, # Looks like "registry.terraform.io/vancluever/acme"
provider-source-address
}@attrs:
buildGoModule {
pname = repo;
@ -34,9 +35,15 @@ let
inherit 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}}";
# Move the provider to libexec
postInstall = ''
dir=$out/libexec/terraform-providers/${provider-source-address}/${version}/''${GOOS}_''${GOARCH}
mkdir -p "$dir"
mv $out/bin/* "$dir/terraform-provider-$(basename ${provider-source-address})_${version}"
rmdir $out/bin
'';
# Keep the attributes around for later consumption
passthru = attrs;
};

@ -1,5 +1,6 @@
{ stdenv
, lib
, buildEnv
, buildGoModule
, fetchFromGitHub
, makeWrapper
@ -62,9 +63,9 @@ let
babariviere
kalbasit
marsam
maxeaubrey
timstott
zimbatm
maxeaubrey
zowoq
];
};
@ -76,39 +77,6 @@ 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) 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/${pname}_v${version} "$@"
'';
in
''
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/${pname}_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"
@ -134,18 +102,16 @@ let
terraform.overrideAttrs
(orig: { passthru = orig.passthru // passthru; })
else
lib.appendToName "with-plugins" (stdenv.mkDerivation {
lib.appendToName "with-plugins" (buildEnv {
inherit (terraform) name meta;
paths = actualPlugins;
nativeBuildInputs = [ makeWrapper ];
buildCommand = pluginDir + ''
mkdir -p $out/bin/
postBuild = ''
mkdir -p $out/bin
makeWrapper "${terraform}/bin/terraform" "$out/bin/terraform" \
--set NIX_TERRAFORM_PLUGIN_DIR $out/plugins \
--set NIX_TERRAFORM_PLUGIN_DIR $out/libexec/terraform-providers \
--prefix PATH : "${lib.makeBinPath wrapperInputs}"
'';
inherit passthru;
});
in
withPlugins (_: [ ]);

Loading…
Cancel
Save