How to correctly populate a clang and llvm development environment using nix-shell?

Thanks to the discussion in OpenSSL dependency for Rust - #4 by danieldk I learned you can add pkgconfig to a shell.nix that needs to use openssl. (I also updated the wiki).

I then thought to try the same trick for a shell.nix used to compile a Rust project, olm-rs, that needs clang and llvm. I started with the following shell.nix:

# copied expressions from
# and Mozilla's nix overlay README
  moz_overlay = import (builtins.fetchTarball;
  pkgs = import <nixpkgs> { overlays = [ moz_overlay ]; };
  with pkgs;
  stdenv.mkDerivation {
    name = "clang-env-with-nightly-rust";
    buildInputs = [
    # why do we need to set the library path manually?
    shellHook = ''
      export LIBCLANG_PATH="${pkgs.llvmPackages.libclang}/lib";

You’ll notice the ugly shellHook where I manually export the LIBCLANG_PATH.
When I remove the shellHook entirely and add pkgconfig to buildInputs, LIBCLANG_PATH is still not populated.

Am I specifying the wrong llvm and clang build inputs?
Or should I be doing something like what scala-native does?

1 Like

Yeah, clang does not provide pkgconfig files.

There are some other places it looks at:

You end up needing to set LIBCLANG_PATH no matter what here. It also looks for llvm-config, but we don’t put libclang there. So LIBCLANG_PATH is pretty much required. We could make this easier with a setup hook though.

PR here:

1 Like

Wow, thanks for the quick answer and solution @matthewbauer!
Confirms that I wasn’t crazy trying to write the shell.nix that way.