0
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-07-14 06:00:33 +03:00

[Backport release-24.11] opentofu: 1.8.5 -> 1.8.7 (#362838)

This commit is contained in:
Aleksana 2024-12-08 17:27:27 +08:00 committed by GitHub
commit 4a730afe1b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,30 +1,36 @@
{ stdenv {
, lib stdenv,
, buildGoModule lib,
, fetchFromGitHub buildGoModule,
, makeWrapper fetchFromGitHub,
, coreutils makeWrapper,
, runCommand coreutils,
, runtimeShell runCommand,
, writeText runtimeShell,
, terraform-providers writeText,
, installShellFiles terraform-providers,
installShellFiles,
}: }:
let let
package = buildGoModule rec { package = buildGoModule rec {
pname = "opentofu"; pname = "opentofu";
version = "1.8.5"; version = "1.8.7";
src = fetchFromGitHub { src = fetchFromGitHub {
owner = "opentofu"; owner = "opentofu";
repo = "opentofu"; repo = "opentofu";
rev = "v${version}"; rev = "v${version}";
hash = "sha256-sZGKM6Dxz0bZkHIITujojSsKtRD4E+q1uReWRg5EfC8="; hash = "sha256-OLXR9aA94KcIsZxk8gOZxZsljMKuymScuYcoj9W5Hj4=";
}; };
vendorHash = "sha256-cM2DSP2ss3vleUhPBIdyxKeWJxtHpdjL5b5HVS/iC6o="; vendorHash = "sha256-6M/uqwhNruIPx5srbimKuDJaFiZkyosoZQXWjxa6GxY=";
ldflags = [ "-s" "-w" "-X" "github.com/opentofu/opentofu/version.dev=no" ]; ldflags = [
"-s"
"-w"
"-X"
"github.com/opentofu/opentofu/version.dev=no"
];
postConfigure = '' postConfigure = ''
# speakeasy hardcodes /bin/stty https://github.com/bgentry/speakeasy/issues/22 # speakeasy hardcodes /bin/stty https://github.com/bgentry/speakeasy/issues/22
@ -37,7 +43,9 @@ let
passthru = { passthru = {
inherit full plugins withPlugins; inherit full plugins withPlugins;
tests = { inherit opentofu_plugins_test; }; tests = {
inherit opentofu_plugins_test;
};
}; };
# https://github.com/posener/complete/blob/9a4745ac49b29530e07dc2581745a218b646b7a3/cmd/install/bash.go#L8 # https://github.com/posener/complete/blob/9a4745ac49b29530e07dc2581745a218b646b7a3/cmd/install/bash.go#L8
@ -67,29 +75,28 @@ let
full = withPlugins (p: lib.filter lib.isDerivation (lib.attrValues p.actualProviders)); full = withPlugins (p: lib.filter lib.isDerivation (lib.attrValues p.actualProviders));
opentofu_plugins_test = let opentofu_plugins_test =
mainTf = writeText "main.tf" '' let
terraform { mainTf = writeText "main.tf" ''
required_providers { terraform {
random = { required_providers {
source = "registry.terraform.io/hashicorp/random" random = {
source = "registry.terraform.io/hashicorp/random"
}
} }
} }
}
resource "random_id" "test" {} resource "random_id" "test" {}
''; '';
opentofu = package.withPlugins (p: [ p.random ]); opentofu = package.withPlugins (p: [ p.random ]);
test = runCommand "opentofu-plugin-test" { test = runCommand "opentofu-plugin-test" { buildInputs = [ opentofu ]; } ''
buildInputs = [ opentofu ]; # make it fail outside of sandbox
} '' export HTTP_PROXY=http://127.0.0.1:0 HTTPS_PROXY=https://127.0.0.1:0
# make it fail outside of sandbox cp ${mainTf} main.tf
export HTTP_PROXY=http://127.0.0.1:0 HTTPS_PROXY=https://127.0.0.1:0 tofu init
cp ${mainTf} main.tf touch $out
tofu init '';
touch $out in
'';
in
test; test;
plugins = removeAttrs terraform-providers [ plugins = removeAttrs terraform-providers [
@ -98,18 +105,18 @@ let
"recurseForDerivations" "recurseForDerivations"
]; ];
withPlugins = plugins: withPlugins =
plugins:
let let
actualPlugins = plugins package.plugins; actualPlugins = plugins package.plugins;
# Wrap PATH of plugins propagatedBuildInputs, plugins may have runtime dependencies on external binaries # Wrap PATH of plugins propagatedBuildInputs, plugins may have runtime dependencies on external binaries
wrapperInputs = lib.unique (lib.flatten wrapperInputs = lib.unique (
(lib.catAttrs "propagatedBuildInputs" lib.flatten (lib.catAttrs "propagatedBuildInputs" (builtins.filter (x: x != null) actualPlugins))
(builtins.filter (x: x != null) actualPlugins))); );
passthru = { passthru = {
withPlugins = newplugins: withPlugins = newplugins: withPlugins (x: newplugins x ++ actualPlugins);
withPlugins (x: newplugins x ++ actualPlugins);
# Expose wrappers around the override* functions of the terraform # Expose wrappers around the override* functions of the terraform
# derivation. # derivation.
@ -131,21 +138,20 @@ let
# 3. Specifying overrides on the wrapper is unsupported. # 3. Specifying overrides on the wrapper is unsupported.
# #
# See nixpkgs#158620 for details. # See nixpkgs#158620 for details.
overrideDerivation = f: overrideDerivation = f: (package.overrideDerivation f).withPlugins plugins;
(package.overrideDerivation f).withPlugins plugins; overrideAttrs = f: (package.overrideAttrs f).withPlugins plugins;
overrideAttrs = f: override = x: (package.override x).withPlugins plugins;
(package.overrideAttrs f).withPlugins plugins;
override = x:
(package.override x).withPlugins plugins;
}; };
# Don't bother wrapping unless we actually have plugins, since the wrapper will stop automatic downloading
# of plugins, which might be counterintuitive if someone just wants a vanilla Terraform.
in in
if actualPlugins == [ ] then # Don't bother wrapping unless we actually have plugins, since the wrapper will stop automatic downloading
package.overrideAttrs # of plugins, which might be counterintuitive if someone just wants a vanilla Terraform.
(orig: { passthru = orig.passthru // passthru; }) if actualPlugins == [ ] then
else package.overrideAttrs (orig: {
lib.appendToName "with-plugins" (stdenv.mkDerivation { passthru = orig.passthru // passthru;
})
else
lib.appendToName "with-plugins" (
stdenv.mkDerivation {
inherit (package) meta pname version; inherit (package) meta pname version;
nativeBuildInputs = [ makeWrapper ]; nativeBuildInputs = [ makeWrapper ];
@ -178,6 +184,7 @@ let
--set NIX_TERRAFORM_PLUGIN_DIR $out/libexec/terraform-providers \ --set NIX_TERRAFORM_PLUGIN_DIR $out/libexec/terraform-providers \
--prefix PATH : "${lib.makeBinPath wrapperInputs}" --prefix PATH : "${lib.makeBinPath wrapperInputs}"
''; '';
}); }
);
in in
package package