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

buildGoModule: form GOFLAGS from goFlags #359744

Open
wants to merge 2 commits into
base: staging
Choose a base branch
from

Conversation

ShamrockLee
Copy link
Contributor

@ShamrockLee ShamrockLee commented Nov 28, 2024

This PR introduces a new argument, goFlags, to form GOFLAGS at build time at the beginning of buildPhase and checkPhase.

This PR also adds a helper Bash function to setup.sh named removeAllPrefixedFromVar, which removes all the elements with given prefixes from the Bash array/IFS-separated string variable of the given name.

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/)
  • 25.05 Release Notes (or backporting 24.11 and 25.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.

@github-actions github-actions bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: documentation This PR adds or changes documentation 8.has: changelog 6.topic: golang labels Nov 28, 2024
@ShamrockLee ShamrockLee force-pushed the build-go-module-goflags branch 4 times, most recently from 088f5dd to 182f790 Compare November 28, 2024 08:21
@TomaSajt TomaSajt self-requested a review November 28, 2024 08:31
(lib.optional (!allowGoReference) "-trimpath");
env = args.env or { } // {

GOFLAGS = lib.concatStringsSep " " finalAttrs.goFlags;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if we should do this from nix.

Can't we perhaps have goFlags be used as a bash array and set GOFLAGS later in bash?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am thinking about it. Operating on goFlags and forming GOFLAGS as needed makes the interface more consistent.

Still, as GOFLAGS acts as the "default flags for all Go commands if applicable," people are likely to expect GOFLAGS to be defined before the first execution of the go command. Defining and exporting GOFLAGS in one of the prePhases seems to defeat the purpose of making goFlags modifiable after evaluation.

Copy link
Contributor Author

@ShamrockLee ShamrockLee Dec 1, 2024

Choose a reason for hiding this comment

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

After examining the implementation again, it turns out the GOFLAGS is only used during the buildPhase and checkPhase provided by buildGoModule, and the configurePhase is still adjusting the flags.

Let's form the GOFLAGS at the beginning of the buildPhase then.

@TomaSajt
Copy link
Contributor

By the way, is the rationale behind having goFlags the fact that lists are more ergonomic to use with overrideAttrs?

@ShamrockLee
Copy link
Contributor Author

By the way, is the rationale behind having goFlags the fact that lists are more ergonomic to use with overrideAttrs?

It's because a list is more structured than a string, and I hope to keep having a way to specify GOFLAGS with a list. As you said, the main benefit would be a smoother overrideAttrs experience.

@ShamrockLee ShamrockLee force-pushed the build-go-module-goflags branch from 182f790 to 00f676d Compare December 1, 2024 17:44
@github-actions github-actions bot added 6.topic: python 6.topic: GNOME GNOME desktop environment and its underlying platform 8.has: module (update) This PR changes an existing module in `nixos/` 6.topic: policy discussion 6.topic: vim 6.topic: stdenv Standard environment 6.topic: cinnamon Desktop environment 6.topic: php 8.has: maintainer-list (update) This PR changes `maintainers/maintainer-list.nix` 6.topic: continuous integration Affects continuous integration (CI) in Nixpkgs, including Ofborg and GitHub Actions labels Dec 1, 2024
@ShamrockLee ShamrockLee changed the title buildGoModule: pass GOFLAGS with env and construct from goFlags buildGoModule: form GOFLAGS from goFlags Dec 1, 2024
@ShamrockLee
Copy link
Contributor Author

I reimplemented this PR and made buildGoModule form GOFLAGS at build time at the beginning of buildPhase and checkPhase.

@@ -209,6 +221,8 @@ in
''
runHook preBuild

export GOFLAGS="''${goFlags[*]}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if we'd want to do it, but we could have goFlags be appended to GOFLAGS in case it's already set, for some reason.

I'm trying to look at this from a standpoint where the build script eventually becomes a hook, which wouldn't be able to cleanly enforce using goFlags over GOFLAGS.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm trying to look at this from a standpoint where the build script eventually becomes a hook, which wouldn't be able to cleanly enforce using goFlags over GOFLAGS.

If the "hook" hear means a "setup hook", it can as long as it provides the buildPhase and the checkPhase.

@@ -385,6 +385,25 @@ appendToVar() {
fi
}

removeAllPrefixedFromVar() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, this is something that would be useful globally, but should probably stay in module.nix until the testing is done.

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/breaking-changes-announcement-for-unstable/17574/74

@ShamrockLee ShamrockLee marked this pull request as ready for review December 19, 2024 00:30
@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Dec 31, 2024
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 6.topic: golang 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 6.topic: stdenv Standard environment 8.has: changelog 8.has: documentation This PR adds or changes documentation 10.rebuild-darwin: 501+ 10.rebuild-darwin: 5001+ 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild 10.rebuild-linux: 501+ 10.rebuild-linux: 5001+ 10.rebuild-linux-stdenv This PR causes stdenv to rebuild
Projects
Status: In progress
Development

Successfully merging this pull request may close these issues.

5 participants