docs: improve go builder comments in module.nix (#341561)

This commit is contained in:
Paul Meyer 2024-10-14 07:39:53 +02:00 committed by GitHub
commit 7e823e977e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,56 +1,62 @@
{ go, cacert, git, lib, stdenv }: { go, cacert, git, lib, stdenv }:
{ name ? "${args'.pname}-${args'.version}" { name ? "${args'.pname}-${args'.version}"
# The source used to build the derivation.
, src , src
# Native build inputs used for the derivation.
, nativeBuildInputs ? [ ] , nativeBuildInputs ? [ ]
, passthru ? { } , passthru ? { }
, patches ? [ ] , patches ? [ ]
# A function to override the goModules derivation # A function to override the `goModules` derivation.
, overrideModAttrs ? (finalAttrs: previousAttrs: { }) , overrideModAttrs ? (finalAttrs: previousAttrs: { })
# path to go.mod and go.sum directory # Directory to the `go.mod` and `go.sum` relative to the `src`.
, modRoot ? "./" , modRoot ? "./"
# vendorHash is the SRI hash of the vendored dependencies # The SRI hash of the vendored dependencies.
# # If `vendorHash` is `null`, no dependencies are fetched and
# if vendorHash is null, then we won't fetch any dependencies and # the build relies on the vendor folder within the source.
# rely on the vendor folder within the source.
, vendorHash ? throw ( , vendorHash ? throw (
if args'?vendorSha256 then if args'?vendorSha256 then
"buildGoModule: Expect vendorHash instead of vendorSha256" "buildGoModule: Expect vendorHash instead of vendorSha256"
else else
"buildGoModule: vendorHash is missing" "buildGoModule: vendorHash is missing"
) )
# Whether to delete the vendor folder supplied with the source. # Whether to delete the vendor folder supplied with the source.
, deleteVendor ? false , deleteVendor ? false
# Whether to fetch (go mod download) and proxy the vendor directory. # Whether to fetch (go mod download) and proxy the vendor directory.
# This is useful if your code depends on c code and go mod tidy does not # This is useful if your code depends on c code and go mod tidy does not
# include the needed sources to build or if any dependency has case-insensitive # include the needed sources to build or if any dependency has case-insensitive
# conflicts which will produce platform dependant `vendorHash` checksums. # conflicts which will produce platform dependant `vendorHash` checksums.
, proxyVendor ? false , proxyVendor ? false
# We want parallel builds by default # We want parallel builds by default.
, enableParallelBuilding ? true , enableParallelBuilding ? true
# Do not enable this without good reason # Do not enable this without good reason
# IE: programs coupled with the compiler # IE: programs coupled with the compiler.
, allowGoReference ? false , allowGoReference ? false
# Go env. variable to enable CGO.
, CGO_ENABLED ? go.CGO_ENABLED , CGO_ENABLED ? go.CGO_ENABLED
# Meta data for the final derivation.
, meta ? { } , meta ? { }
# Not needed with buildGoModule # Not needed with `buildGoModule`.
, goPackagePath ? "" , goPackagePath ? ""
# Go linker flags.
, ldflags ? [ ] , ldflags ? [ ]
# Go build flags.
, GOFLAGS ? [ ] , GOFLAGS ? [ ]
# needed for buildFlags{,Array} warning # Needed for buildFlags{,Array} warning
, buildFlags ? "" , buildFlags ? "" # deprecated
, buildFlagsArray ? "" , buildFlagsArray ? "" # deprecated
, ... , ...
}@args': }@args':
@ -79,10 +85,10 @@ in
inherit (go) GOOS GOARCH; inherit (go) GOOS GOARCH;
inherit GO111MODULE GOTOOLCHAIN; inherit GO111MODULE GOTOOLCHAIN;
# The following inheritence behavior is not trivial to expect, and some may # The following inheritance behavior is not trivial to expect, and some may
# argue it's not ideal. Changing it may break vendor hashes in Nixpkgs and # argue it's not ideal. Changing it may break vendor hashes in Nixpkgs and
# out in the wild. In anycase, it's documented in: # out in the wild. In anycase, it's documented in:
# doc/languages-frameworks/go.section.md # doc/languages-frameworks/go.section.md.
prePatch = finalAttrs.prePatch or ""; prePatch = finalAttrs.prePatch or "";
patches = finalAttrs.patches or [ ]; patches = finalAttrs.patches or [ ];
patchFlags = finalAttrs.patchFlags or [ ]; patchFlags = finalAttrs.patchFlags or [ ];
@ -160,8 +166,8 @@ in
outputHashMode = "recursive"; outputHashMode = "recursive";
outputHash = finalAttrs.vendorHash; outputHash = finalAttrs.vendorHash;
# Handle empty vendorHash; avoid # Handle empty `vendorHash`; avoid error:
# error: empty hash requires explicit hash algorithm # empty hash requires explicit hash algorithm.
outputHashAlgo = if finalAttrs.vendorHash == "" then "sha256" else null; outputHashAlgo = if finalAttrs.vendorHash == "" then "sha256" else null;
# in case an overlay clears passthru by accident, don't fail evaluation # in case an overlay clears passthru by accident, don't fail evaluation
}).overrideAttrs (finalAttrs.passthru.overrideModAttrs or overrideModAttrs); }).overrideAttrs (finalAttrs.passthru.overrideModAttrs or overrideModAttrs);
@ -323,7 +329,7 @@ in
} // passthru; } // passthru;
meta = { meta = {
# Add default meta information # Add default meta information.
platforms = go.meta.platforms or lib.platforms.all; platforms = go.meta.platforms or lib.platforms.all;
} // meta; } // meta;
} }