Repository navigation
Closed
Description
I just realized that we don't have a good way to stop setup hooks from being run multiple times. For instance, this is the output for gpgme on my computer:
-lintl -lintl -lintl -lintl -lintl -lintl -lintl -lintl -lintl -lintl -L/nix/store/zl3vsrqfwx4xvxagdrdqav73yl53cxps-libc++-5.0.1/lib -lintl -L/nix/store/15jap16aibnk81idwlf37g91mx8akaqv-gpgme-1.11.1-dev/lib -lintl -lintl -L/nix/store/8rcmp881wmbh18mzrkd9kmjxh2w8cn5z-libgpg-error-1.28/lib -lintl -L/nix/store/dkmxfrzsi0bzg4a4b976ww08243fslbs-glib-2.56.0-dev/lib -lintl -L/nix/store/byjz3zsj2397x4bllp4axqcnc517jdl7-zlib-1.2.11-dev/lib -lintl -L/nix/store/553hwxk54h8z87m4xgga4n8dznd6n8vp-zlib-1.2.11/lib -lintl -L/nix/store/si0g5b52xhrpdd8xjd67xdpskfgfscid-libffi-3.2.1-dev/lib -lintl -L/nix/store/qm51pj3fsvvb34kl7s9p4vvis92vq3ml-libffi-3.2.1/lib -lintl -L/nix/store/s8yvb556vw7l73qzx2wmhc2qmdw972dy-gettext-0.19.8/lib -lintl -L/nix/store/6xismd1mcjqnsj873wmx1fr0p62v13f2-libiconv-osx-10.11.6/lib -lintl -L/nix/store/7cb7305cliycr62pkcc8yzpjl50jncad-glib-2.56.0/lib -lintl -lintl -L/nix/store/yr6dzd26vd5crjfczv5w5kpw0g3la7qg-libassuan-2.5.1/lib -lintl -L/nix/store/8ipd3lbwabrxwbm1f7sxi8xj54sn0a44-pth-2.0.7/lib -lintl -L/nix/store/6ilwnfqar3k2vx9baazzagbfh25xgcfg-gpgme-1.11.1/lib -lintl -lintl -lintl -lintl -lintl -lintl -lintl -lintl -lintl -lintl -lintl -lintl -L/nix/store/zl3vsrqfwx4xvxagdrdqav73yl53cxps-libc++-5.0.1/lib -lintl -L/nix/store/15jap16aibnk81idwlf37g91mx8akaqv-gpgme-1.11.1-dev/lib -lintl -lintl -L/nix/store/8rcmp881wmbh18mzrkd9kmjxh2w8cn5z-libgpg-error-1.28/lib -lintl -L/nix/store/dkmxfrzsi0bzg4a4b976ww08243fslbs-glib-2.56.0-dev/lib -lintl -L/nix/store/byjz3zsj2397x4bllp4axqcnc517jdl7-zlib-1.2.11-dev/lib -lintl -L/nix/store/553hwxk54h8z87m4xgga4n8dznd6n8vp-zlib-1.2.11/lib -lintl -L/nix/store/si0g5b52xhrpdd8xjd67xdpskfgfscid-libffi-3.2.1-dev/lib -lintl -L/nix/store/qm51pj3fsvvb34kl7s9p4vvis92vq3ml-libffi-3.2.1/lib -lintl -L/nix/store/s8yvb556vw7l73qzx2wmhc2qmdw972dy-gettext-0.19.8/lib -lintl -L/nix/store/6xismd1mcjqnsj873wmx1fr0p62v13f2-libiconv-osx-10.11.6/lib -lintl -L/nix/store/7cb7305cliycr62pkcc8yzpjl50jncad-glib-2.56.0/lib -lintl -lintl -L/nix/store/yr6dzd26vd5crjfczv5w5kpw0g3la7qg-libassuan-2.5.1/lib -lintl -L/nix/store/8ipd3lbwabrxwbm1f7sxi8xj54sn0a44-pth-2.0.7/lib -lintl -L/nix/store/6ilwnfqar3k2vx9baazzagbfh25xgcfg-gpgme-1.11.1/lib -lintl -lintl -lintl -lintl -lintl -lintl -lintl -lintl -lintl -lintl -lintl -lintl -L/nix/store/zl3vsrqfwx4xvxagdrdqav73yl53cxps-libc++-5.0.1/lib -lintl -L/nix/store/15jap16aibnk81idwlf37g91mx8akaqv-gpgme-1.11.1-dev/lib -lintl -lintl -L/nix/store/8rcmp881wmbh18mzrkd9kmjxh2w8cn5z-libgpg-error-1.28/lib -lintl -L/nix/store/dkmxfrzsi0bzg4a4b976ww08243fslbs-glib-2.56.0-dev/lib -lintl -L/nix/store/byjz3zsj2397x4bllp4axqcnc517jdl7-zlib-1.2.11-dev/lib -lintl -L/nix/store/553hwxk54h8z87m4xgga4n8dznd6n8vp-zlib-1.2.11/lib -lintl -L/nix/store/si0g5b52xhrpdd8xjd67xdpskfgfscid-libffi-3.2.1-dev/lib -lintl -L/nix/store/qm51pj3fsvvb34kl7s9p4vvis92vq3ml-libffi-3.2.1/lib -lintl -L/nix/store/s8yvb556vw7l73qzx2wmhc2qmdw972dy-gettext-0.19.8/lib -lintl -L/nix/store/6xismd1mcjqnsj873wmx1fr0p62v13f2-libiconv-osx-10.11.6/lib -lintl -L/nix/store/7cb7305cliycr62pkcc8yzpjl50jncad-glib-2.56.0/lib -lintl -lintl -L/nix/store/yr6dzd26vd5crjfczv5w5kpw0g3la7qg-libassuan-2.5.1/lib -lintl -L/nix/store/8ipd3lbwabrxwbm1f7sxi8xj54sn0a44-pth-2.0.7/lib -lintl -L/nix/store/6ilwnfqar3k2vx9baazzagbfh25xgcfg-gpgme-1.11.1/lib -lintl -lintl -lintl -lintl -lintl -lintl -lintl -lintl -lintl -lintl -lintl -lintl -L/nix/store/zl3vsrqfwx4xvxagdrdqav73yl53cxps-libc++-5.0.1/lib -lintl -L/nix/store/15jap16aibnk81idwlf37g91mx8akaqv-gpgme-1.11.1-dev/lib -lintl -lintl -L/nix/store/8rcmp881wmbh18mzrkd9kmjxh2w8cn5z-libgpg-error-1.28/lib -lintl -L/nix/store/dkmxfrzsi0bzg4a4b976ww08243fslbs-glib-2.56.0-dev/lib -lintl -L/nix/store/byjz3zsj2397x4bllp4axqcnc517jdl7-zlib-1.2.11-dev/lib -lintl -L/nix/store/553hwxk54h8z87m4xgga4n8dznd6n8vp-zlib-1.2.11/lib -lintl -L/nix/store/si0g5b52xhrpdd8xjd67xdpskfgfscid-libffi-3.2.1-dev/lib -lintl -L/nix/store/qm51pj3fsvvb34kl7s9p4vvis92vq3ml-libffi-3.2.1/lib -lintl -L/nix/store/s8yvb556vw7l73qzx2wmhc2qmdw972dy-gettext-0.19.8/lib -lintl -L/nix/store/6xismd1mcjqnsj873wmx1fr0p62v13f2-libiconv-osx-10.11.6/lib -lintl -L/nix/store/7cb7305cliycr62pkcc8yzpjl50jncad-glib-2.56.0/lib -lintl -lintl -L/nix/store/yr6dzd26vd5crjfczv5w5kpw0g3la7qg-libassuan-2.5.1/lib -lintl -L/nix/store/8ipd3lbwabrxwbm1f7sxi8xj54sn0a44-pth-2.0.7/lib -lintl -L/nix/store/6ilwnfqar3k2vx9baazzagbfh25xgcfg-gpgme-1.11.1/lib -lintl -lintl
I don't understand why the setup hook is being run so many times, but it is definitely not good. Is there a way to ensure addEnvHooks is only run once? Otherwise we may need to add a flag like HAS_ADDED_LINTL.
Current packages adding ldflags:
- libiconv
- gettext (libintl)
- musl-fts
- netbsd.compat
/cc @Ericson2314 @dtzWill
Reacted by Wilfred Denton
Metadata
Metadata
Assignees
Labels
No labels
Activity
knedlsepp commentedon May 6, 2018
There's a paragraph in the docs that I personally read as: While hooks are convenient, they are difficult to do right. There are however no suggestions on how to achieve idempotency in hooks.
nixpkgs/doc/stdenv.xml
Lines 1965 to 1978 in eca5c99
matthewbauer commentedon May 7, 2018
So, the "theory" behind this is to normalize different C standard libraries. Glibc provides a ton of nonstandard symbols bundled into libc (libiconv & libintl stuff). Since most of our packages assume they are running Glibc/Linux, they will assume those symbols will be provided by libc & not pass the needed flags. Ideally, we could "strip" those out of Glibc, but this can get complicated & the long legacy of Glibc in free software means we will break lots of otherwise good software. So instead, we provide the
-lflag automatically when we know the libc will not provide it through the setup hook.I really want to figure out why there are so many NIX_LDFLAGS. My understanding is the setup hook should only be run once for each time it is listed as a dependency (also another for each package that propagates it). This is probably effecting anything that uses
addEnvHooks& appends to an export variable.Ericson2314 commentedon May 7, 2018
This is a consequence of the native back compat hack that I did in 469fd89 which runs setup hooks too many times to ensure improperly categorized dependencies still get processed. It would be nice to remove this altogether.469fd89 is indeed problematic, but I think the next post has the real culprit.
Ericson2314 commentedon May 7, 2018
@matthewbauer also some of the environment hooks should instead be setup hooks. I fix this in #40139.
Ericson2314 commentedon May 7, 2018
@knedlsepp indeed there is no way easy way to be idempotent. So I hope my PR is sufficient.
[BTW https://nixos.org/nixos/nix-pills/basic-dependencies-and-hooks.html which I wrote goes into the hooks more slowly than the manual. I'm curious whether it is more readable.]
Ericson2314 commentedon May 7, 2018
#40139 should be fixed on staging.
knedlsepp commentedon May 7, 2018
Interesting read. I once read through the nix-pills before they were hosted on nixos.org. Didn't know they were still being updated.
One question about the setup hooks:
As far as I understood we get some dependencies multiple times, because of the way the dependency-graph is traversed. What is the reason we cannot simply:
sort | uniqthe inputsnix-support/setup-hookfiles in that order?Ericson2314 commentedon May 7, 2018
setup hooks are 1 once per "role"; calls with the same role are indeed deduplicated already. This is because using using, e.g. the C compiler, as a
nativeBuildInputvsdepsBuildBuildis a fundamentally different thing; the setup hook is called with a different dynamic scope. Reverting 469fd89 will make this OK.