diff options
author | Weijia Wang <9713184+wegank@users.noreply.github.com> | 2024-03-28 10:58:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-28 10:58:18 +0100 |
commit | cb00e17a14a508d9337326a110704481313d1b91 (patch) | |
tree | 0b15cf55c43ae19e2fe84832eb6def966222a638 /pkgs/build-support | |
parent | af8fd52e05c81eafcfd4fb9fe7d3553b61472712 (diff) | |
parent | c9da94beffb66d14a0a9188038dd4d1514e1ec56 (diff) |
Merge pull request #299169 from ShamrockLee/go-module-vendorsha256
buildGoModule: Deprecate vendorSha256 with throw
Diffstat (limited to 'pkgs/build-support')
-rw-r--r-- | pkgs/build-support/go/module.nix | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/pkgs/build-support/go/module.nix b/pkgs/build-support/go/module.nix index 7d2960f699dc7..ab8491da34cd4 100644 --- a/pkgs/build-support/go/module.nix +++ b/pkgs/build-support/go/module.nix @@ -16,7 +16,12 @@ # # if vendorHash is null, then we won't fetch any dependencies and # rely on the vendor folder within the source. -, vendorHash ? args'.vendorSha256 or (throw "buildGoModule: vendorHash is missing") +, vendorHash ? throw ( + if args'?vendorSha256 then + "buildGoModule: Expect vendorHash instead of vendorSha256" + else + "buildGoModule: vendorHash is missing" + ) # Whether to delete the vendor folder supplied with the source. , deleteVendor ? false # Whether to fetch (go mod download) and proxy the vendor directory. @@ -51,7 +56,6 @@ }@args': assert goPackagePath != "" -> throw "`goPackagePath` is not needed with `buildGoModule`"; -assert (args' ? vendorHash && args' ? vendorSha256) -> throw "both `vendorHash` and `vendorSha256` set. only one can be set."; let args = removeAttrs args' [ "overrideModAttrs" "vendorSha256" "vendorHash" ]; @@ -147,7 +151,9 @@ let outputHashMode = "recursive"; outputHash = vendorHash; - outputHashAlgo = if args' ? vendorSha256 || vendorHash == "" then "sha256" else null; + # Handle empty vendorHash; avoid + # error: empty hash requires explicit hash algorithm + outputHashAlgo = if vendorHash == "" then "sha256" else null; }).overrideAttrs overrideModAttrs; package = stdenv.mkDerivation (args // { @@ -298,8 +304,7 @@ let disallowedReferences = lib.optional (!allowGoReference) go; - passthru = passthru // { inherit go goModules vendorHash; } - // lib.optionalAttrs (args' ? vendorSha256 ) { inherit (args') vendorSha256; }; + passthru = passthru // { inherit go goModules vendorHash; }; meta = { # Add default meta information @@ -307,7 +312,6 @@ let } // meta; }); in -lib.warnIf (args' ? vendorSha256) "`vendorSha256` is deprecated. Use `vendorHash` instead" lib.warnIf (buildFlags != "" || buildFlagsArray != "") "Use the `ldflags` and/or `tags` attributes instead of `buildFlags`/`buildFlagsArray`" lib.warnIf (builtins.elem "-buildid=" ldflags) "`-buildid=` is set by default as ldflag by buildGoModule" |