What is the right way to debug linking in NixOS


So I’m failing to build hello world nannou sketch on NixOS and don’t understand how to debug it.

With xorg.libxcb (prerequisite for nannou) installed globally build fails with /nix/store/lbxfixyw1yk099pjyaiy3xj5dl7kxm1g-binutils-2.35.2/bin/ld: cannot find -lxcb. As far as I understand -lxcb should be -l/nix/store/9war3957gri3m3714ghs2jj96i642vvs-system-path/lib/libxcb.so or something. How do I find the exact path and how do I pass it to cargo? What needs to be done so global installation works out of the box?

With libxcb installed from shell.nix build succeeds but runtime panics with libX11.so.6: cannot open shared object file: No such file or directory. Installing xorg.libX11 and/or vulkan-tools does not solve it. It seems libxcb (or something else) cannot resolve libX11 which is /nix/store/w259jz35i221vil0jg2dpdw3zda55ai4-libX11-1.7.2/lib/libX11.so.6. How do I tackle that? I’ve tried ldd target/debug/main but no traces of libX11.so.6. How is that possible assuming this answer is correct?

From my questions you may deduce that I have very little experience with linking and dynamic libraries debugging. Reading recommendations are much appreciated.

The same example works trivially on Arch but I’d like to learn how to fix this kind of issues on Nix.

Sorry for a long rant.

There is no way to make global library installation work

Make sure to have the library in your derivations buildInputs or alternatively in your mkShells packages.

Thanks but no avail with buildInputs, sadly. strace output is quite instructive but still no clue what’s going on.

Eventually I’ll figure it out.

Coincidentally I was also struggling with setting up a build environment
for Nannou. That’s why I published it here: GitHub - nix-community/nix-environments: Repository to maintain out-of-tree shell.nix files (maintainer=@mic92)

If you use Nix with flakes, you can just run

nix develop --no-write-lock-file github:nix-community/nix-environments#

to drop into the shell. Or you look at the sources, maybe that helps?

Runs successfully with your shell.nix! Many thanks!

Now a few minutes to narrow down the culprit…

Okay, so LD_LIBRARY_PATH line makes the difference. cmake and pkg-config are optional.

LD_LIBRARY_PATH is almost never the right solution with Nix/NixOS. You really want your binaries built with the right paths baked in.

1 Like