Fails to find libxcb on nixOS
notgull opened this issue · 5 comments
This patch breaks any executables using this crate on NixOS, since the tiny-xlib library is unable to find libX11 library, even if it's installed by including it in
buildInputs
.In my
nix-shell
environment, I was able to get around this by setting theLD_LIBRARY_PATH
variable like so:with pkgs; LD_LIBRARY_PATH = lib.makeLibraryPath [ xorg.libX11 ]This allows me to resume development on my own crate, but I don't know how I will be able to distribute it in any usable form now.
Originally raised here. I don't know enough about nixOS to know how I should be linking to libX11 here.
Looks like the only way to really figure out where Xlib is is to use pkg-config
. I didn't want to have to use it, as it complicates the build phase. Maybe we could just put it behind an optional feature?
Looks like the only way to really figure out where Xlib is is to use
pkg-config
. I didn't want to have to use it, as it complicates the build phase. Maybe we could just put it behind an optional feature?
Is the location in pkg-config guaranteed to be stable?
I'm not sure, and every article I can find on the topic basically admits that libX11 could be anywhere on the system. It's what x11-dl uses, so it might be the only real way of finding libX11.
This isn't really an issue with the crate. If an executable dynamically loads a library at runtime rather than dynamically linking to it at build time, then it will not be in the DT_NEEDED
fields of the (ELF) executable, so (glossing over a lot of detail here) the executable produced on a NixOS system will not be able to find this library. The way to fix this would be to add something like the following to your derivation that uses tiny-xlib
.
postFixup = ''
patchelf --add-rpath ${xorg.libX11}/lib $out/bin/my-exe
'';
An example of this in nixpkgs is the vulkan-helper program.
Or, if this crate is used in dynamically linked mode rather than dlopen
mode, everything will likely Just Work as with any other foreign library in nixpkgs (e.g. buildInputs = [ xorg.libX11 ]
). pkg-config
is more idiomatic, but not required.