VSCodium

From NixOS Wiki
Jump to: navigation, search

VSCodium is a build of Visual Studio Code without the proprietary bits that are included in the official distribution. See https://github.com/VSCodium/vscodium#readme for more background.

Installation

NixOS

environment.systemPackages = with pkgs; [ vscodium ];

Extensions can be managed using the 'vscode-with-extensions' package:

environment.systemPackages = with pkgs; [
  (vscode-with-extensions.override {
    vscode = vscodium;
    vscodeExtensions = with vscode-extensions; [
      bbenoist.nix
      ms-python.python
      ms-azuretools.vscode-docker
      ms-vscode-remote.remote-ssh
    ] ++ pkgs.vscode-utils.extensionsFromVscodeMarketplace [
      {
        name = "remote-ssh-edit";
        publisher = "ms-vscode-remote";
        version = "0.47.2";
        sha256 = "1hp6gjh4xp2m1xlm1jsdzxw9d8frkiidhph6nvl24d0h8z34w49g";
      }
    ];
  })
];

Some examples here: GitHub search for "extensionFromVscodeMarketplace"

extensionsFromVscodeMarketplace is a manual way to fetch extensions. However, to keep updated from upstream, nix-community/nix-vscode-extensions provides the Nix expressions for the majority of available extensions from Open VSX and VSCode Marketplace. A GitHub Action updates the extensions daily.

It's also possible to install VSCodium via Home Manager:

programs.vscode = {
  enable = true;
  package = pkgs.vscodium;
  extensions = with pkgs.vscode-extensions; [
    dracula-theme.theme-dracula
    vscodevim.vim
    yzhang.markdown-all-in-one
  ];
};

Please note that some Visual Studio Code extensions have licenses that restrict their use to the official Visual Studio Code builds and therefore do not work with VSCodium. See this note on the VSCodium docs page for what's been found so far and possible workarounds.

remote-ssh

In particular, remote-ssh does not work yet with VSCodium out of the box.

Both VSCode and VSCodium use ssh to install software on the remote machine:

   [nixos@nixos:~]$ ls .vscodium-server/
   bin  data  extensions

And since the programs are built for Debian they won't find the libraries in /lib thus need a patchelf run.

This is where https://github.com/nix-community/nixos-vscode-server/ comes in and in particular the auto-fix-vscode-server.service script. One can hack the script or temporarly rename the .vscodium-server into ./vscode-server so that the script applies the changes to the node binary. A symlink should also work but i didn't test it:

   ln -s .vscodium-server/ .vscode-server

Afterwards restart the machine so the script is executed. You can verify that it worked using ldd and it should show:

   [nixos@nixos:~/.vscodium-server/bin]$ ldd 0f99737786f756fe93e2a6e5d8146c46f4a53a4f/node
   not a dynamic executable

And not the errors:

   [nixos@nixos:~/.vscodium-server/bin/0f99737786f756fe93e2a6e5d8146c46f4a53a4f]$ ldd node
       linux-vdso.so.1 (0x00007ffc0fdad000)
       libdl.so.2 => /nix/store/anlf335xlh41yjhm114swi87406mq5pw-glibc-2.38-44/lib/libdl.so.2 (0x00007fabfe549000)
       libstdc++.so.6 => not found
       libm.so.6 => /nix/store/anlf335xlh41yjhm114swi87406mq5pw-glibc-2.38-44/lib/libm.so.6 (0x00007fabfe469000)
       libgcc_s.so.1 => /nix/store/00r99fxv6l92wk0k6wd60klhs7fkmmqj-xgcc-12.3.0-libgcc/lib/libgcc_s.so.1 (0x00007fabfe448000)
       libpthread.so.0 => /nix/store/anlf335xlh41yjhm114swi87406mq5pw-glibc-2.38-44/lib/libpthread.so.0 (0x00007fabfe443000)
       libc.so.6 => /nix/store/anlf335xlh41yjhm114swi87406mq5pw-glibc-2.38-44/lib/libc.so.6 (0x00007fabfe258000)
       /lib64/ld-linux-x86-64.so.2 => /nix/store/anlf335xlh41yjhm114swi87406mq5pw-glibc-2.38-44/lib64/ld-linux-x86-64.so.2 (0x00007fabfe550000)

At least 1.88.0 codium was working with WSL2 nixos-wsl version 23.11.6207.b2cf36f43f9e (Tapir).

Non-NixOS

$ nix-env -iA nixos.vscodium

Use VS Code extensions without additional configuration

With the package vscodium.fhs, the editor launches inside a FHS compliant chroot environment using buildFHSUserEnv. This reintroduces directories such as /bin, /lib, and /usr, which allows for extensions which ship pre-compiled binaries to work with little to no additional nixification.

Note: From a philosophical view, use of buildFHSUserEnv allows for ease-of-use at the cost of some impurity and non-reproducibility. If you prioritize purely-declarative configurations, please stay with the above guidance.

Example usage:

environment.systemPackages = with pkgs; [ vscodium.fhs ];

Home-manager:

programs.vscode = {
  enable = true;
  package = pkgs.vscodium.fhs;
};

Adding extension-specific dependencies, these will be added to the FHS environment:

# needed for rust lang server extension
programs.vscode.package = pkgs.vscodium.fhsWithPackages (ps: with ps; [ rustup zlib ]);

Creating development environments using nix-shell

Instead of using configuration.nix to add packages (e.g. Python or NodeJS) for developing code on VSCode, you can instead use nix-shell. This will allow you to seamlessly create development environments with the correct packages for your project, without rebuilding and restarting NixOS. See this page for further instructions in building nix-shell development environments.

The extension nix-env-selector will make switching between different nix-shell environments within VSCode so you can switch between different coding projects easily. It has a guide for setting up nix-shell environments for VSCode.

Troubleshooting

Issues running Vscodium on Wayland

In case of a broken graphical interface while running Vscodium on Wayland, removing following cache directories might resolve the issues:

$ rm -r ~/.config/VSCodium/GPUCache ~/.config/VSCodium/Crashpad

An other workaround is to run Vscodium without GPU acceleration

$ codium --disable-gpu