How to use Emacs + eglot to develop C++ under Nix

Have this nix.shell:
    with (import  {});

pkgs.llvmPackages_14.libcxxStdenv.mkDerivation {
  name = "clang-nix-shell";
  buildInputs = [
    opencv
    pkgconfig
    python310
    cmake
    clang_14
  ];

  shellHook = ''
      export CPATH="$NIX_CFLAGS_COMPILE";
    '';
}
  

Then, enter in it with nix-shell.
Then, generate compile_commands.json with this snippet in your CMakeLists.txt:
    if(CMAKE_EXPORT_COMPILE_COMMANDS)
    set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES 
      ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
    endif()
  

Source: https://discourse.nixos.org/t/get-clangd-to-find-standard-headers-in-nix-shell/11268
Then, cd to build and run cmake ..
Then, from within the nix shell, start emacs and run M-x eglot
Profit !!