You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Listing clang before or after clang-tools in buildInputs results in a different clangd version. #76486
0.kind: bugSomething is broken2.status: stalehttps://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md6.topic: llvm/clangIssues related to llvmPackages, clangStdenv and related
Expected behavior
I could be misusing the clang-tools package, but I wouldn't expect the order of buildInputs to determine which version of a tool gets installed.
Additional context
Even though there is a 'bad substitution' error in the second case with 8.0.1 (clang listed after clang-tools), this is the order that "works" for me. If clang is listed before clang-tools resulting in clangd 7.0.1, clangd is unable to find stdio.h when using it with vim-lsp. If clang is listed after clang-tools, then clangd 8.0.1 can find stdio.h.
So the latest clang-tools/wrapper does fix the version mismatch (now it is clangd 7.1.0 in both cases), but whether or not clangd can find stdio.h still seems to depend on the order. Here are the logs using vim-lsp:
@NilsIrlclang-tools creates a wrapper for clangd that defines the environment variables CPATH and CPLUS_INCLUDE_PATH. So, both clang and clang-tools provide different clangd. It seems that clangd in LSP is only able to find stdio.h with the clang-tools version of clangd. That's why the order matters.
Looking at the definitions of clang and clang-tools in pkgs/top-level/all-packages.nix I also noticed that they are using different LLVM versions by default. clang is defined using llvmPackages and clang-tools using llvmPackages_latest. See 8dddd6d (couldn't find a related PR). I'm not sure if that could cause further problems. CC @orivej who authored that commit.
This has been automatically marked as stale because it has had no activity for 180 days.
If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.
Here are suggestions that might help resolve this more quickly:
Search for maintainers and people that previously touched the related code and @ mention them in a comment.
I just fought with clangd not being able to find system headers for some time, I'm happy to find that adding clang-tools before clang in buildInputs indeed fixes that!
Out of curiosity, why does the clang package outputs binaries for clangd and other tools if they aren't wrapped? Or why doesn't it define wrappers like it does for the compiler itself?
I've stumbled into a variation of this problem where I have a shell made with, mkShell.override { stdenv = pkgs.clang11Stdenv; }. I'm not sure what the best way to list clang-tools before clang is in such a case.
I've stumbled into a variation of this problem where I have a shell made with, mkShell.override { stdenv = pkgs.clang11Stdenv; }. I'm not sure what the best way to list clang-tools before clang is in such a case.
I initially was in that same situation too, what you can do here to achieve the same thing is forcing clang-tools' bin folder to appear first in PATH, for example with a shellHook:
0.kind: bugSomething is broken2.status: stalehttps://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md6.topic: llvm/clangIssues related to llvmPackages, clangStdenv and related
Activity
spearman commentedon Dec 25, 2019
So the latest clang-tools/wrapper does fix the version mismatch (now it is clangd 7.1.0 in both cases), but whether or not clangd can find stdio.h still seems to depend on the order. Here are the logs using vim-lsp:
buildInputs = [ clang clang-tools ];buildInputs = [ clang-tools clang ];NilsIrl commentedon Jan 1, 2020
cc @aherrmann
aherrmann commentedon Jan 2, 2020
@NilsIrl
clang-toolscreates a wrapper forclangdthat defines the environment variablesCPATHandCPLUS_INCLUDE_PATH. So, bothclangandclang-toolsprovide differentclangd. It seems thatclangdin LSP is only able to findstdio.hwith theclang-toolsversion ofclangd. That's why the order matters.Looking at the definitions of
clangandclang-toolsinpkgs/top-level/all-packages.nixI also noticed that they are using different LLVM versions by default.clangis defined usingllvmPackagesandclang-toolsusingllvmPackages_latest. See 8dddd6d (couldn't find a related PR). I'm not sure if that could cause further problems. CC @orivej who authored that commit.stale commentedon Jun 30, 2020
Thank you for your contributions.
This has been automatically marked as stale because it has had no activity for 180 days.
If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.
Here are suggestions that might help resolve this more quickly:
MagicRB commentedon Dec 5, 2021
Still relevant and OK to be like it is, it should just be more clear that this order dependent situation exists. I stumbled upon it by accident
Dettorer commentedon Jan 9, 2022
I just fought with
clangdnot being able to find system headers for some time, I'm happy to find that addingclang-toolsbeforeclanginbuildInputsindeed fixes that!Out of curiosity, why does the
clangpackage outputs binaries forclangdand other tools if they aren't wrapped? Or why doesn't it define wrappers like it does for the compiler itself?acowley commentedon Mar 8, 2022
I've stumbled into a variation of this problem where I have a shell made with,
mkShell.override { stdenv = pkgs.clang11Stdenv; }. I'm not sure what the best way to listclang-toolsbeforeclangis in such a case.Dettorer commentedon Mar 8, 2022
I initially was in that same situation too, what you can do here to achieve the same thing is forcing
clang-tools' bin folder to appear first inPATH, for example with a shellHook:acowley commentedon Mar 8, 2022
@Dettorer Thank you! That doesn't get picked up by
direnv, though, does it?MagicRB commentedon Mar 8, 2022
It will, but only in a shell, if youre using direnv from within an editor like Emacs, no it wont get picked up
acowley commentedon Mar 8, 2022
Thank you @MagicRB, that was my conclusion on the issue, too.
It does seem unfortunate that
clangincludes the unwrapped executable. Is there any objection to removing it fromclang's output?MagicRB commentedon Mar 8, 2022
I see no reason why it should even be there, it doesn't work afterall.
4 remaining items
fix(flake): clang-tools moved to nativeBuildInputs (#26955)
fix(flake): clang-tools moved to nativeBuildInputs (neovim#26955)
fix(flake): clang-tools moved to nativeBuildInputs (neovim#26955)
josheppinette commentedon Jan 10, 2025
I just ran into an issue with having to reorder clang/clang-tools to resolve a
error: 'iostream' file not founderror from clang-tidy.The issue is perfectly described in this blog post: https://blog.kotatsu.dev/posts/2024-04-10-nixpkgs-clangd-missing-headers/.
nixos-discourse commentedon Jul 19, 2025
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/configuring-vs-code-for-c-development/66927/2
ethernet-gravy commentedon Dec 6, 2025
are there any plans for fixing this?
nix: list clang-tools before clang so its tools find standard headers
nix: list clang-tools before clang so its tools find standard headers
nix: list clang-tools before clang so its tools find standard headers
nix: list clang-tools before clang so its tools find standard headers