GO-MODULE(5)

πŸ“¦ in nixpkgs unstable

🐹 go-module(5) β€” the lang/go port module, explained bestie to bestie

okay so this is from the File Formats Manual section of the man pages (yes, go-module(5), that's her full name πŸ’…) and it's literally the entire personality of setting MODULES=lang/go in the ports(7) tree. Buckle up πŸŽ€


✨ NAME ✨

go-module β€” the lang/go port module. that's it, that's the whole name, she's iconic like that πŸ‘‘


🌸 DESCRIPTION 🌸

This page documents exactly what happens when you set MODULES=lang/go in the ports(7) tree. no cap, every detail is here 🫢

πŸ¦‹ What it actually does

It adds Go toolchain support. periodt. and it requires ALL_TARGET to be set to the canonical Go import path of the port. (good news tho: the module sets it automatically for ports that use the GH_ACCOUNT and GH_PROJECT macros, so you don't gotta do it yourself πŸ’–)

πŸŽ€ The build pipeline, step by step

  • During pre-configure β€” the module moves the source code from ${MODGO_SUBDIR} to ${WRKSRC}, which is a subdirectory of ${MODGO_WORKSPACE} β€” a specially-crafted Go workspace located at ${WRKDIR}/go. moving day! 🚚
  • During do-build β€” the module calls go install with GOPATH set to ${MODGO_WORKSPACE}, runs its output through sed to prevent writes outside the WRKDIR sandbox, and sends the output to sh(1). the sed glow-up is doing SO much work here ngl ✨
  • During do-install β€” it copies executables from ${MODGO_WORKSPACE}/bin to ${PREFIX}/bin, and/or the directories ${MODGO_WORKSPACE}/pkg and ${MODGO_WORKSPACE}/src to ${PREFIX}/go, all depending on what's in MODGO_TYPE. it's giving "choose your own adventure" 🧚

⭐ Stuff it sets for you

It sets BUILD_DEPENDS, RUN_DEPENDS, ALL_TARGET, TEST_TARGET, ONLY_FOR_ARCHS, SEPARATE_BUILD, and WRKSRC. so many presets, so little effort from you πŸ’…

It also appends to CATEGORIES.


πŸ’œ The variables it defines πŸ’œ

  • MODGO_TYPE β€” the type of port. can be any combination of:
    • bin β€” an ordinary binary, which should be installed to ${PREFIX}/bin
    • lib β€” a library, which should come with source code
    • defaults to bin. simple, classic, reliable πŸ“
  • MODGO_WORKSPACE β€” path to the Go workspace set up for the port build process. defaults to ${WRKDIR}/go. see the Go documentation for details, iykyk πŸ“š
  • MODGO_SUBDIR β€” path to the Go source code within the port's sources tarball. defaults to ${WRKDIST}.
  • MODGO_SETUP_WORKSPACE β€” the commands that set up the Go workspace for building ports. by default this happens during execution of the pre-configure target.
  • MODGO_BUILDDEP β€” controls whether the contents of MODGO_BUILD_DEPENDS get appended to the port's BUILD_DEPENDS. defaults to Yes βœ…
  • MODGO_MODNAME β€” the name of the Go module as defined in the go.mod file contained in the project. > if this is set, MODGO_MODULES, MODGO_MODFILES and MODGO_VERSION need to be defined as well β€” all four or nothing bestie, no skipping 😀 Setting this will also set ALL_TARGET. and when MODGO_MODFILES is set and a "cmd" directory is found in WRKSRC, then "./cmd/..." is also built by do-build automatically. sneak attack build πŸ”₯
  • MODGO_VERSION β€” sets the specific version of a Go module to use. for example: v0.1.3.
  • MODGO_MODULES β€” the list of modules and their specific versions that an application depends on.
  • MODGO_MODFILES β€” the list of go.mod files and their versions that are required for dependency resolution. these are required by Go to determine the full dependency graph β€” like, mandatory mandatory 🫢

🌈 And there's more (the bonus round)

Additionally it defines:

  • MODGO_ARCH β€” application architecture name used by Go
  • MODGO_PACKAGES, MODGO_SOURCES and MODGO_TOOLS β€” paths for installed Go packages, sources and tools respectively
  • MODGO_CMD and MODGO_FLAGS β€” the source code build command and the flags passed as its arguments
  • MODGO_LDFLAGS
  • MODGO_BUILD_CMD and MODGO_TEST_CMD β€” commands for building and testing go packages; normally called with canonical Go package names as arguments
  • MODGO_{BUILD,INSTALL,TEST}_TARGET
  • MODGO_{BUILD,RUN}_DEPENDS

the curly braces are literally serving cunt, she's efficient πŸ’€βœ¨


πŸ‘‘ The make(1) target πŸ‘‘

This module adds exactly one make(1) target:

  • modgo-gen-modules β€” generate the MODGO_MODULES and the MODGO_MODFILES lists. if MODGO_VERSION is set to "latest", the latest known-to-Go version of a package will be used to build the list of modules. similarly, if MODGO_VERSION is empty, the latest version will be fetched. auto-magic, we love to see it ⭐

πŸ’– SEE ALSO πŸ’–

  • port-modules(5) β€” go read that one next, bestie, it's the whole family πŸ¦‹

friendly reminder that this is a real build system and the sandbox rules are there for a reason β€” the sed write-prevention step is not decorative, it's literally protecting your WRKDIR. respect the sandbox πŸ™ˆ

🌸 aaaand that's the page! this cutie comes to you courtesy of Debian, dated February 7, 2025 β€” she's fresh, she's official, she's slaying. bye bestie, happy porting πŸ’…πŸ’œπŸŽ€

πŸ“¦ where this page comes from