I’m working on switching over to NixOS on my desktop and one of the last things I haven’t got fully working is my neovim config. My LSP’s are able to start, and all of them work fine except for clangd. For some reason, it can’t find C/C++ header files for any installed libraries. I have all of the LSPs themselves installed through Mason in Neovim, and I have programs.nix-ld.enable = true enabled so they can be run correctly.

screenshot showing 'file not found' error on '#include <fcntl.h>'

screenshot showing 'file not found' error on '#include <SDL2/SDL2.h>'

Here is the shell.nix file I’m using for this project:

{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell.override { stdenv = pkgs.gccStdenv; } {
  nativeBuildInputs = with pkgs.buildPackages; [
    glibc libgcc
    clang-tools libclang
    SDL2 SDL2_image SDL2_sound
  ]; 
  CPATH = pkgs.lib.makeSearchPathOutput "dev" "include" pkgs.glibc pkgs.SDL2 pkgs.SDL2_Image pkgs.SDL2_sound;
}

Is there something extra I need to do to get clangd to find the C headers being used by the project? when I actually run gcc it compiles fine, it just can’t seem to find them correctly in Neovim

Edit: Forgot to mention that I’m using this shell with direnv and launching nvim directly from the same shell that I’m compiling from

  • Zangoose@lemmy.worldOP
    link
    fedilink
    English
    arrow-up
    1
    ·
    29 days ago

    I’m actually using CMake for this project (I just haven’t moved it over from my system config yet) so I was able to set an environment variable to get that successfully. Is there a specific place I need to put the json to get clangd to recognize it?

    It would probably work if I used the python script from the other project but I want to try getting it working directly first.

    • balsoft@lemmy.ml
      link
      fedilink
      English
      arrow-up
      2
      ·
      edit-2
      29 days ago

      Hmm, I think for me it just picks it up from the project root “magically”. I’m starting my editor from the project root too, maybe that matters (i.e. clangd looks for this file in $PWD)?

      Actually, looking at the docs, it should just search for it upwards from the source file you’re editing, so it can find it in the project root or in the subdirectory where your code lives. If you have it in some other locaiton, you can set this option in the .clangd file in your project root.