Handling transitive C dependencies

I’m trying to setup an environment for building glfw projects. This is the nix expression I’ve written:

{pkgs ? import <nixpkgs> {}}:

pkgs.mkShell rec {

  buildInputs = with pkgs; [

This is the error I get when using pkg-config:

[$] pkg-config --static --libs glfw3                                  
Package x11 was not found in the pkg-config search path.
Perhaps you should add the directory containing `x11.pc'
to the PKG_CONFIG_PATH environment variable
Package 'x11', required by 'glfw3', not found

If I add xorg.libX11 to the expression I get another error saying pthread-stubs not found.

What is the correct way of handling transitive dependencies in nix shells?

As I understand the wiki you need to use nativeBuildInputs.l for pkg-config

We add the dependencies listed in the Requires section of the .pc file into propagatedBuildInputs of the package but sometimes this is forgotten.

We do not do this for Requires.private which are only required for static linking since it is superfluous in normal operation. I am not sure if there is other way than collecting the dependencies manually or using something like let deps = pkg: (pkg.buildInputs or []) ++ (pkg.propagatedBuildInputs or []); collect = pkg: lib.unique (deps pkg ++ lib.concatMap collect (deps pkg)); in collect xorg.libX11.

1 Like

It’s better, but it won’t make a practical difference unless cross-compiling (which doesn’t seem to be this case).