sonowz / vscode-remote-wsl-nixos

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

wget not found even though wget is installed #7

Closed Cody119 closed 7 months ago

Cody119 commented 10 months ago

This might be realted to #6 but not 100% sure. Still a bit new to NixOS so forgive me if I missed anything obvious.

Installed wget as instructed but im getting an error when I try to connect saying that wget is not installed:

[2024-01-04 06:14:15.463] Extension version: 0.81.8
[2024-01-04 06:14:15.464] L10N bundle: undefined
[2024-01-04 06:14:15.477] authorityHierarchy: wsl+NixOS
[2024-01-04 06:14:15.477] WSL extension activating for a local WSL instance
[2024-01-04 06:14:15.488] Resolving wsl+NixOS, resolveAttempt: 1
[2024-01-04 06:14:15.489] WSL feature installed: true (dll path)
[2024-01-04 06:14:15.490] NodeExecServer run: C:\WINDOWS\System32\wsl.exe --list --verbose
[2024-01-04 06:14:15.652] 5 distros found
[2024-01-04 06:14:15.653] Starting VS Code Server inside WSL (wsl2)
[2024-01-04 06:14:15.653] Windows build: 19045. Multi distro support: available. WSL path support: enabled
[2024-01-04 06:14:15.653] Scriptless setup: false
[2024-01-04 06:14:15.653] No shell environment set or found for current distro.
[2024-01-04 06:14:15.870] WSL daemon log file: 
[2024-01-04 06:14:15.873] Probing if server is already installed: if [ -d ~/.vscode-server/bin/0ee08df0cf4527e40edc9aa28f4b5bd38bbff2b2 ]; then printf 'install-found '; fi; if [ -f /etc/alpine-release ]; then printf alpine-; fi; uname -m
[2024-01-04 06:14:15.873] NodeExecServer run: C:\WINDOWS\System32\wsl.exe -d NixOS -e sh -c if [ -d ~/.vscode-server/bin/0ee08df0cf4527e40edc9aa28f4b5bd38bbff2b2 ]; then printf 'install-found '; fi; if [ -f /etc/alpine-release ]; then printf alpine-; fi; uname -m
[2024-01-04 06:14:16.203] 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/x88ivkf7rmrhd5x3cvyv5vh3zqqdnhsk-bash-interactive-5.2-p15/bin/sh: line 1: uname: command not found
[2024-01-04 06:14:16.203] , 
[2024-01-04 06:14:16.204] NodeExecServer run: C:\WINDOWS\System32\wsl.exe -d NixOS sh -c '"$VSCODE_WSL_EXT_LOCATION/scripts/wslServer.sh" 0ee08df0cf4527e40edc9aa28f4b5bd38bbff2b2 stable code-server .vscode-server --host=127.0.0.1 --port=0 --connection-token=2466978617-315245953-626045778-2323571674 --use-host-proxy --without-browser-env-var --disable-websocket-compression --accept-server-license-terms --telemetry-level=all'
[2024-01-04 06:14:16.508] Setting up server environment: Looking for /home/nixos/.vscode-server/server-env-setup. Found, executing...
[2024-01-04 06:14:16.508] == '~/.vscode-server/server-env-setup' SCRIPT START ==
[2024-01-04 06:14:16.508] NIXOS_VERSION detected as "23.11"
[2024-01-04 06:14:16.808] Got vscode directory : /home/nixos/.vscode-server
[2024-01-04 06:14:16.808] If the directory is incorrect, you can hardcode it on the script.
[2024-01-04 06:14:16.808] Patching nodejs binaries...
[2024-01-04 06:14:18.612] patchelf: getting info about '/home/nixos/.vscode-server/bin/*/node_modules/node-pty/build/Release/spawn-helper': No such file or directory
[2024-01-04 06:14:19.513] == '~/.vscode-server/server-env-setup' SCRIPT END ==
[2024-01-04 06:14:19.513] WSL version: 5.15.133.1-microsoft-standard-WSL2 NixOS
[2024-01-04 06:14:19.513] patchelf: getting info about '/home/nixos/.vscode-server/bin/*/node': No such file or directory
[2024-01-04 06:14:19.813] Updating VS Code Server to version 0ee08df0cf4527e40edc9aa28f4b5bd38bbff2b2
[2024-01-04 06:14:19.813] Removing previous installation...
[2024-01-04 06:14:20.109] ERROR: Failed to download the VS Code server. 'wget' not installed.
[2024-01-04 06:14:20.109] Please install wget:
[2024-01-04 06:14:20.109] Debian/Ubuntu: sudo apt-get install wget
[2024-01-04 06:14:20.109] For help with startup problems, go to https://code.visualstudio.com/docs/remote/troubleshooting#_wsl-tips
[2024-01-04 06:14:23.039] Download in background is enabled

wget installation:

[nixos@nixos:~]$ wget --version
GNU Wget 1.21.4 built on linux-gnu.

...

[nixos@nixos:~]$ nix profile list

...

Index:              2
Flake attribute:    legacyPackages.x86_64-linux.wget
Original flake URL: flake:nixpkgs
Locked flake URL:   github:NixOS/nixpkgs/d44d59d2b5bd694cd9d996fd8c51d03e3e9ba7f7
Store paths:        /nix/store/xflxgibbr4kabs1h4mcpvv03j1i36n97-wget-1.21.4

system info:

[nixos@nixos:~]$ nix-info -m
 - system: `"x86_64-linux"`
 - host os: `Linux 5.15.133.1-microsoft-standard-WSL2, NixOS, 23.11 (Tapir), 23.11.2391.9dd7699928e2`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.1`
 - channels(root): `"nixos-23.11, nixos-wsl"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

I was able to get everything working by running code . directly into the NixOS terminal as suggested by the vscode troubleshooting docs, but since that isn't mentioned anywhere in the readme I wanted to see if I was missing anything.

I did note that some of the earlier logs suggested that vscode was running shell commands using wsl -d NixOS -e sh "<command>". When I try to access wget through this method I get a "command not found" error. I assume using "sh" directly like this skips setting up PATH properly in Nix. Im not sure how vscode calls wget for the server install so this may be unrelated.

p.s. other than this minor issue, script works great! Thanks for sharing!

sonowz commented 10 months ago

I did note that some of the earlier logs suggested that vscode was running shell commands using wsl -d NixOS -e sh "".

Yes you are right and I'm supposing that the command is not executed as user nixos.

Instead of adding wget into nix profile, can you try adding it to system path by adding this to configuration.nix and rebuild the OS?

environment.systemPackages = with pkgs; [
  wget
];
Cody119 commented 9 months ago

Thansk for the reply!

Instead of adding wget into nix profile, can you try adding it to system path by adding this to configuration.nix and rebuild the OS?

Still wasn't able to access wget from wsl -d NixOS -e sh after doing this.

After messing around a bit, I was able to modify NixOS-WSL to get wget installed in the sh enviroment with the following diff:

diff --git a/modules/systemd/native/default.nix b/modules/systemd/native/default.nix
index f641580..ae0afc6 100644
--- a/modules/systemd/native/default.nix
+++ b/modules/systemd/native/default.nix
@@ -7,7 +7,7 @@ with lib; {
       nativeUtils = pkgs.callPackage ../../../utils { };

       bashWrapper = pkgs.writeShellScriptBin "sh" ''
-        export PATH="$PATH:${lib.makeBinPath [ pkgs.systemd pkgs.gnugrep ]}"
+        export PATH="$PATH:${lib.makeBinPath [ pkgs.systemd pkgs.gnugrep pkgs.wget ]}"
         exec ${pkgs.bashInteractive}/bin/sh "$@"
       '';
     in

This seems to have fixed it, although obviosuly I had to modify NixOS-WSL which is a bit of a pain.

Do you think this is related to a recent update to the way vs code is installing the sever? Did it used to use the WSL default shell for each distor instead of directly using sh? Just confused as to why this is suddenly an issue.

sonowz commented 9 months ago

Do you think this is related to a recent update to the way vs code is installing the sever?

Could you give details about what has been changed with vscode?

I updated my environment and my vscode can download the server with any problem. (I updated vscode, WSL extension, and NixOS-WSL)

Strangely, the command you provided are not working for me as well:

>wsl -d NixOS -e sh "wget"
/nix/store/x88ivkf7rmrhd5x3cvyv5vh3zqqdnhsk-bash-interactive-5.2-p15/bin/sh: wget: No such file or directory
sonowz commented 7 months ago

I think I figured out what's going on here.

  1. The sh used in the recent version (2311.5.3) of NixOS-WSL is kind of meh. It even doesn't have ls command in its path:

    >wsl -d NixOS sh -c ls
    /nix/store/x88ivkf7rmrhd5x3cvyv5vh3zqqdnhsk-bash-interactive-5.2-p15/bin/sh: line 1: ls: command not found
  2. However the script should work because I modified PATH envvar so that the NixOS system packages (environment.systemPackages) should be available in the sh: https://github.com/sonowz/vscode-remote-wsl-nixos/blob/b8f59ee7839d00a3123c84ebe682318c023377fe/server-env-setup#L8

Thus, when wget is missing, you can put wget in system packages (as I did) or systemd derivation (as you did above). Either should work.

Do you think this is related to a recent update to the way vs code is installing the sever?

In other words, I think it has nothing to do with the recent update and the cause is that wget was not available in your system. I'm closing this issue, and feel free to reopen it when something doesn't work :)

Cody119 commented 7 months ago

Hey thanks for following up. Sorry for disapearing, the whole thing completely fell out of my mind for a while haha.

Thus, when wget is missing, you can put wget in system packages (as I did) or systemd derivation (as you did above). Either should work.

I am pretty sure I tried putting it in system package with no luck, but if I get a chance ill give it another shoot. What your saying makes sense so im inclinded to believe I just made a mistake when doing it.