Skip to content

llvmPackages.clang-tools: add support for -cxx-isystem#462747

Merged
reckenrode merged 1 commit intoNixOS:stagingfrom
reckenrode:push-oypkqxwyotkn
Nov 18, 2025
Merged

llvmPackages.clang-tools: add support for -cxx-isystem#462747
reckenrode merged 1 commit intoNixOS:stagingfrom
reckenrode:push-oypkqxwyotkn

Conversation

@reckenrode
Copy link
Contributor

This is necessary after #445095, which moved libc++ to -cxx-isystem to improve compatibility with build systems that invoke clang to compile C++ code.

Things done

  • Built on platform:
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested, as applicable:
  • Ran nixpkgs-review on this PR. See nixpkgs-review usage.
  • Tested basic functionality of all binary files, usually in ./result/bin/.
  • Nixpkgs Release Notes
    • Package update: when the change is major or breaking.
  • NixOS Release Notes
    • Module addition: when adding a new NixOS module.
    • Module update: when the change is significant.
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other READMEs.

Add a 👍 reaction to pull requests you find important.

@nixpkgs-ci nixpkgs-ci bot added 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-darwin: 101-500 This PR causes between 101 and 500 packages to rebuild on Darwin. 10.rebuild-linux: 1001-2500 This PR causes many rebuilds on Linux and should target the staging branches. 6.topic: llvm/clang Issues related to llvmPackages, clangStdenv and related labels Nov 18, 2025
This is necessary after NixOS#445095,
which moved libc++ to -cxx-isystem to improve compatibility with build
systems that invoke `clang` to compile C++ code.
@reckenrode reckenrode marked this pull request as draft November 18, 2025 01:35
@reckenrode reckenrode changed the base branch from master to staging November 18, 2025 01:35
@nixpkgs-ci nixpkgs-ci bot closed this Nov 18, 2025
@reckenrode reckenrode marked this pull request as ready for review November 18, 2025 01:35
@nixpkgs-ci nixpkgs-ci bot reopened this Nov 18, 2025
@reckenrode
Copy link
Contributor Author

Targeting to staging due to the number of rebuilds.

@nixpkgs-ci nixpkgs-ci bot added the 12.approvals: 1 This PR was reviewed and approved by one person. label Nov 18, 2025
@reckenrode reckenrode added this pull request to the merge queue Nov 18, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 18, 2025
@wolfgangwalther wolfgangwalther added this pull request to the merge queue Nov 18, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 18, 2025
@wolfgangwalther wolfgangwalther added this pull request to the merge queue Nov 18, 2025
@github-actions github-actions bot added the 8.has: port to stable This PR already has a backport to the stable release. label Nov 18, 2025
@mattkang
Copy link
Contributor

I think something about this may have broken my environment. I actually do not use clang but rather gcc. Was using clang-tools merely for clangd as an LSP. Any idea why this might be happening and how I can fix it?

@reckenrode
Copy link
Contributor Author

What branch are you using? This fix won’t land in master until after the next staging cycle. If you’re using the release-25.11 branch, it won’t land until after the next staging-25.11 cycle. From what I understand, a (likely final) staging-25.05 cycle is planned next, so it may take a little bit for the backported fix to hand in 25.11.

@mattkang
Copy link
Contributor

mattkang commented Nov 24, 2025

@reckenrode On nixos-unstable. Double-checked before posting and now triple-checking... pretty sure I've got it. Actually now I'm second-guessing

EDIT: you're right @reckenrode don't have it yet. Hopefully this PR fixes my issue. Will keep my eyes peeled.

@HuaHuaY
Copy link

HuaHuaY commented Nov 26, 2025

I use official nixos-unstable and clangd can't find the header files in the standard library.
I fork nixpkgs, cherry-pick this commit to my repo, add the repo into flake's input section and use clang-tools in the repo. Clangd works well. Thanks for your fix.
@mattkang FYI

@GrahamDennis
Copy link
Contributor

Does this PR Does this PR need to land on master?

@reckenrode
Copy link
Contributor Author

It’s currently going through staging-next.

https://nixpkgs-tracker.ocfox.me/?pr=462747

@hzeller
Copy link
Contributor

hzeller commented Dec 20, 2025

Since this is a crucial component to have clangd work, unchanged unstable and master are not very usable for weeks now to do c++ development. So (at least for me), it is a somewhat critical problem that can be fixed with an unlikely-to-cause-trouble patch.
Would it be possible to cherrypick this change to master, or would that mess up the merge cycle ?

@reckenrode
Copy link
Contributor Author

reckenrode commented Dec 20, 2025

It has to go through staging due to the number of rebuilds it would cause.

If you really need the fix, you can try using the staging-next branch. Note that some of the packages you use may not have been built yet.

@mattkang
Copy link
Contributor

I just want to second that this has made unstable unusable for me. This is required for any real C++ dev. How much longer until it hits master?

@hzeller
Copy link
Contributor

hzeller commented Dec 21, 2025

for my personal projects, I created an overlay, putting that in a file in ~/.config/nixpkgs/overlays/clang-tools-patch.nix

with content

# Locally applying PR 462747, which modifies the wrapper, that ends up named
# clangd in the final package. So patch that `clangd` script with that change.
# The patch contains a path to the wrapper, but we apply it directly to the
# clangd script where it ends up in.
##

# Define a transformation, then apply it to all llvm versions of interest.
final: prev:
let
  # Transformations for each version
  patchClangTools = llvmPkgSet: llvmPkgSet.overrideScope (lfinal: lprev: {
    clang-tools = lprev.clang-tools.overrideAttrs (oldAttrs: {
      postInstall = (oldAttrs.postInstall or "") + ''
        echo "Applying PR 462747 patch to the generated clangd wrapper..."
        patch -i ${prev.fetchpatch {
          url = "https://github.com/NixOS/nixpkgs/pull/462747.diff";
          hash = "sha256-WDP/WJAflkYw8YQDgXK3q9G7/Z6BXTu7QpNGAKjO3co=";
        }} $out/bin/clangd
      '';
    });
  });

  # ... all the llvm version we'd like to apply this to
  llvm_versions = [ "17" "18" "19" "20" "21" ];

in
prev.lib.genAttrs (map (v: "llvmPackages_${v}") llvm_versions) (name: 
  patchClangTools prev.${name}
)

nix-shell will look in that directory and apply overlays found.

So using clang-tools now nix-shell -p llvmPackages_21.clang-tools will use the patched version.

getchoo added a commit to PrismLauncher/PrismLauncher that referenced this pull request Dec 22, 2025
This makes `clangd` work again, thanks to
NixOS/nixpkgs#462747

• Updated input 'nixpkgs':
    'github:NixOS/nixpkgs/c6245e83d836d0433170a16eb185cefe0572f8b8' (2025-12-18)
  → 'https://releases.nixos.org/nixos/25.11/nixos-25.11.2222.b3aad468604d/nixexprs.tar.xz?lastModified=1766201043&narHash=sha256-v9nbQe0BgwBx%2BKcxRf6i2kbS8EwKjBFRjAawA91B/OE%3D&rev=b3aad468604d3e488d627c0b43984eb60e75e782' (2025-12-20)

Signed-off-by: Seth Flynn <getchoo@tuta.io>
Trial97 pushed a commit to Trial97/PrismLauncher that referenced this pull request Dec 25, 2025
This makes `clangd` work again, thanks to
NixOS/nixpkgs#462747

• Updated input 'nixpkgs':
    'github:NixOS/nixpkgs/c6245e83d836d0433170a16eb185cefe0572f8b8' (2025-12-18)
  → 'https://releases.nixos.org/nixos/25.11/nixos-25.11.2222.b3aad468604d/nixexprs.tar.xz?lastModified=1766201043&narHash=sha256-v9nbQe0BgwBx%2BKcxRf6i2kbS8EwKjBFRjAawA91B/OE%3D&rev=b3aad468604d3e488d627c0b43984eb60e75e782' (2025-12-20)

Signed-off-by: Seth Flynn <getchoo@tuta.io>
(cherry picked from commit 5ee3381)
@Mic92
Copy link
Member

Mic92 commented Dec 30, 2025

Also now added in master #475078
Is a 25.11 backport needed?

@evysgarden
Copy link
Contributor

evysgarden commented Jan 1, 2026

A backport to 25.11 would be very appreciated since clangd is unusable for cpp on 25.11 otherwise

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/clang-clang-and-clangd-cant-find-headers-even-with-compile-commands-json/54657/13

@reckenrode
Copy link
Contributor Author

The backport PR was #462884. The fix should already be in release-25.11.

ryanofsky added a commit to ryanofsky/libmultiprocess that referenced this pull request Jan 13, 2026
Without this change, building with -DMP_ENABLE_IWYU=ON and newer versions of
nixpkgs (after 2025-11-12) fails with mysterious errors that look like:

make[2]: *** [CMakeFiles/mputil.dir/build.make:79: CMakeFiles/mputil.dir/src/mp/util.cpp.o] Error 1

with no other error messages. The are no messages because cmake -E
__run_co_compile hides the output from IWYU and does not display anything itself.

The actual problem is missing include directories on the compiler command line,
and the fix here is to extend a workaround previously added for clang-tidy to
be used for IWYU as well.

Breakage seems to have been caused by
NixOS/nixpkgs@76a8ffa
from NixOS/nixpkgs#445095, which I found by bisecting
with --first-parent to a change between the following merge commit:

https://github.com/NixOS/nixpkgs/commits/de21549a840be528ef4763dd7dca2006caf9c11f (bad)
https://github.com/NixOS/nixpkgs/commits/c4d1151093af5d483d1900d9214a65e68bc21560 (good)

If you check out the bad commit above (or any later commit) and revert
NixOS/nixpkgs@76a8ffa
the problem disappears.

I suspect the problem happens because cmake is not handling -cxx-isystem
properly, but did not debug further. The later change
NixOS/nixpkgs#462747 which followed up on
NixOS/nixpkgs#445095 did not seem to have any effect on
this issue in my testing.
@yshui yshui mentioned this pull request Jan 28, 2026
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: llvm/clang Issues related to llvmPackages, clangStdenv and related 8.has: port to stable This PR already has a backport to the stable release. 10.rebuild-darwin: 101-500 This PR causes between 101 and 500 packages to rebuild on Darwin. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 1001-2500 This PR causes many rebuilds on Linux and should target the staging branches. 12.approvals: 1 This PR was reviewed and approved by one person. backport staging-25.11 Backport PR automatically

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants