-
-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Docs: complete process for how to use VSCode #294
Comments
I've had a workaround for this for a while that I never got around to publishing, but now I did: https://github.com/K900/vscode-remote-workaround This should be enough to get things working without any extra movements, no matter what setup you're using. |
Got vscode wsl remoting with NixOS to work. This is using the nix-ld approach Version Info
Setup Instructions
wsl.extraBin = with pkgs; [
{ src = "${coreutils}/bin/uname"; }
{ src = "${coreutils}/bin/dirname"; }
{ src = "${coreutils}/bin/readlink"; }
];
programs.nix-ld.enable = true;
nix.settings.experimental-features = [ "nix-command" "flakes" ];
environment.systemPackages = [
pkgs.wget
];
# note the changes to `wsl.exe -d nixos -e sh -l -c` and expanding the `$VSCODE_WSL_EXT_LOCATION`
C:\Windows\System32\wsl.exe -d nixos -e sh -l -c '"/mnt/c/Users/Acelinkio/.vscode/extensions/ms-vscode-remote.remote-wsl-0.81.8/scripts/wslServer.sh" f1b07bd25dfad64b0167beb15359ae573aecd2cc stable code-server .vscode-server --host=127.0.0.1 --port=0 --connection-token=3823671665-1023682691-1766917102-882463176 --use-host-proxy --without-browser-env-var --disable-websocket-compression --accept-server-license-terms --telemetry-level=all'
ThoughtsChanging wslDaemon.js as mentioned https://nixos.wiki/wiki/Visual_Studio_Code#Remote_WSL did nothing. My guess is that that file is versioned outside of the wsl extension. No amount of changing versions or restarting vscode helped. The underlying wsl remoting commands being executed did not respect any modifications. Really would like to see this user experience improved. Most of this appears to have been caused by the VSCode WSL extension changes. Closest issue I could find is microsoft/vscode-remote-release#8305 |
I believe the solutions mentioned above should have worked before Remote-WSL 0.77.0, which broke all the solutions and caused microsoft/vscode-remote-release#8305. |
I think we can use the fallback path since nix-community/nix-ld#53 |
Here's the simplest solution I have found so far. On a fresh wsl instance, put this flake somewhere and then apply via flake.nix {
description = "SpecialSnowflake";
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05";
inputs.nixoswsl.url = "github:nix-community/NixOS-WSL";
inputs.nixoswsl.inputs.nixpkgs.follows = "nixpkgs";
inputs.vscode-server.url = "github:nix-community/nixos-vscode-server";
outputs = {
self,
nixpkgs,
nixoswsl,
vscode-server,
...
}: {
nixosConfigurations.nixos = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
nixoswsl.nixosModules.wsl
vscode-server.nixosModules.default
({ pkgs, ... }: {
system = {
stateVersion = "23.05";
};
programs.nix-ld.enable = true;
services.vscode-server.enable = true;
environment.systemPackages = [
pkgs.wget
];
wsl = {
enable = true;
defaultUser = "nixos";
extraBin = with pkgs; [
{ src = "${coreutils}/bin/uname"; }
{ src = "${coreutils}/bin/dirname"; }
{ src = "${coreutils}/bin/readlink"; }
];
};
})
];
};
};
}
For anyone trying to create solutions, be sure to document how to get things started. Trying to do first run from VSCode starting a WSL remote connection leads to errors with another group of missing tools. referencing nix-community/nixos-vscode-server#67 as this has been the simplest flake so far. I did not have luck with others. |
I really do not want to enable nix-ld as it changes LD_LIBRARY_PATH for everything which can lead to weird bugs in my experience. |
nix-ld-rs behaves differently
…On Thu, Nov 9, 2023 at 2:37 AM Sandro ***@***.***> wrote:
I really do not want to enable nix-ld as it changes LD_LIBRARY_PATH for
everything which can lead to weird bugs in my experience.
—
Reply to this email directly, view it on GitHub
<#294 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAES3ORRXQDWDKHSLZUOVZLYDSXAPAVCNFSM6AAAAAA5HT3IOOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMBTGU3TSOJWGA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@acelinkio
Upon investigation, I found that the issue lies in the $PATH environment variable, which lacks |
I don't know how Docker based container remoting works when inside WSL. Afaik the connection is made by invoking the I successfully got the remoting working with kuberenetes by directly point the kubernetes api server that is hosted WSL. Doing it this way avoids leveraging the |
I would try |
Does anyone have a lightweight solution to this issue that doesn't require |
There are two small errors that happened with recent versions of vscode. One is with not being able to locate { src = "${coreutils}/bin/cat"; }
{ src = "${coreutils}/bin/sed"; }
{ src = "/run/current-system/sw/bin/sed"; } After exploring @rodent1 nix configuration, there is a more direct fix that allows wsl remoting to be opened by Windows or Nixos. Creating a configuration
Reference for how I implemented https://github.com/acelinkio/nixplayground/blob/main/wsl/flake.nix Docs: https://code.visualstudio.com/docs/remote/wsl#_advanced-environment-setup-script |
I tried the eg nixos config wsl = {
enable = true;
defaultUser = "nixos";
};
environment.systemPackages = with pkgs; [
wget
];
programs.nix-ld = {
enable = true;
package = inputs.nix-ld-rs.packages.${pkgs.system}.default;
}; Honestly it doesn't look like you even need vscode-server with it. |
Hello. I've summed up and tested the minimum WSL2 NixOS config that make VSCode Remote works.
{
inputs = {
nixpkgs.url = "nixpkgs";
nixos-wsl = {
url = "github:nix-community/NixOS-WSL";
inputs.nixpkgs.follows = "nixpkgs";
};
nix-ld-rs = {
url = "github:nix-community/nix-ld-rs";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = inputs: with inputs; {
nixosConfigurations.nixos = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
specialArgs = { inherit inputs; };
modules = [
nixos-wsl.nixosModules.default
./configuration.nix
];
};
};
}
{
wsl = {
enable = true;
defaultUser = "nixos";
};
nix.settings.experimental-features = [ "nix-command" "flakes" ];
programs.nix-ld = {
enable = true;
package = inputs.nix-ld-rs.packages."${pkgs.system}".nix-ld-rs;
};
}
PATH=$PATH:/run/current-system/sw/bin/ Hope it will be helpful!
|
Why micro? I don't think we need that. |
Sorry, it's just a text editor I used. Removed. |
Above solution by @songpola fixed NixOS WSL and VSCode Insiders for me. Insiders can now successfully open remote connection to WSL both by running 'code-insiders .' within WSL directory, and by launching VSCode in Windows and connecting. |
I use the stable one. Glad it helps with Insider one too! |
Hmm, I did a fresh install recently and now for some reason after going into my project directory, running Not sure what happened. Pretty sure it worked just fine on the previous installation. |
@0xLunch Have you by any chance found a solution? I just freshly installed nix and got VsCode working and I have the exact same problem. Edit2: Edit3: shellHook =
''
WSLENV=$WSLENV:PATH
''; to my |
Update: Today, I tried the setup again and found that it works even without the |
+1 I just want vscode server to run with entering |
On Mac, this solution will work as same? |
With @songpola config, I'm getting such an error: `error: undefined variable 'inputs'
|
@arraen make sure you are passing the outputs = inputs: with inputs; {
# IMPORTANT ^^^^^^^^^^^^^^^^^^^
nixosConfigurations.nixos = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
specialArgs = { inherit inputs; };
# IMPORTANT ^^^^^^^^^^^^^^
modules = [
nixos-wsl.nixosModules.default
./configuration.nix
];
};
}; |
@carschandler Yes, I copied both configs and put them into fresh wsl. *Also, you should have wget installed :) PS Additionally, in |
I'm a bit confused by the need to use VSCode on the host with the WSL extension in the first place; wouldn't it be better to just use VSCode from WSL directly, since it's possible to use GUI apps + we'd also get to use the VSCode home-manager module ? |
Not really, no, because WSLg is far from perfect, is currently not very fast (though that is something that could be addressed on the NixOS side to an extent), and isn't always enabled. |
For this time period, I think it is necessary to update the documentation After several hours of trying, I can now prove that the method mentioned in https://github.com/sonowz/vscode-remote-wsl-nixos is completely usable except for a small flaw. I may upload all the configuration files later but I think everything mentioned in this repository can solve the problems you encounter (only wget is needed, not K900 and nix-ld solutions). Ok, the url https://github.com/nan-mu/nixos-config |
If possible, I'd like to write a document about this, but I see a lot of similar pull requests are open? Any plans for documentation? |
There is a file on now to run vscode remote server. https://github.com/nix-community/NixOS-WSL/blob/main/docs/src/how-to/vscode.md |
The strange thing is that both methods didn't work after trying them. There are somethings, for example, it seems that nix-ld-rs has been merged into nix-ld, and I can't find the functions mentioned in the documentation for the latest version. Also, K900's solution reported a socket timeout error in vscode side. I think these errors are not difficult to reproduce. |
@nan-mu For the latest version (unstable), you can just enable only the |
Thanks, I tried that too. But it seems like don't work for me. |
I just had the same issue today, and your workaround works for me. Thanks! BTW, if you have
|
Problem
On WSL with a fresh Ubuntu install, running
code .
works to make the distro immediately useful. On NixOS there are a number of decisions to be made and issues to be overcome before being able to use the distro for dev work.The info about this process is scattered across a number of issues (see below) and discussions in this repo, plus NixOS wiki pages, the NixOS discourse and other repos.
A lot of this information is conflicting and/or outdated.
Relevant issues for initial VSCode install/setup process:
wsl --exec
#222Background:
I am a complete noob to NixOS (though I have 15+ years of Linux and software dev experience). The ideas behind Nix are appealing, so thought I'd try it out for some dev work via WSL to get acquainted. When starting NixOS on WSL for the first time, the first task I tried to achieve (after upgrading) was to get a working dev env up and running, including VSCode. Unfortunately, even after eventually reading all the resources listed above, I still haven't achieved a fully-working VSCode install & dev setup I'm comfortable with (so have had to revert to Ubuntu for the time being)
Virtually everyone I know using WSL is also using VSCode, so this seems like an extremely common first step for new installers. AFAICT at least some of the kindly folks working on NixOS-WSL (including @nzbr ) are using vscode successfully (there is a
.vscode
dir in the repo root). So would be very helpful to have their knowledge/opinions distilled into ...Solution
An authoritative set of clear, concise, up-to-date, step-by-step/end-to-end instructions on how to go from a fresh install to a working dev env with VSCode. Ideally this would be in this repo, linked from the README and effectively considered part of the initial install instructions
Specific questions to address:
The text was updated successfully, but these errors were encountered: