Per the NixOS Wiki article on clang, it seems like this should work:
# in file ./shell.nix
with import <nixpkgs> {};
clangStdenv.mkDerivation {
name = "clang-nix-shell";
nativeBuildInputs = [ clang-tools /* add libraries here */ ];
}
It might seem weird to put a derivation instead of a call to mkShell in the shell.nix, but from my understanding, nix-shell was originally developed as a way to test derivation builders and so drops you into a interactive shell that just sets up the dependencies of a derivation (nix-instantiate/nix-build would build the actual derivation)
From Discourse - how to make mkShell use clang’s stdenv, it seems like the way to do it with mkShell involves overriding the stdenv.
let
pkgs = (import <nixpkgs> { });
in
pkgs.mkShell.override { stdenv = pkgs.clangStdenv; } {
nativeBuildInputs = [ clang-tools ];
}
Do either of these shell.nix fix your problem?
EDIT: see query driver answer byKeatonClark above, which should be a workable fix. There is weirdness in how clangd is wrapped that should probably be addressed upstream but will need someone with the knowledge and time to fix it in a more properly engineered fashion. See a PR that wraps clangd, but only in pkgs.clang-tools and an abandoned PR to implement similar in pkgs.clang for more information
EDIT2: added clang-tools to the shell.nix above, which then should put the clangd from the package earlier in the path. It’s a bit of an ugly hack for now.