When I run nix-shell in the project root, I can compile and run C++ code from the terminal, including standard headers like <iostream>, <vector>, and libraries like Boost and spdlog—everything works.
I have a shell.nix for C++ development with GCC, Boost, CMake, etc.
shell.nix:
buildInputs = with pkgs; [
stdenv.cc.cc.lib
boost
cmake
ninja
spdlog
yaml-cpp
openssl
protobuf
gnulib
nlohmann_json
catch2_3
];
Problem: When I open VSCodium or LunarVim (even from inside the nix-shell), the language server shows missing headers like <iostream>.
I’ve tried exporting PATH in shellHook, but the editor still doesn’t see the standard headers.
export CPATH=${pkgs.stdenv.cc.cc.lib}/include/c++/${pkgs.stdenv.cc.version}:$CPATH
export LIBRARY_PATH=${pkgs.stdenv.cc.cc.lib}/lib:$LIBRARY_PATH
export LD_LIBRARY_PATH=${pkgs.stdenv.cc.cc.lib}/lib:$LD_LIBRARY_PATH
Also, My codium setup:
{config, pkgs, ...}: {
programs.vscode = {
enable = true;
package = pkgs.vscodium;
extensions = with pkgs.vscode-extensions; [
vscodevim.vim
jnoortheen.nix-ide
llvm-vs-code-extensions.vscode-clangd # I'm using this one for C/C++ Completion
github.github-vscode-theme
rust-lang.rust-analyzer
pylyzer.pylyzer
usernamehw.errorlens
christian-kohler.path-intellisense
formulahendry.code-runner
pkief.material-icon-theme
zguolee.tabler-icons
];
};
}
Questions:
- How can I make editors fully recognize C++ headers from a nix-shell?
- Is there a preferred NixOS workflow for GUI editors + nix-shell for C++ development?
Thanks for any tips!