Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 24 additions & 18 deletions pkgs/build-support/go/module.nix
Original file line number Diff line number Diff line change
@@ -1,56 +1,62 @@
{ go, cacert, git, lib, stdenv }:

{ name ? "${args'.pname}-${args'.version}"
# The source used to build the derivation.
, src
# Native build inputs used for the derivation.
, nativeBuildInputs ? [ ]
, passthru ? { }
, patches ? [ ]

# A function to override the goModules derivation
# A function to override the `goModules` derivation.
, overrideModAttrs ? (finalAttrs: previousAttrs: { })

# path to go.mod and go.sum directory
# Directory to the `go.mod` and `go.sum` relative to the `src`.
, modRoot ? "./"

# vendorHash is the SRI hash of the vendored dependencies
#
# if vendorHash is null, then we won't fetch any dependencies and
# rely on the vendor folder within the source.
# The SRI hash of the vendored dependencies.
# If `vendorHash` is `null`, no dependencies are fetched and
# the build relies on the vendor folder within the source.
, 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.
# 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
# conflicts which will produce platform dependant `vendorHash` checksums.
, proxyVendor ? false

# We want parallel builds by default
# We want parallel builds by default.
, enableParallelBuilding ? true

# Do not enable this without good reason
# IE: programs coupled with the compiler
# IE: programs coupled with the compiler.
, allowGoReference ? false

# Go env. variable to enable CGO.
, CGO_ENABLED ? go.CGO_ENABLED

# Meta data for the final derivation.
, meta ? { }

# Not needed with buildGoModule
# Not needed with `buildGoModule`.
, goPackagePath ? ""

# Go linker flags.
, ldflags ? [ ]

# Go build flags.
, GOFLAGS ? [ ]

# needed for buildFlags{,Array} warning
, buildFlags ? ""
, buildFlagsArray ? ""
# Needed for buildFlags{,Array} warning
, buildFlags ? "" # deprecated
, buildFlagsArray ? "" # deprecated

, ...
}@args':
Expand Down Expand Up @@ -79,10 +85,10 @@ in
inherit (go) GOOS GOARCH;
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
# 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 "";
patches = finalAttrs.patches or [ ];
patchFlags = finalAttrs.patchFlags or [ ];
Expand Down Expand Up @@ -160,8 +166,8 @@ in

outputHashMode = "recursive";
outputHash = finalAttrs.vendorHash;
# Handle empty vendorHash; avoid
# error: empty hash requires explicit hash algorithm
# Handle empty `vendorHash`; avoid error:
# empty hash requires explicit hash algorithm.
outputHashAlgo = if finalAttrs.vendorHash == "" then "sha256" else null;
# in case an overlay clears passthru by accident, don't fail evaluation
}).overrideAttrs (finalAttrs.passthru.overrideModAttrs or overrideModAttrs);
Expand Down Expand Up @@ -323,7 +329,7 @@ in
} // passthru;

meta = {
# Add default meta information
# Add default meta information.
platforms = go.meta.platforms or lib.platforms.all;
} // meta;
}
Expand Down