Repository navigation
Description
Current situation
- Many Go packages in nixpkgs set
ldflags = [ "-s" "-w" ]; - nix-init sets
ldflags = [ "-s" "-w" ];for Go packages - stdenv has it's own stripping mechanism, which is turned on by default and can be disabled with
dontStrip = true; - For debugging, people want to override individual packages with
dontStrip = true;and get the expected debug symbols, which isn't currently working for many packages that set-s -won a package level (see Golang: add support for thegcflagsattribute #277609) - At the same time, the stripping done by stdenv isn't removing all symbols, so binaries aren't as small as they could be (see
buildGoModule: Binaries are not stripped by default. Proposal to add-s -wldflags by default #177698 and table below) - There have been repeated discussions in PR review about whether these flags should be added or not
History
buildGoModule: Binaries are not stripped by default. Proposal to add-s -wldflags by default #177698 long running issue on adding -s -w by default- DRAFT: buildGo{Module,Package}: add defaultLdflags
-s -w#182743 previous draft implementation, stating we should fix the stdenv stripping instead
About -w
From the Go v1.22 release notes:
The -w flag suppresses DWARF debug information generation. The -s flag suppresses symbol table generation. The -s flag also implies the -w flag
Setting -w in combination with -s has no effect.
Suggested action items:
- Update nix-init to not set
-wflag - Remove all occurrences of
-win nixpkgs
About -s
Go's native stripping works far better than the stripping done by stdenv (see table below for comparison), binaries are smaller and recognized by file as stripped.
In my opinion, we should use Go's native stripping mechanism by default in buildGoModule. This would mean that we:
- Add
-sto theldflagsinside of buildGoModule - Don't add
-sto theldflagsin casedontStripis set - Throw a warning in case
-sis set in ldflags
We can discuss whether we want to always set dontStrip on the underlying derivation (maybe to fasten up build time) or if we keep it active to prevent confusion and for mixed language derivations (I'd opt for keeping it for now).
Suggested action items:
- Update nix-init to not set
-sflag - Update
buildGoModuleto strip with-sflag by default, to drop-swhendontStrip = true, throw warning if flag is parsed from outside - Remove all occurrences of
-sin nixpkgs
Example: stripping statistics for uplosi on x86_64-linux
| CGO_ENABLED | dontStrip | ldflags | size | file |
|---|---|---|---|---|
| 1 | false | 73871744 (71MiB) | dynamically linked, not stripped, | |
| 1 | true | 89904674 (86MiB) | dynamically linked, with debug_info, not stripped, | |
| 1 | false | -w | 73871744 (71MiB) | dynamically linked, not stripped, |
| 1 | true | -w | 73880107 (71MiB) | dynamically linked, not stripped, |
| 1 | false | -s | 64374008 (62MiB) | dynamically linked, stripped, |
| 1 | true | -s | 64372979 (62MiB) | dynamically linked, stripped, |
| 1 | false | -s -w | 64374008 (62MiB) | dynamically linked, stripped, |
| 1 | true | -s -w | 64372979 (62MiB) | dynamically linked, stripped, |
| 0 | false | 73753128 (71MiB) | statically linked, not stripped, | |
| 0 | true | 89767921 (86MiB) | statically linked, with debug_info, not stripped, | |
| 0 | false | -w | 73753128 (71MiB) | statically linked, not stripped, |
| 0 | true | -w | 73762114 (71MiB) | statically linked, not stripped, |
| 0 | false | -s | 64269808 (62MiB) | statically linked, stripped, |
| 0 | true | -s | 64270471 (62MiB) | statically linked, stripped, |
| 0 | false | -s -w | 64269808 (62MiB) | statically linked, stripped, |
| 0 | true | -s -w | 64270471 (62MiB) | statically linked, stripped, |
Created with katexochen@169e31b, which can be used to check results for other packages.
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsBacklog
Activity
zowoq commentedon Oct 5, 2024
I looked at this a while ago: #177698
Agree.
Agree with keeping it for now.
katexochen commentedon Oct 5, 2024
katexochen commentedon Oct 6, 2024
I've updated the issue description with the additional pointers to the previous work. For me, there are two points from the previous discussion we should note:
-s=0to the ldflags. We must ensure to add the default ldflags first.issue2md: add `ldflags`
eclairevoyant commentedon May 3, 2026
Did
-send up getting handled? I didn't see any code for it, maybe I missed it though.katexochen commentedon May 5, 2026
No, nothing of this has been implemented.
nixos-discourse commentedon Jun 8, 2026
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/why-do-so-many-go-packages-use-s-w-in-their-ldflags-it-breaks-dontfixup-dontstrip/36843/9
scion-apps: unstable-2025-03-12 -> 0.6.0-unstable-2026-06-04