vscode-csharp icon indicating copy to clipboard operation
vscode-csharp copied to clipboard

Extension no longer loads in NixOS (uname in non-standard location)

Open GGG-KILLER opened this issue 2 years ago • 10 comments

Environment data

dotnet --info output:

.NET SDK:
 Version:   7.0.102
 Commit:    4bbdd14480

Runtime Environment:
 OS Name:     nixos
 OS Version:  23.05
 OS Platform: Linux
 RID:         linux-x64
 Base Path:   /nix/store/b5sc5y8f64bxl7bw835ayc4hnnndmhrx-dotnet-sdk-7.0.102/sdk/7.0.102/

Host:
  Version:      7.0.2
  Architecture: x64
  Commit:       d037e070eb

.NET SDKs installed:
  3.1.426 [/nix/store/q2y79sgadi9sszfh86k7hs5dvr09blpn-dotnet-core-combined/sdk]
  6.0.405 [/nix/store/q2y79sgadi9sszfh86k7hs5dvr09blpn-dotnet-core-combined/sdk]
  7.0.102 [/nix/store/q2y79sgadi9sszfh86k7hs5dvr09blpn-dotnet-core-combined/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.32 [/nix/store/q2y79sgadi9sszfh86k7hs5dvr09blpn-dotnet-core-combined/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.13 [/nix/store/q2y79sgadi9sszfh86k7hs5dvr09blpn-dotnet-core-combined/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.2 [/nix/store/q2y79sgadi9sszfh86k7hs5dvr09blpn-dotnet-core-combined/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.32 [/nix/store/q2y79sgadi9sszfh86k7hs5dvr09blpn-dotnet-core-combined/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.13 [/nix/store/q2y79sgadi9sszfh86k7hs5dvr09blpn-dotnet-core-combined/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.2 [/nix/store/q2y79sgadi9sszfh86k7hs5dvr09blpn-dotnet-core-combined/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  DOTNET_ROOT       [/nix/store/q2y79sgadi9sszfh86k7hs5dvr09blpn-dotnet-core-combined]

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

VS Code version: 1.75.0 C# Extension version: 1.25.4 (but happens sinde v1.25.1-beta2 when #4738 got merged)

OmniSharp log

2023-02-05 16:09:02.874 [error] Activating extension ms-dotnettools.csharp failed due to an error:
2023-02-05 16:09:02.874 [error] Error: Error: Command failed: uname -m
/bin/sh: line 1: uname: command not found


/bin/sh: line 1: uname: command not found

	at /nix/store/dq5cgsfmh9r491qwaiwi5mmln533gbfv-vscode-extension-ms-dotnettools-csharp-1.25.4/share/vscode/extensions/ms-dotnettools.csharp/dist/extension.js:2:763831
	at ChildProcess.exithandler (node:child_process:415:5)
	at ChildProcess.emit (node:events:526:28)
	at maybeClose (node:internal/child_process:1092:16)
	at Socket.<anonymous> (node:internal/child_process:451:11)
	at Socket.emit (node:events:526:28)
	at Pipe.<anonymous> (node:net:687:12)

Steps to reproduce

  1. Open VSCode with v1.25.4
  2. Open Extension Host output
  3. See error

Expected behavior

Extension opens and works.

Actual behavior

Error when invoking uname -m as we no longer inherit the process' env vars.

Additional context

In NixOS, uname is not located in neither /bin nor /usr/bin (which is what child_process checks by default if env.PATH is not specified), so the call to invoke uname should include the process' PATH to be able to find it.

In my system it's located at /run/current-system/sw/bin/uname (which is a symlink that resolves to /nix/store/jynqcrh9yxh59w3sckkzmsz9n4r4iv0r-coreutils-full-9.1/bin/uname but that could change at any moment so the most reliable method to find it to have the process' PATH).

This was introduced in #4738 which sends in an empty object to child_process (and that makes in no longer inherit the env vars from process.env).

GGG-KILLER avatar Feb 05 '23 19:02 GGG-KILLER

Also ran into this. Altough setting up some symlinks results in the same failure:

$ file {,/usr}/bin/uname
/bin/uname:     symbolic link to /run/current-system/sw/bin/uname
/usr/bin/uname: symbolic link to /run/current-system/sw/bin/uname

viperML avatar May 14 '23 14:05 viperML

Although I can't see any issue relating to uname on my side, this extension just doesnt work at all for me after v1.25.0, and doesn't appear to load or anything in vscode at all - no line completion/linting , and the c# and omnisharp log just dont exist in the output window. If i try to manually try to run an omnisharp command, such as select project, it says command o.pickProjectAndStart not found, and same goes for running dotnet commands such as .net generate assets and debug: command dotnet.generateAssets not found - as if these are simply not in the environment, but I can use dotnet from the vscode terminal to run code just fine.

I'm using direnv to create my dotnet dev environment from a flake, if the issue is really stripping the envvars from process, that would mean that direnv is having no effect at all on the extension after this version - so gets confused by nix. I tried running vscode-fhs, which does some naughty symlinking of directories, inside a shell created using nix develop using the same dotnet flake, and the latest version of the extension functions properly, with linting etc. None of my other extensions have a problem using a direnv environment, so it's definitely an extension issue, if everything could just use the envvars as it should be, it would work splendid.

philipwilk avatar May 20 '23 01:05 philipwilk

Hello! I am also encountering this issue, and my solution so far has been to downgrade to v1.24.4, however this shouldn't be the accepted solution.

Although I can't see any issue relating to uname on my side

For me, this message appeared in [Help > Toggle Developer Tools].

headblockhead avatar May 20 '23 09:05 headblockhead

command not found is also related to dynamically-linked ELFs not finding libraries (not the binary itself not being found)

viperML avatar May 20 '23 09:05 viperML

Hello! I am also encountering this issue, and my solution so far has been to downgrade to v1.24.4, however this shouldn't be the accepted solution.

Although I can't see any issue relating to uname on my side

For me, this message appeared in [Help > Toggle Developer Tools].

Is this what you mean? image

philipwilk avatar May 20 '23 12:05 philipwilk

Yes

headblockhead avatar May 20 '23 12:05 headblockhead

I have implemented a fix for this in the nixpkgs package for this extension, but it'd be nice if this was fixed to check $PATH upstream.

GGG-KILLER avatar May 23 '23 13:05 GGG-KILLER

I just came across this issue when developing my F# project remotely on a NixOS machine.

util.execChildProcess throws an error in src/shared/platform.ts: https://github.com/dotnet/vscode-csharp/blob/1755b7bc3c1f4b9853f4bc34c049987ca19ab897/src/shared/platform.ts#L176

The execChildProcess function is defined at src/common.ts: https://github.com/dotnet/vscode-csharp/blob/1755b7bc3c1f4b9853f4bc34c049987ca19ab897/src/common.ts#L59-L65

Since we don't provide env in platform.ts, child_process.exec will be called with option { env: {} }. In this scenario the search path will be [/usr/bin:/bin](https://nodejs.org/api/child_process.html#child_processexeccommand-options-callback:~:text=path%20search%20of-,/usr/bin%3A/bin,-(see%20your%20operating). When env option is not provided explicitly, it will be process.env.

However on NixOS, the /usr/bin only contains env, and /bin only contains sh. The uname binary is instead located at /run/current-system/sw/bin/uname instead. Therefore we cannot find uname on NixOS.

The env parameter in execChildProcess function is added from commit https://github.com/dotnet/vscode-csharp/pull/4738. It says Implement the "dotNetCliPaths" option to support custom .NET SDK locations. However, I'm still confused why we use {} instead of process.env as the default value of env.

KiruyaMomochi avatar Nov 16 '23 12:11 KiruyaMomochi

I am facing this issue using nixos on WSL. The following configuration file took care most WSL related errors.
.vscode-server/server-env-setup

PATH=$PATH:/run/current-system/sw/bin/

However this error is entirely extension related. @jkoritzinsky could you review @KiruyaMomochi''s comments above about why env is defaulted to empty. Right now the only workaround is to modify the extension after installation. Thanks!

acelinkio avatar Mar 17 '24 21:03 acelinkio

Still seems to be a problem (NixOS, VsCode 1.881. , c# Extension 2.23.15); Error is still:

`2024-04-28 21:44:02.365 [error] Activating extension ms-dotnettools.csharp failed due to an error: 2024-04-28 21:44:02.365 [error] Error: Error: Command failed: uname -m /bin/sh: line 1: uname: command not found /bin/sh: line 1: uname: command not found

at /home/mo/.vscode/extensions/ms-dotnettools.csharp-2.23.15-linux-x64/dist/extension.js:2:1147378
at ChildProcess.exithandler (node:child_process:431:5)
at ChildProcess.emit (node:events:517:28)
at maybeClose (node:internal/child_process:1098:16)
at Socket.<anonymous> (node:internal/child_process:450:11)
at Socket.emit (node:events:517:28)
at Pipe.<anonymous> (node:net:350:12)`

Mr-MooMoo avatar Apr 28 '24 19:04 Mr-MooMoo