Take clang-tools over executables in llvmPackages.stdenv

I have a flake with a devShell that uses clang 17:

devShells = forAllSystems (system:
  let
    pkgs = nixpkgsFor.${system};
    frameworks = pkgs.darwin.apple_sdk_11_0.frameworks;
    mkShell = pkgs.mkShell.override {stdenv = pkgs.llvmPackages_17.stdenv;};
  in {
    default = mkShell {
      buildInputs = with pkgs; [
        cmake
        ninja
        llvmPackages_17.bintools-unwrapped
        clang-tools_17
        lldb_17
      ] ++ lib.optionals stdenv.isDarwin [ darwin.DarwinTools frameworks.ApplicationServices ];
    };
  });

So here’s the problem: there are executable provided by clang that are the same as in clang-tools. For example:

$ type clangd
clangd is /nix/store/yq6k6rbc50ylcbixkxbzjh9i9a9zplyh-clang-17.0.6/bin/clangd

This is bad news for me, since this clangd executable cannot find standard headers.

The same goes on with clang-tidy.

I want to use the executable provided by clang-tools_17, is there a way to tell nix to prioritize that package over the ones from the stdenv? Thanks.

See Unable to access clang tools in clangStdenv · Issue #214945 · NixOS/nixpkgs · GitHub.

I suppose the solution is probably to prevent binaries that are/need (?) to be exposed via clang-tools to show up in clang-unwrapped’s output.

Until then you can probably have a hack that modifies PATH in shellHook although it’s pretty ugly.

Actually, adding clang-tools_17 to my nativeBuildInputs in my flake file resolved the issue. I see clangd and clang-scan-deps and others command to be from clang-tools_17 instead of clang.