Load libaries by absolute path on NixOS#15196
Conversation
If "nixbuild" is defined then choose dynamic runtime libraries by searching $NIX_LDFLAGS at compile-time. Fix #15194
|
Is there a way to implement this that doesn't require another build flag? Does NixOS require all programs to add in special support for manual shared library loading? |
|
The compiler/stdlib could always check the contents of NIX_LDFLAGS, or not at all and we patch the compiler when building for Nix. I think the build flag is should be a non-issue because for Nix we can just set it permanently in nim.cfg during installation and no one needs to know it exists. Normally stuff just works on NixOS, but if something is using |
|
Why is NixOS being a special case here? Why does it need this different mechanism, it's a Linux distro after all. |
Because it doesn't follow FHS and each package/lib resides in it's own folder in /nix/store/ |
| # During Nix/NixOS packaging the line "define:nixbuild" | ||
| # should be appended to the ../../config/nim.cfg file | ||
| # to enable this behavior by default. |
There was a problem hiding this comment.
Or you can just use --dynlibOverrideAll then --passL to link as you'd like.
|
I think for Nix you can just use a custom Alternatively, you can use |
|
The problem is described in #15194. Yes, manually passing the correct flags makes the correct thing happen, each package built from Nim sources in Nixpkgs passes special flags to fix this problem, and its the least preferable solution. |
|
@ehmry you can edit global nim.cfg to add these flags for the compiler and all programs (config/nim.cfg) |
|
Maybe we could create a hook in Nixpkgs that would consider
For more background, search also for |
Can you elaborate? |
alaviss
left a comment
There was a problem hiding this comment.
I fail to see the benefit of this change over just changing all -L into -Wl,-rpath. In fact, the latter will even be more flexible as users can add into the search path with LD_LIBRARY_PATH as needed.
Can you point us to the documentation for |
Here you go: https://nim-lang.org/docs/nims.html
For packaging in a distribution I'd recommend |
|
So we could modify |
|
It would be much better to modify a |
it may be worth creating a Edit: There seems to be an |
Note that this new Personally I would not recommend For adding flags into builds you can use |
Good, that was what I was worried about initially! In what format are the flags supposed to be passed in? Comma or space separated? I would expect the latter, however $ tail -n1 config/nim.cfg
--passL="$NIX_LDFLAGS"One should not use $ echo $NIX_LDFLAGS
-rpath /nix/store/hn1y9dinsrcxfbgjiymv3fhzd10k9m12-nim-1.2.6/lib64 -rpath /nix/store/hn1y9dinsrcxfbgjiymv3fhzd10k9m12-nim-1.2.6/lib -L/nix/store/a0jxdf0wc13l4270fgq9n1f42x45pq69-openssl-1.1.1g/lib -L/nix/store/5gdc4wn4nx74dx5mv2k3gqx8hh4q72mg-pcre-8.44/lib -L/nix/store/s2kyldk2s42n5z2ijjj1v5ns78n9wzr3-ncurses-6.2/lib -L/nix/store/v7b326xn4wq9n4wqjdxar3xadz73mi8f-readline-6.3p08/lib -L/nix/store/19a50vv9bv66rsw91anv8r6avnzrbwxy-boehm-gc-8.0.4/lib -L/nix/store/iwmz9cl5x7xyzdfm3phxn7y4krz27m5j-sfml-2.5.1/lib -L/nix/store/f7lws879jarjs40qznw95pwz4ngc7ib0-sqlite-3.32.3/lib -L/nix/store/a0jxdf0wc13l4270fgq9n1f42x45pq69-openssl-1.1.1g/lib -L/nix/store/5gdc4wn4nx74dx5mv2k3gqx8hh4q72mg-pcre-8.44/lib -L/nix/store/s2kyldk2s42n5z2ijjj1v5ns78n9wzr3-ncurses-6.2/lib -L/nix/store/v7b326xn4wq9n4wqjdxar3xadz73mi8f-readline-6.3p08/lib -L/nix/store/19a50vv9bv66rsw91anv8r6avnzrbwxy-boehm-gc-8.0.4/lib -L/nix/store/iwmz9cl5x7xyzdfm3phxn7y4krz27m5j-sfml-2.5.1/lib -L/nix/store/f7lws879jarjs40qznw95pwz4ngc7ib0-sqlite-3.32.3/lib |
The same format as what the gcc driver accepts (since we pass the flags directly to gcc during link): |
|
Long term we want to get rid of rpath for Nix and I don't see any reason to look up something at runtime when we can know it with certainty at compile-time. I'd rather just patch the compiler downstream than deal with this configuration stuff. |
But you are still doing lookups at runtime? All this change does is to generate library candidates for the compiler with the paths prefixed. Unless I'm reading this wrong, this means you are basically doing Also note that I'm still not convinced that this solution is better than rpath. |
|
Ah, shame on me, I am reading this wrong. I didn't notice the existence check. This does seem to be something you'd want to do in the compiler though. The |
|
@ehmry FYI there is https://nim-lang.github.io/Nim/packaging.html - can you please keep it up to date with any relevant information? Thanks |
|
This is something that should be patched downstream. |
If "nixbuild" is defined then choose dynamic runtime libraries by
searching $NIX_LDFLAGS at compile-time.
Fix #15194