Vscode c++ cpptools and clangd not working

Hi everyone,

I have vscode-with-extensions (unstable) on environment.systemPackages, with the extensions being installed manually from the extensions bar.

I got the following problem with cpptools:

[Error - 16:59:51] cpptools client: couldn't create connection to server.
Launching server using command /home/davide/.vscode/extensions/ms-vscode.cpptools-1.12.4-linux-x64/bin/cpptools failed. Error: spawn /home/davide/.vscode/extensions/ms-vscode.cpptools-1.12.4-linux-x64/bin/cpptools ENOENT

and the following with clangd:

[Error - 17:11:30] Clang Language Server client: couldn't create connection to server.
Launching server using command /home/davide/.config/Code/User/globalStorage/llvm-vs-code-extensions.vscode-clangd/install/15.0.0/clangd_15.0.0/bin/clangd failed. Error: spawn /home/davide/.config/Code/User/globalStorage/llvm-vs-code-extensions.vscode-clangd/install/15.0.0/clangd_15.0.0/bin/clangd ENOENT

In other words, no c++ tool seems to work.

EDIT the two filed actually exist, but if I try to execute them from the terminal I get no such file or directory.

Thank you :slight_smile:


Hi! So this happens because vscode is downloading random binaries from the internet, which are built on a normal distro with the dynamic linker in the normal path, but NixOS doesn’t place the dynamic linker in the usual path.

Let me explain. If you run, e.g.,

ldd /home/davide/.vscode/extensions/ms-vscode.cpptools-1.12.4-linux-x64/bin/cpptools

you will get output something like this:

        linux-vdso.so.1 (0x00007ffe689dc000)
        libdl.so.2 => /nix/store/lxpdbaazqd2s79jx6lngr8nak2rjdaq1-glibc-2.34-210/lib/libdl.so.2 (0x00007f27e9915000)
        libpthread.so.0 => /nix/store/lxpdbaazqd2s79jx6lngr8nak2rjdaq1-glibc-2.34-210/lib/libpthread.so.0 (0x00007f27e9910000)
        libm.so.6 => /nix/store/lxpdbaazqd2s79jx6lngr8nak2rjdaq1-glibc-2.34-210/lib/libm.so.6 (0x00007f27e8527000)
        libc.so.6 => /nix/store/lxpdbaazqd2s79jx6lngr8nak2rjdaq1-glibc-2.34-210/lib/libc.so.6 (0x00007f27e8329000)
        /lib64/ld-linux-x86-64.so.2 => /nix/store/lxpdbaazqd2s79jx6lngr8nak2rjdaq1-glibc-2.34-210/lib64/ld-linux-x86-64.so.2 (0x00007f27e991c000)

The final line there is the so-called “interpreter”, which is at the start of the file with a #!. It’s responsible for starting the application, and making sure all its dynamic libraries are correctly loaded.

As you see, it asks for /lib64/..., which doesn’t exist on NixOS - all libraries and binaries live in the nix store instead.

ldd is even smart enough to find a dynamic linker that would work, but when you execute the binary Linux doesn’t go looking for other files, it just uses exactly the file that the binary asks for, and then gives you the extremely unhelpful “file not found” error message you see.

There are two solutions to this problem:

  1. Manually patch the binaries every time vscode downloads them
  2. Use nix to install the plugins

The former can be done with patchelf.

The latter can be done by not using vscode’s plugin browser, and instead doing something like this:

environment.systemPackages = with pkgs; [
  # <snip lots of packages>
  # ...
  (vscode-with-extensions.override {
    vscodeExtensions = with vscode-extensions; [

Personally, I think this is preferable :slight_smile:

Thank you for your reply. I tried the second approach when I first approached vscode on NixOS, but I gave up as many extensions I routinely use are not present in the store. Trying to manually install extensions not containing binaries from the extensions bar gives an error:

[renderer1] [error] EACCES: permission denied, mkdir '/nix/store/syiwpv55wx6w54m1q27j63ymqkkfsgir-vscode-extensions/share/vscode/extensions/.3c51de5b-0693-41a9-8edf-5f5ba92f839a': Extract: EACCES: permission denied, mkdir '/nix/store/syiwpv55wx6w54m1q27j63ymqkkfsgir-vscode-extensions/share/vscode/extensions/.3c51de5b-0693-41a9-8edf-5f5ba92f839a'
    at J.extractAtLocation (vscode-file://vscode-app/nix/store/006i7y5prgw2iqg8ysi91wl1va019zfl-vscode-1.71.2/lib/vscode/resources/app/out/vs/code/electron-browser/sharedProcess/sharedProcessMain.js:83:164082)
    at async J.extractUserExtension (vscode-file://vscode-app/nix/store/006i7y5prgw2iqg8ysi91wl1va019zfl-vscode-1.71.2/lib/vscode/resources/app/out/vs/code/electron-browser/sharedProcess/sharedProcessMain.js:83:161465)
    at async G.extract (vscode-file://vscode-app/nix/store/006i7y5prgw2iqg8ysi91wl1va019zfl-vscode-1.71.2/lib/vscode/resources/app/out/vs/code/electron-browser/sharedProcess/sharedProcessMain.js:83:168414)
    at async G.doRun (vscode-file://vscode-app/nix/store/006i7y5prgw2iqg8ysi91wl1va019zfl-vscode-1.71.2/lib/vscode/resources/app/out/vs/code/electron-browser/sharedProcess/sharedProcessMain.js:83:169681)

I tried to change environment.systemPackages to users.users.davide.packages but to no avail.

Are there any hybrid solutions?

In that case you probably want to use vscode-fhs instead of vscode-with-extensions, which I just learned about!

Thank you. That does the trick, but has a problem with git:

Git not found. Install it or configure it using the ‘git.path’ setting

The problem persists after manually editing settings.json. From the log:

[2022-09-23T11:26:25.313Z] [info] Validating found git in: /home/davide/.nix-profile/bin/git
[2022-09-23T11:26:25.332Z] [info] Validating found git in: git
[2022-09-23T11:26:25.338Z] [warning] Git installation not found.

Hmm, it’s saying something about “validating”, any way to get a log from what that validation did? This issue might be relevant: vscode-fhs run from nix develop cannot launch terminal or extensions with binaries · Issue #169464 · NixOS/nixpkgs · GitHub

Thank you. I solved the problem by using the stable version of vscode-fhs in place of the unstable one, as a user suggested.

A couple of further thoughts:
I wonder if it would not be a better idea to use your solution 2, packaging the extension not in the store by myself? I have never packaged anything and I have no idea where to start, nor how long it would take, though.

Second - I notice some conflicts popping out when running sudo nixos-rebuild switch, which apparently do not impact the system’s working:

warning: collision between `/nix/store/5aba3b8kk4srznz895sv9jgybs03k90m-glibc-multi-2.34-210-bin/bin/ldconfig' and `/nix/store/p5s01iqh7w0dgm7d3p5r2m4hwcj7yp6n-ldconfig/bin/ldconfig'
warning: collision between `/nix/store/akdcc3j6k15nn2l8i5mqmq6jr392ppcn-glibc-multi-2.34-210/lib/locale/locale-archive' and `/nix/store/fqmdxlbk32miazamkyavwwiwkn146i37-glibc-locales-2.34-210/lib/locale/locale-archive'
warning: collision between `/nix/store/pnqyyr621w93zqb550q5889b1ri1qah5-gcc-11.3.0-lib/lib64/libgcc_s.so.1' and `/nix/store/akdcc3j6k15nn2l8i5mqmq6jr392ppcn-glibc-multi-2.34-210/lib64/libgcc_s.so.1'
warning: collision between `/nix/store/pnqyyr621w93zqb550q5889b1ri1qah5-gcc-11.3.0-lib/lib64/libgcc_s.so' and `/nix/store/akdcc3j6k15nn2l8i5mqmq6jr392ppcn-glibc-multi-2.34-210/lib64/libgcc_s.so'
warning: collision between `/nix/store/pnqyyr621w93zqb550q5889b1ri1qah5-gcc-11.3.0-lib/lib/libgcc_s.so.1' and `/nix/store/akdcc3j6k15nn2l8i5mqmq6jr392ppcn-glibc-multi-2.34-210/lib/libgcc_s.so.1'
warning: collision between `/nix/store/pnqyyr621w93zqb550q5889b1ri1qah5-gcc-11.3.0-lib/lib/libgcc_s.so' and `/nix/store/akdcc3j6k15nn2l8i5mqmq6jr392ppcn-glibc-multi-2.34-210/lib/libgcc_s.so'
warning: collision between `/nix/store/l4b3ilygyf9vwb037dhfxf53zhhfg12q-glibc-2.34-210-bin/bin/ldconfig' and `/nix/store/p5s01iqh7w0dgm7d3p5r2m4hwcj7yp6n-ldconfig/bin/ldconfig'
warning: collision between `/nix/store/l4b3ilygyf9vwb037dhfxf53zhhfg12q-glibc-2.34-210-bin/bin/ldd' and `/nix/store/5aba3b8kk4srznz895sv9jgybs03k90m-glibc-multi-2.34-210-bin/bin/ldd'
warning: collision between `/nix/store/lxpdbaazqd2s79jx6lngr8nak2rjdaq1-glibc-2.34-210/lib/locale/locale-archive' and `/nix/store/fqmdxlbk32miazamkyavwwiwkn146i37-glibc-locales-2.34-210/lib/locale/locale-archive'

plus others involving virtualbox and sushi. Perhaps this may have effects on how the system and applications read the binaries?

Hrm, that sounds like you are pulling things from multiple versions of nixpkgs and end up needing to have them around at the same time, or something. Can’t really judge what’s happening here without more context, but that looks quite scary.

Looks like it’s actually pretty easy to do, there’s some documentation for that in the vscode-with-extensions definition: nixpkgs/with-extensions.nix at bcc68429a50c4ac051920c72c60e417202c19d79 · NixOS/nixpkgs · GitHub

thank you for your reply, the comment in your link explains how solve the problem and now I have all the extensions working - both on the store and not!

About the conflicts - what context would be useful?

thank you :slight_smile:

Your configuration, and if you’re not using a flake your channels. I’d make a new topic though; I don’t know too much about how NixOS handles collisions, so it’d be better if someone else chimes in :wink:

1 Like