Can't reference a library in a nix-shell shellHook

Greetings

I’m trying to use the cudaPackages.libnvjitlink library in a shellhook to no avail.

Specifically, I include the package in my ‘shell.nix’ file and try to reference it as follows:

...

nativeBuildInputs = [
    cudaPackages.cudatoolkit
    cudaPackages.libnvjitlink
 ...

];

shellHook = ''
  echo "Entering CUDA-enabled nix-shell."
  export CUDA_PATH=${pkgs.cudatoolkit}
  export LD_LIBRARY_PATH=${pkgs.linuxPackages.nvidiaPackages.stable}/lib:${pkgs.ncurses}/lib:${cudaPackages.cudatoolkit}/lib:${cudaPackages.libnvjitlink}/lib
  export EXTRA_LDFLAGS="-L/lib -L${pkgs.linuxPackages.nvidiaPackages.stable}/lib"
  export EXTRA_CCFLAGS="-I/usr/include"
'';

...

But I can not access libnvJitLink.so.13 which is provided by the package. When I manually look at the installed ‘cudaPackages.libnvjitlink’ directory in /nix/store, the only meaingful contents it shows are a nix-support/propogated-build-inputs.

So the real question becomes how do I reference this correctly from my shell.nix file?

Thank you

The cuda packages use split outputs. The library contents will only be available in the .dev output.

The buildInputs attribute will automatically include the .dev output if one exists, but if you manually walk through /nix/store you probably aren’t looking at the right directory.


Besides, your environment variable manipulation can only cause issues. mkShell does this for you, but correctly.

You should delete the entire shellHook, and instead add the libraries you want to link against to the packages of your mkShell. E.g.:

{
  pkgs ? import <nixpkgs> { },
  ...
}: pkgs.mkShell {
  packages = [
    pkgs.ncurses

    pkgs.linuxPackages.nvidiaPackages.stable
    pkgs.cudaPackages.cudatoolkit
    pkgs.cudaPackages.libnvjitlink
  ];
}

packages is a less confusing alias of nativeBuildInputs, which should in general be used instead of buildInputs and nativeBuildInputs for mkShell.

You can inspect the result with env; you’ll see that the library paths end up in variables without you specifying them by hand (though I forget which variables off the top of my head).

You can also inspect the contents of the directories in those variables, instead of trying to find the packages manually, they will contain the correct paths.

This is probably wrong, but...

This might be the one edge case where you want to use buildInputs. I’m not certain that nativeBuildInputs uses the dev output off the top of my head. The above might still not work, if so, try this:

{
  pkgs ? import <nixpkgs> { },
  ...
}: pkgs.mkShell {
  packages = [
    pkgs.ncurses
  ];

  # WARNING: probably wrong; I just don't recall
  # if the `.dev` output is used by `packages`.
  buildInputs = [
    pkgs.linuxPackages.nvidiaPackages.stable
    pkgs.cudaPackages.cudatoolkit
    pkgs.cudaPackages.libnvjitlink
  ];
}

… but more realistically it probably just means your code isn’t linking correctly. Share more of your shell and build system if you can’t get it to work.

1 Like