Skip to content

WIP: experiment with a hook based alternative to buildGoModule#353526

Draft
TomaSajt wants to merge 3 commits intoNixOS:masterfrom
TomaSajt:go-build-support-refactor
Draft

WIP: experiment with a hook based alternative to buildGoModule#353526
TomaSajt wants to merge 3 commits intoNixOS:masterfrom
TomaSajt:go-build-support-refactor

Conversation

@TomaSajt
Copy link
Contributor

@TomaSajt TomaSajt commented Nov 3, 2024

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@TomaSajt TomaSajt marked this pull request as draft November 3, 2024 22:48
@github-actions github-actions bot added the 6.topic: golang Go is a high-level general purpose programming language that is statically typed and compiled. label Nov 3, 2024
@TomaSajt TomaSajt force-pushed the go-build-support-refactor branch from 5381b6c to 1c1769a Compare November 3, 2024 22:59
@ofborg ofborg bot added 11.by: package-maintainer This PR was created by a maintainer of all the package it changes. 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels Nov 4, 2024
Comment on lines +130 to +138
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the motivation of this PR is to increase composability, meaning constructing one call to stdenv.mkDerivation with functionalities provided by more than one build helpers, such as buildGoModule and rustPlatform.buildRustPackage.

Would it be more composable if we also add goBuildHook (with runHook removed, of course) to preBuildHooks or postBuildHooks?

Use case: one package, with its own buildPhase, wants to build some go stuff.

Here is my implementation of this idea for Rust: #334476.

@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Nov 10, 2024
@TomaSajt TomaSajt force-pushed the go-build-support-refactor branch 2 times, most recently from cd1a821 to 4d6cb5e Compare November 13, 2024 00:21
@ofborg ofborg bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Nov 13, 2024
@TomaSajt TomaSajt force-pushed the go-build-support-refactor branch from 4d6cb5e to 083a109 Compare November 15, 2024 12:30
@ofborg ofborg bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Nov 15, 2024
@TomaSajt TomaSajt force-pushed the go-build-support-refactor branch from 083a109 to 9273a74 Compare November 26, 2024 15:16
@ofborg ofborg bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Nov 27, 2024
@katexochen
Copy link
Contributor

I like the idea of moving to a hook based alternative, but I think it will need some discussion on how exactly such a future builder would look like. Maybe you can make your experiment consumable via an out-of-tree flake for now, so people can evaluate and test it? This is what was done for gomod2nix (which didn't end up in nixpkgs in the end).
Also, notice there is another hook-based experiment in https://github.com/adisbladis/gobuild.nix. :)

fi
exclude+='\)'

buildGoDir() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, Bash doesn't support nested function declaration. Let's flatten the definition of these Bash functions.

@@ -0,0 +1,140 @@

goBuildHook() {
Copy link
Contributor

@ShamrockLee ShamrockLee Nov 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
goBuildHook() {
goBuildPhase() {

AFAICT, fooBarHook is meant to be run when doing runHook foo.

Also, I would propose also defining goBuild, which runs all the goBuildPhase commands except runHook preBuild and runHook postBuild. This way, goBuild could be inserted into the pre- and post-phases of other build helpers/workflows. For example, apptainer uses the stdenv.mkDerivation's Make-based workflow during configuration and build but still requires the Go modules realization from goConfigurePhase. If we have goConfigure, we could plug it into preConfigure and switch on dontGoConfigure and dontGoBuild.

@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Dec 31, 2024
@nixpkgs-ci nixpkgs-ci bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.status: merge conflict This PR has merge conflicts with the target branch 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 6.topic: golang Go is a high-level general purpose programming language that is statically typed and compiled. 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 11.by: package-maintainer This PR was created by a maintainer of all the package it changes.

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

5 participants