Skip to content
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

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

Closed
GGG-KILLER opened this issue Feb 5, 2023 · 10 comments · Fixed by #7152
Closed

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

GGG-KILLER opened this issue Feb 5, 2023 · 10 comments · Fixed by #7152

Comments

@GGG-KILLER
Copy link

GGG-KILLER commented Feb 5, 2023

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 GGG-KILLER changed the title Extension no longer loads in NixOS Extension no longer loads in NixOS (uname in non-standard location) Feb 5, 2023
@viperML
Copy link

viperML commented May 14, 2023

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

@philipwilk
Copy link

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.

@headblockhead
Copy link

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].

@viperML
Copy link

viperML commented May 20, 2023

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

@philipwilk
Copy link

philipwilk commented May 20, 2023

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

@headblockhead
Copy link

Yes

@GGG-KILLER
Copy link
Author

GGG-KILLER commented May 23, 2023

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.

@KiruyaMomochi
Copy link

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:

const architecture = (await util.execChildProcess('uname -m', __dirname)).trim();

The execChildProcess function is defined at src/common.ts:

export async function execChildProcess(
command: string,
workingDirectory: string = getExtensionPath(),
env: NodeJS.ProcessEnv = {}
): Promise<string> {
return new Promise<string>((resolve, reject) => {
cp.exec(command, { cwd: workingDirectory, maxBuffer: 500 * 1024, env: env }, (error, stdout, stderr) => {

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 #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.

@acelinkio
Copy link

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!

@Mr-MooMoo
Copy link

Mr-MooMoo commented Apr 28, 2024

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)`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants