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: pass GOFLAGS with env and construct from goFlags #359744

Draft
wants to merge 3 commits into
base: staging
Choose a base branch
from

Conversation

ShamrockLee
Copy link
Contributor

Pass GOFLAGS as env.GOFLAGS to support __structuredAttrs = true.

Introduce a new argument, goFlags, to form GOFLAGS at evaluation time. (Environment variables passed via env cannot be a list.)

This PR depends on #359641. Once the dependent PR is merged, I'll rebase this feature branch and drop the [placeholder] commit.

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.

@ShamrockLee ShamrockLee force-pushed the build-go-module-goflags branch 2 times, most recently from 1cced9b to 088f5dd Compare November 28, 2024 08:12
(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.

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In progress
Development

Successfully merging this pull request may close these issues.

2 participants