From d8f7d3527ee4beac19d73db953541e7cc67cf89e Mon Sep 17 00:00:00 2001 From: Zhong Jianxin Date: Mon, 31 Mar 2025 20:27:25 +0800 Subject: [PATCH] opentofu: Allow using terraform-providers.* from binary cache Currently `opentofu.withPlugins(p: [p.])` causes `` to rebuild. Since we build terraform-providers.* from source, overriding homepage of terraform-providers.* only affects their `postInstall` phase, the providers binaries remain the same. We can avoid the provider rebuilds by creating the right dir in the wrapper. --- pkgs/by-name/op/opentofu/package.nix | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/pkgs/by-name/op/opentofu/package.nix b/pkgs/by-name/op/opentofu/package.nix index 85d9952b8c52..e73a6e6b27f0 100644 --- a/pkgs/by-name/op/opentofu/package.nix +++ b/pkgs/by-name/op/opentofu/package.nix @@ -108,28 +108,7 @@ let withPlugins = plugins: let - actualPlugins = lib.lists.map ( - provider: - if provider ? override then - # use opentofu plugin registry over terraform's - provider.override ( - oldArgs: - if (builtins.hasAttr "homepage" oldArgs) then - { - provider-source-address = - lib.replaceStrings - [ "https://registry.terraform.io/providers" ] - [ - "registry.opentofu.org" - ] - oldArgs.homepage; - } - else - { } - ) - else - provider - ) (plugins package.plugins); + actualPlugins = plugins package.plugins; # Wrap PATH of plugins propagatedBuildInputs, plugins may have runtime dependencies on external binaries wrapperInputs = lib.unique ( @@ -183,13 +162,16 @@ let passthru = package.passthru // passthru; buildCommand = '' - # Create wrappers for terraform plugins because Terraform only + # Create wrappers for terraform plugins because OpenTofu only # walks inside of a tree of files. + # Also replace registry.terraform.io dir with registry.opentofu.org, + # so OpenTofu can find the plugins. for providerDir in ${toString actualPlugins} do for file in $(find $providerDir/libexec/terraform-providers -type f) do relFile=''${file#$providerDir/} + relFile=''${relFile/registry.terraform.io/registry.opentofu.org} mkdir -p $out/$(dirname $relFile) cat < $out/$relFile #!${runtimeShell}