I eventually got fed up with needing to solve this problem differently for each build system, so wrote this: GitHub - danielbarter/mini_compile_commands. it is similar to bear, but works more reliably on nixos (bear struggles to distinguish between our compiler wrappers and the compiler invocations themselves)