Visual Studio Code: Difference between revisions

imported>Poelzi
No edit summary
imported>Atry
No edit summary
Line 145: Line 145:
=== Any client to NixOS host ===
=== Any client to NixOS host ===


'''tl;dr Use [https://github.com/msteen/nixos-vscode-server nix-vscode-server] on host machines.'''
'''tl;dr Use [https://github.com/msteen/nixos-vscode-server nix-vscode-server] or [https://github.com/Mic92/nix-ld nix-ld] on host machines.'''
 
==== nix-vscode-server ====


Note that nix-vscode-server works as of 8/21/21 but is occasionally broken (See https://github.com/msteen/nixos-vscode-server/pull/3, https://github.com/msteen/nixos-vscode-server/pull/4, https://github.com/msteen/nixos-vscode-server/pull/5). Here's a workaround: Install the <code>nodejs-16_x</code> package on the NixOS host, and then run the following nix-shell script:
Note that nix-vscode-server works as of 8/21/21 but is occasionally broken (See https://github.com/msteen/nixos-vscode-server/pull/3, https://github.com/msteen/nixos-vscode-server/pull/4, https://github.com/msteen/nixos-vscode-server/pull/5). Here's a workaround: Install the <code>nodejs-16_x</code> package on the NixOS host, and then run the following nix-shell script:
Line 170: Line 172:


If instead you'd prefer to fix the binaries manually and have to do so every time that you upgrade your VS Code version, then you can install the <code>nodejs-16_x</code> package on the NixOS host and replace the VS Code provided version. This workaround is described here: https://github.com/microsoft/vscode-remote-release/issues/648#issuecomment-503148523. Note that NodeJS needs to be updated according to VS Code upstream requirements (NodeJS 16 required from 4/2022).
If instead you'd prefer to fix the binaries manually and have to do so every time that you upgrade your VS Code version, then you can install the <code>nodejs-16_x</code> package on the NixOS host and replace the VS Code provided version. This workaround is described here: https://github.com/microsoft/vscode-remote-release/issues/648#issuecomment-503148523. Note that NodeJS needs to be updated according to VS Code upstream requirements (NodeJS 16 required from 4/2022).
==== nix-ld ====
Add the following settings to <code>configuration.nix</code> on the NixOS host
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
  programs.nix-ld.enable = true;
  environment.variables = {
      NIX_LD_LIBRARY_PATH = lib.makeLibraryPath [
        pkgs.stdenv.cc.cc
      ];
      NIX_LD = lib.fileContents "${pkgs.stdenv.cc}/nix-support/dynamic-linker";
  };
</nowiki>}}
Then run `nixos-rebuild switch` to enable `nix-ld`. Unlike the `nix-vscode-server` solution, `nix-ld` solution also enables VSCode extensions even if they include non-Nix binaries.
=== WSL2 ===
Similar to SSH hosts, both <code>nix-vscode-server</code> and <code>nix-ld</code> solution allows a VSCode Windows client to connect a [https://github.com/nix-community/NixOS-WSL NixOS-WSL] host. However, by default the VSCode Windows client uses <code>wsl.exe --exec</code> to start the code server, which bypasses NixOS environment variables required by <code>nix-ld</code>, resulting in failures. As a workaround, add the following settings for the VSCode Windows client:
{{file|%USERPROFILE%\AppData\Roaming\Code\User\settings.json|json|<nowiki>
{
    "remote.WSL2.connectionMethod": "localhost"
}
</nowiki>}}


=== Nix-sourced VS Code to NixOS host ===
=== Nix-sourced VS Code to NixOS host ===