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

pkgsStatic.go #77591

Open
tomberek opened this issue Jan 13, 2020 · 4 comments
Open

pkgsStatic.go #77591

tomberek opened this issue Jan 13, 2020 · 4 comments

Comments

@tomberek
Copy link
Contributor

Issue description

pkgsStatic has flags for C/C++ projects to attempt a static build. Go can do this but usually needs to either

  • CGO_ENABLED=0 : easiest if possible
  • CGO_ENABLED=0 go build -a -tags netgo -ldflags '-w -extldflags "-static"' : if otherwise needed
  • something else with musl?

Steps

Easiest is to place CGO_ENABLED=0 into:
https://github.com/NixOS/nixpkgs/blob/master/pkgs/stdenv/adapters.nix#L46

Another approach is for derivations (or probably buildGoPackage/buildGoModule) to detect that they are in pkgsStatic and set the proper flags/vars.

Technical details

Pros:

  • Having an automatic way to get static builds for go projects would be a nice feature, capturing some expert knowledge usable in a wide variety of packages.
  • Central definition and update of flags
  • musl support to produce static builds of otherwise difficult CGO projects

Cons:

  • Increasing complexity in pkgsStatic environment.
  • stdenv either has more language-specific details or must signal to the buildGoPackage system that a static build is needed.
@FRidh FRidh changed the title Go in pkgsStatic pkgsStatic.go Mar 29, 2020
@stale
Copy link

stale bot commented Sep 25, 2020

Hello, I'm a bot and I thank you in the name of the community for opening this issue.

To help our human contributors focus on the most-relevant reports, I check up on old issues to see if they're still relevant. This issue has had no activity for 180 days, and so I marked it as stale, but you can rest assured it will never be closed by a non-human.

The community would appreciate your effort in checking if the issue is still valid. If it isn't, please close it.

If the issue persists, and you'd like to remove the stale label, you simply need to leave a comment. Your comment can be as simple as "still important to me". If you'd like it to get more attention, you can ask for help by searching for maintainers and people that previously touched related code and @ mention them in a comment. You can use Git blame or GitHub's web interface on the relevant files to find them.

Lastly, you can always ask for help at our Discourse Forum or at #nixos' IRC channel.

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Sep 25, 2020
@andrew-d
Copy link
Contributor

This is still important to me

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Sep 25, 2020
@stale
Copy link

stale bot commented Mar 26, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Mar 26, 2021
@cdepillabout cdepillabout removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Aug 1, 2022
@azahi
Copy link
Member

azahi commented Sep 7, 2022

There's a proposal for Go to include a simple -static build flag to statically compile an executable.

This proposal also has a comment suggesting that currently flags and tags to build a completely statically linked executables differ depending on the OS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants