sonowz / vscode-remote-wsl-nixos

Develop using VSCode Remote-WSL environment with NixOS
72 stars 4 forks source link

bunch of "command not found" errors #6

Closed boozedog closed 11 months ago

boozedog commented 1 year ago

Remote WSL works fine with WSL Debian on my system.

I've got nixos-unstable running in WSL2 with flakes. I am able to connect using Windows terminal and things work as expected. uname, wget, nixos-version, etc all work fine.

However, when I try to connect using remote WSL in VS Code, it fails with the output below.

[2023-07-25 19:02:31.535] authorityHierarchy: wsl+NixOS
[2023-07-25 19:02:31.536] WSL extension activating for a local WSL instance
[2023-07-25 19:02:31.545] Resolving wsl+NixOS, resolveAttempt: 1
[2023-07-25 19:02:31.546] WSL feature installed: true (dll path)
[2023-07-25 19:02:31.547] Run: C:\Windows\System32\wsl.exe --list --verbose
[2023-07-25 19:02:31.611] Starting VS Code Server inside WSL (wsl2)
[2023-07-25 19:02:31.611] Extension version: 0.80.2
[2023-07-25 19:02:31.611] Windows build: 19045. Multi distro support: available. WSL path support: enabled
[2023-07-25 19:02:31.611] L10N bundle: undefined
[2023-07-25 19:02:31.611] Scriptless setup: false
[2023-07-25 19:02:31.612] No shell environment set or found for current distro.
[2023-07-25 19:02:31.716] WSL daemon log file: 
[2023-07-25 19:02:31.719] Probing if server is already installed: if [ -d ~/.vscode-server/bin/74f6148eb9ea00507ec113ec51c489d6ffb4b771 ]; then printf 'install-found '; fi; if [ -f /etc/alpine-release ]; then printf alpine-; fi; uname -m
[2023-07-25 19:02:31.719] Run: C:\Windows\System32\wsl.exe -d NixOS -e sh -c if [ -d ~/.vscode-server/bin/74f6148eb9ea00507ec113ec51c489d6ffb4b771 ]; then printf 'install-found '; fi; if [ -f /etc/alpine-release ]; then printf alpine-; fi; uname -m
[2023-07-25 19:02:31.874] Unable to detect if server is already installed: Error: Failed to probe if server is already installed: code: Failed to probe if server is already installed: code: 127, /nix/store/zi11gd05qg6ryi81d3difs416anyz7lp-bash-interactive-5.2-p15/bin/sh: line 1: uname: command not found
[2023-07-25 19:02:31.874] , 
[2023-07-25 19:02:31.874] Run: C:\Windows\System32\wsl.exe -d NixOS sh -c '"$VSCODE_WSL_EXT_LOCATION/scripts/wslServer.sh" 74f6148eb9ea00507ec113ec51c489d6ffb4b771 stable code-server .vscode-server --host=127.0.0.1 --port=0 --connection-token=1243760339-1784116670-2445965475-3550068193 --use-host-proxy --without-browser-env-var --disable-websocket-compression --accept-server-license-terms --telemetry-level=all'
[2023-07-25 19:02:32.179] Setting up server environment: Looking for /home/david/.vscode-server/server-env-setup. Found, executing...
[2023-07-25 19:02:32.179] == '~/.vscode-server/server-env-setup' SCRIPT START ==
[2023-07-25 19:02:32.179] NIXOS_VERSION detected as ""
[2023-07-25 19:02:32.179] Got vscode directory : /mnt/c/Users/david/AppData/Local/Programs/Microsoft VS Code
[2023-07-25 19:02:32.179] If the directory is incorrect, you can hardcode it on the script.
[2023-07-25 19:02:32.179] Patching nodejs binaries...
[2023-07-25 19:02:32.179] == '~/.vscode-server/server-env-setup' SCRIPT END ==
[2023-07-25 19:02:32.180] /home/david/.vscode-server/server-env-setup: line 10: cut: command not found
[2023-07-25 19:02:32.180] /home/david/.vscode-server/server-env-setup: line 10: nixos-version: command not found
[2023-07-25 19:02:32.180] /home/david/.vscode-server/server-env-setup: line 17: dirname: command not found
[2023-07-25 19:02:32.180] /home/david/.vscode-server/server-env-setup: line 22: nix: command not found
[2023-07-25 19:02:32.309] WSL version:  NixOS
[2023-07-25 19:02:32.309] /mnt/c/Users/david/.vscode/extensions/ms-vscode-remote.remote-wsl-0.80.2/scripts/wslServer.sh: line 28: uname: command not found
[2023-07-25 19:02:32.310] /mnt/c/Users/david/.vscode/extensions/ms-vscode-remote.remote-wsl-0.80.2/scripts/wslServer.sh: line 32: dirname: command not found
[2023-07-25 19:02:32.310] /mnt/c/Users/david/.vscode/extensions/ms-vscode-remote.remote-wsl-0.80.2/scripts/wslServer.sh: line 32: /wslDownload.sh: No such file or directory
[2023-07-25 19:02:32.310] For help with startup problems, go to https://code.visualstudio.com/docs/remote/troubleshooting#_wsl-tips
[2023-07-25 19:03:01.247] Download in background is enabled
sonowz commented 1 year ago

Sorry for the late reply, I was busy IRL :(

It seems like the script was not run in NixOS shell, by looking at your log:

[2023-07-25 19:02:32.179] NIXOS_VERSION detected as ""
[2023-07-25 19:02:32.179] Got vscode directory : /mnt/c/Users/david/AppData/Local/Programs/Microsoft VS Code

where NIXOS_VERSION was not detected, and vscode directory is shown as your Windows directory rather than something like /home/david/.vscode-server. Maybe you should try changing WSL2 connection method, located in vscode preference as remote.WSL2.connectionMethod?

sylvorg commented 1 year ago

Two things: remote.WSL2.connectionMethod doesn't seem to be a valid setting anymore, and what connectionMethod should you use, if I may ask?

sonowz commented 1 year ago

I updated WSL extension and was able to reproduce the issue.

There's an issue opened in NixOS-WSL: https://github.com/nix-community/NixOS-WSL/issues/238

You may have noticed that with the latest update to the WSL remote extension (0.77.0), connecting to NixOS fails. This is because Micrsoft removed the option for setting the remote connection method.

remote.WSL2.connectionMethod setting was removed in 0.77.0, so you should downgrade WSL extension to 0.76.0. And setting connection method to localhost works for me. Hope it helps!

sylvorg commented 1 year ago

I'll try that; thanks!

sonowz commented 11 months ago

I stumbled upon this issue again after I updated NixOS-WSL version to 23.5.5.2. It turned out that actually uname, cut, nixos-version, dirname, nix commands were not available on shell path. So I added what was needed to PATH envvar, and after this commit(https://github.com/sonowz/vscode-remote-wsl-nixos/commit/b8f59ee7839d00a3123c84ebe682318c023377fe) it works. If you're using the latest NixOS-WSL release, please give it a try.

I'm supossing that the fix would solve the "command not found" error for the most cases, so I'll close this issue for now. If you find that the issue persists, please give me more details about your environment so that we can figure out the root cause.