VSCodium: Difference between revisions

From NixOS Wiki
imported>Dramforever
Fix code snippet so that it's a valid, complete NixOS module
Klinger (talk | contribs)
m Category:IDE added
 
(12 intermediate revisions by 11 users not shown)
Line 1: Line 1:
VSCodium is a build of [[Vscode]] without the proprietary bits that are included in the official [[Vscode]] distribution. See https://github.com/VSCodium/vscodium#readme for more background.
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.


== Install ==
== Installation ==


Install the `vscodium` package.
=== NixOS ===


<syntaxhighlight lang="nix>
<syntaxHighlight lang=nix>
  environment.systemPackages = with pkgs; [ vscodium ];
environment.systemPackages = with pkgs; [ vscodium ];
</syntaxHighlight>
 
Extensions can be managed using the 'vscode-with-extensions' package:
 
<syntaxhighlight lang="nix">
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 = "dscodegpt";
        publisher = "DanielSanMedium";
        version = "3.4.10";
        hash = "sha256-zjaM9YME0wfBOwhJTacnQbQvw35QL5NvXIBAx5d/bjI=";
      }
    ];
  })
];
</syntaxhighlight>
</syntaxhighlight>


== Managing extensions ==
Some examples here: [https://github.com/search?q=extensionFromVscodeMarketplace&type=code GitHub search for "extensionFromVscodeMarketplace"]


Extensions can be managed using the 'vscode-with-extensions' package, mostly like for [[Vscode]]:
{{ic|extensionsFromVscodeMarketplace}} is a manual way to fetch extensions. However, to keep updated from upstream, [https://github.com/nix-community/nix-vscode-extensions 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]]:
<syntaxhighlight lang="nix">
programs.vscode = {
  enable = true;
  package = pkgs.vscodium;
  extensions = with pkgs.vscode-extensions; [
    dracula-theme.theme-dracula
    vscodevim.vim
    yzhang.markdown-all-in-one
  ];
};
</syntaxhighlight>
* See for more options: [https://nix-community.github.io/home-manager/options.xhtml#opt-programs.vscode.enable Home Manager Manual: Options - programs.vscode]
* Search for extensions with configurations: [https://search.nixos.org/packages?type=packages&query=vscode-extensions NixOS Search: vscode-extensions]
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 [https://github.com/VSCodium/vscodium/blob/master/docs/index.md#proprietary-debugging-tools this note on the VSCodium docs page] for what's been found so far and possible workarounds.
In particular, [https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh remote-ssh] does not work yet with VSCodium.
=== Non-NixOS ===
<syntaxHighlight lang="console">
$ nix-env -iA nixos.vscodium
</syntaxHighlight>
=== Use VS Code extensions without additional configuration ===
With the package vscodium.fhs, the editor launches inside a [https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard 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:
<syntaxHighlight lang=nix>
<syntaxHighlight lang=nix>
{ pkgs, ... }:
environment.systemPackages = with pkgs; [ vscodium.fhs ];
</syntaxHighlight>


let
Home-manager:
   extensions = (with pkgs.vscode-extensions; [
<syntaxHighlight lang=nix>
      bbenoist.Nix
programs.vscode = {
      ms-python.python
  enable = true;
      ms-azuretools.vscode-docker
   package = pkgs.vscodium.fhs;
    ]) ++ pkgs.vscode-utils.extensionsFromVscodeMarketplace [
};
    {
</syntaxHighlight>
      name = "remote-ssh-edit";
 
      publisher = "ms-vscode-remote";
Adding extension-specific dependencies, these will be added to the FHS environment:
      version = "0.47.2";
<syntaxHighlight lang=nix>
      sha256 = "1hp6gjh4xp2m1xlm1jsdzxw9d8frkiidhph6nvl24d0h8z34w49g";
# needed for rust lang server extension
    }
programs.vscode.package = pkgs.vscodium.fhsWithPackages (ps: with ps; [ rustup zlib ]);
  ];
</syntaxHighlight>
  vscodium-with-extensions = pkgs.vscode-with-extensions.override {
 
    vscode = pkgs.vscodium;
== Creating development environments using nix-shell ==
    vscodeExtensions = extensions;
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 [[Development_environment_with_nix-shell | this page]] for further instructions in building nix-shell development environments.
  };
 
in {
The extension [https://marketplace.visualstudio.com/items?itemName=arrterian.nix-env-selector 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.
  environment.systemPackages = [
 
    vscodium-with-extensions
== 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:
 
<syntaxHighlight lang="console">
$ rm -r ~/.config/VSCodium/GPUCache ~/.config/VSCodium/Crashpad
</syntaxHighlight>
 
An other workaround is to run Vscodium without GPU acceleration
 
<syntaxHighlight lang="console">
$ codium --disable-gpu
</syntaxHighlight>
</syntaxHighlight>


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 [https://github.com/VSCodium/vscodium/blob/master/DOCS.md#proprietary-debugging-tools this note on the VSCodium docs page] for what's been found so far and possible workarounds.
[[Category:Applications]]
In particular [https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh remote-ssh] does not work yet with vscodium.
[[Category:IDE]]

Latest revision as of 21:22, 26 September 2024

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 = "dscodegpt";
        publisher = "DanielSanMedium";
        version = "3.4.10";
        hash = "sha256-zjaM9YME0wfBOwhJTacnQbQvw35QL5NvXIBAx5d/bjI=";
      }
    ];
  })
];

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. In particular, remote-ssh does not work yet with VSCodium.

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