Visual Studio Code: Difference between revisions

From NixOS Wiki
imported>Mic92
No edit summary
imported>Tbenst
link to nix-env-selector
Line 66: Line 66:
== Remote ssh ==
== Remote ssh ==
When first launching remote-ssh for a NixOS host, the connection will fail due to a missing glibc dependency in the shipped node.js.  
When first launching remote-ssh for a NixOS host, the connection will fail due to a missing glibc dependency in the shipped node.js.  
This can be resolved by installing the <code>nodejs-12_x</code> package on the NixOS host.
This can be resolved by installing the <code>nodejs-12_x</code> package on the NixOS host. If the extension was installed from the store itself follow the instructions in https://github.com/microsoft/vscode-remote-release/issues/648#issuecomment-503148523. Note that nodejs needs to be updated according to VS Code upstream requirements (node 12 is needed as of 12/6/2019)
If vscode-remote is installed from nix (vscode-extensions.ms-vscode-remote) this will automatically replace the node.js shipped by the extension. If the extension was installed from the store itself follow the instructions in https://github.com/microsoft/vscode-remote-release/issues/648#issuecomment-503148523. Note that nodejs needs to be updated according to VS Code upstream requirements (node 12 is needed as of 12/6/2019)
 
If vscode-remote is installed from nix (vscode-extensions.ms-vscode-remote) this will automatically replace the node.js shipped by the extension.
 
== Using nix-shell ==
Some features of VSCode, like the Python package, require linters or other dependencies. The package [https://marketplace.visualstudio.com/items?itemName=arrterian.nix-env-selector nix-env-selector] makes this easy and does not require overrides on vscode itself to add dependencies.

Revision as of 05:28, 2 January 2020

Installing Microsoft's Visual Studio Code

Note: Visual Studio Code is unfree, its license prohibits distribution. See the FAQ/unfree page to install unfree software.

Because it is NixOS, you don't have to be root in order to be able to install stuff. As a normal user, do:

$ nix-env -iA nixos.vscode

And to open or launch the IDE, do:

$ code

As a normal user, you might be curious what stuff you have installed. To find out, do:

$ nix-env -q

Also, if you want to uninstall stuff that you installed there as a normal user, do:

$ nix-env --uninstall package-name-here

Replace the package-name-here with whatever package returned by 'nix-env -q'.

Managing extensions

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

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

We can retrieve an updated set for manually installed / specified packages by cloning the 'nixpkgs' repo from github, and running: 'nixpkgs/pkgs/misc/vscode-extensions/update_installed_exts.sh'

Remote ssh

When first launching remote-ssh for a NixOS host, the connection will fail due to a missing glibc dependency in the shipped node.js. This can be resolved by installing the nodejs-12_x package on the NixOS host. If the extension was installed from the store itself follow the instructions in https://github.com/microsoft/vscode-remote-release/issues/648#issuecomment-503148523. Note that nodejs needs to be updated according to VS Code upstream requirements (node 12 is needed as of 12/6/2019)

If vscode-remote is installed from nix (vscode-extensions.ms-vscode-remote) this will automatically replace the node.js shipped by the extension.

Using nix-shell

Some features of VSCode, like the Python package, require linters or other dependencies. The package nix-env-selector makes this easy and does not require overrides on vscode itself to add dependencies.