Why do so many Go packages use "-s" "-w" in their `ldflags`? It breaks `dontFixup`/`dontStrip`


I see:

~/src/nix/nixpkgs% rg -c '"-s" "-w"' | wc -l
~/src/nix/nixpkgs% rg buildGoModule | wc -l

Does anyone know if there is some reason for that?

Because for the go linker -s and -w respectively are for:

  • Omit the symbol table and debug information.
  • Omit the DWARF symbol table.

And my understanding is that fixupPhase is supposed to do that during builds.

This means that dontFixup and dontStrip do not work as expected, which is a poor user experience.

If there is no reasons, I would suggest the idea that we update affected packages and add some check/warning to prevent those linker flags from being passed in. edit: And that we remove those flags from the docs too.

This change would also be necessary:


Ping @kalbasit for the Golang team, I would love some guidance here!

Thank you

During the package build but after the go build command.

I think this is a general problem in any build system, as we don’t enforce that packages can’t do stripping on their own, so the problem is not just limited to golang.

A warning as in checking via nix code or via shellcode? Via nix code we would first need to remove them from all packages, otherwise ofborg will trip over them. Via shellcode is probably a bit pointless since no one looks at logs if things build fine.

I did a quick comparison on a random go program and seemingly the difference between go strip and our strip is very very tiny

ldflags -s -w: 17170432
strip: 17172216

cc @qbit @Mic92 not sure how to ping zowoq

Independent of this, I think both commits as of writing in Comparing NixOS:nixos-23.11...lopter:nixos-23.11-lo-patches · NixOS/nixpkgs · GitHub are upstreamable and I think you should create PRs for them.

My guess is that those might be cargo-culted from upstream linker flakes i.e. some projects have Makefiles with those.

Thank you all for the follow-up,

Right, I am just interested in Golang at the moment, this is more of an exercise for myself then anything else.

As a warning in nix code: i.e in there check if args.ldflags have "-s" or "-w" and, if it does, say that stripping is controlled by the fixup phase. Same for …/go/package.nix.

I think that’s fine if we have to remove them first, it will have to be automated anyway, rollout sounds like:

  1. Write Nix code to walk through the package set to get affected packages;
  2. Figure out some sed or awk incantations to fix affected nix files;
  3. Submit those changes;
  4. Add warning;
  5. Repeat the first two steps for stuff that got in while step 3 was in progress.


Sweet, I didn’t even realize that could yield a different result.

Hello Jörg, as we cross paths, I wanna take the opportunity to thank you for your work: your dotfiles have been super instrumental to my Nix onboarding, as well as sops-nix. What’s being cooked at clan.lol looks pretty interesting too.

Cargo-culting has also been my guess, which is why I want to remove those flags from the docs, and I just opened this PR.

1 Like

I think people usually use ripgrep to find the occurrences and some other tool to replace them. If ldflags is empty afterwards, we can delete it.

Sure, sounds like a plan to me.