NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
16.66k stars 13.11k forks source link

Clangd issues with clang and clang-tools package. #308482

Open ErinaInit opened 2 months ago

ErinaInit commented 2 months ago

Describe the bug

I'm developing a cpp project and I have some fuzz with clangd.

Steps To Reproduce

Steps to reproduce the behavior:

  1. Here's my devshell flake:
    
                  packages = with pkgs; [
                    clang
                    clang-tools
                    cmake
                    cmakeCurses
                    xorg.libX11
                    xorg.libXi
                    boost
                  ];
2. Go into the shell and find clangd, which resides in /nix/store/bcjr80nk9cxy2bwhmz8pdl7zxd30mxba-clang-17.0.6/bin/clangd
as a binary file. And it does failed to find the libraries.

### Expected behavior
Clangd should come from clang-tools instead and be a script, residing in /nix/store/brxm6ld0k4ipciq4rmh013p48mvqmj8r-clang-tools-17.0.6/bin/clangd

### Screenshots
![test](https://github.com/NixOS/nixpkgs/assets/161044739/7e5a02d9-34b1-4825-a6c1-85f1db7dc7ba)
![test](https://github.com/NixOS/nixpkgs/assets/161044739/8961fe36-c749-42c3-8da5-1ec184d9f9ec)

### Metadata
kotatsuyaki commented 2 months ago

I have met this issue before. Swapping the order of clang and clang-tools in the list so that clang-tools come first solved it for me as a workaround.

The problem only happens in a nix develop devShell and not when, for example, using nix shell twice to add clang and clang-tools to $PATH, no matter the order. The reason seems to be that only nix develop runs the setup hooks, and the setup hook of clang (wrapped) adds the path to unwrapped clangd to $_PATH that's added to $PATH by the stdenv setup file. Details in my messy note.

ErinaInit commented 2 months ago

This worked. I wonder if we should fix this though.