NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.83k stars 13.92k forks source link

VSCode: cannot open terminal (posix_spawn failed: Permission denied) #214617

Open wmertens opened 1 year ago

wmertens commented 1 year ago

In vscode 1.75.0, cannot open a terminal.

The same issue happened in Gentoo, see https://bugs.gentoo.org/show_bug.cgi?id=893208 for how they solved it

Notify maintainers

@TethysSvensson

utybo commented 1 year ago

Here's an expression that seems to work for me in the mean time.

vscode.overrideAttrs (finalAttrs: previousAttrs: {
  installPhase = previousAttrs.installPhase + ''
    chmod +x $out/lib/vscode/resources/app/node_modules/node-pty/build/Release/spawn-helper
    chmod +x $out/lib/vscode/resources/app/node_modules.asar.unpacked/node-pty/build/Release/spawn-helper
  '';
})

(note: this is a horrible way to patch nix packages and you shouldn't use this, I don't know what i'm doing)

Note that I've added exec permissions to both node_modules and ndoe_modules.asar.unpacked variants, but it seems that the asar one already has those.

$ ls -l $(find /nix/store/niz86m85pdkzhwark0kvms3a693d22fb-vscode-1.75.0 -name "spawn-helper")         
-r-xr-xr-x 1 root root 39584  1 janv.  1970 /nix/store/niz86m85pdkzhwark0kvms3a693d22fb-vscode-1.75.0/lib/vscode/resources/app/node_modules.asar.unpacked/node-pty/build/Release/spawn-helper
-r--r--r-- 1 root root 39584  1 janv.  1970 /nix/store/niz86m85pdkzhwark0kvms3a693d22fb-vscode-1.75.0/lib/vscode/resources/app/node_modules/node-pty/build/Release/spawn-helper
bobby285271 commented 1 year ago

214666

nimakalantar commented 1 year ago

This issue is also present on code-server.

maddyblue commented 1 year ago

I think there's a variant of this issue also present when using vscode remote dev. From a mac client (have also repro'd from a Windows client), I'm connecting to a nixos remote host. Nixos doesn't have the vscode package installed (so the above patch doesn't do anything). But I then run:

fd spawn-helper ~/.vscode-server | xargs chmod +x

To find and fix perms for the spawn-helper file. Verifying that:

~/scratch/nix@work (main)$ fd spawn-helper ~/.vscode*
/home/mjibson/.vscode-server/bin/e2816fe719a4026ffa1ee0189dc89bdfdbafb164/node_modules/node-pty/build/Release/spawn-helper
~/scratch/nix@work (main)$ ls -l /home/mjibson/.vscode-server/bin/e2816fe719a4026ffa1ee0189dc89bdfdbafb164/node_modules/node-pty/build/Release/spawn-helper
-rwxr-xr-x 1 mjibson users 13688 Feb  1 07:57 /home/mjibson/.vscode-server/bin/e2816fe719a4026ffa1ee0189dc89bdfdbafb164/node_modules/node-pty/build/Release/spawn-helper

so it's definitely setting +x on the only instance of spawn-helper in the vscode remote binaries. After all this, there's no change from the reported behavior in this issue. Starting a terminal closes the pane immediately, and the Window output pane still contains

2023-02-06 14:27:26.663 [warning] The terminal process failed to launch: A native exception occurred during launch (posix_spawn failed: No such file or directory).
maddyblue commented 1 year ago

One workaround: run a 1.74.X client.

NobbZ commented 1 year ago

@mjibson We probably have a different problem here…

The same problem that also requires us to swap out the prebuilt nodejs before being able to use the remote server:

$ ./bin/e2816fe719a4026ffa1ee0189dc89bdfdbafb164/node_modules/node-pty/build/Release/spawn-helper: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=2130faeb2d0213c2a7ed0072726176ab45e17405, not stripped

Perhaps we should ask the VScode-nixos-service integrators to provide a fix for that?

@msteen and @mudrii are 2 maintainers I can find in my configs history. Not sure how many more variants of the script/service do exist.

maddyblue commented 1 year ago

(Yes, I also had to run that script to patch the node path, but I did not note it above.)

yangm97 commented 1 year ago

Not sure how many more variants of the script/service do exist.

Many. I, for instance, am/was(?) using jmatsushita/nixos-vscode-server

yangm97 commented 1 year ago

BTW why is the merged module system wide and single user? shouldn't it be refactored to work per user, just like the many community wrappers?

alissa-tung commented 1 year ago

Here's an expression that seems to work for me in the mean time.

vscode.overrideAttrs (finalAttrs: previousAttrs: {
  installPhase = previousAttrs.installPhase + ''
    chmod +x $out/lib/vscode/resources/app/node_modules/node-pty/build/Release/spawn-helper
    chmod +x $out/lib/vscode/resources/app/node_modules.asar.unpacked/node-pty/build/Release/spawn-helper
  '';
})

(note: this is a horrible way to patch nix packages and you shouldn't use this, I don't know what i'm doing)

Note that I've added exec permissions to both node_modules and ndoe_modules.asar.unpacked variants, but it seems that the asar one already has those.

$ ls -l $(find /nix/store/niz86m85pdkzhwark0kvms3a693d22fb-vscode-1.75.0 -name "spawn-helper")         
-r-xr-xr-x 1 root root 39584  1 janv.  1970 /nix/store/niz86m85pdkzhwark0kvms3a693d22fb-vscode-1.75.0/lib/vscode/resources/app/node_modules.asar.unpacked/node-pty/build/Release/spawn-helper
-r--r--r-- 1 root root 39584  1 janv.  1970 /nix/store/niz86m85pdkzhwark0kvms3a693d22fb-vscode-1.75.0/lib/vscode/resources/app/node_modules/node-pty/build/Release/spawn-helper

In addition, as for VSCode variant:

pkgs.vscode-with-extensions.override {
  vscode = pkgs.vscode.overrideAttrs (_: prev: {
    postPatch =
      prev.postPatch
      + "chmod +x resources/app/node_modules/node-pty/build/Release/spawn-helper";
  });
  vscodeExtensions =
Princemachiavelli commented 1 year ago

In my version of the remote vscode wrapper, I was able to fix this issue by adding a symlink to the NixOS packages's spawn_helper binary. Lines I added in https://github.com/Princemachiavelli/nixos-vscode-ssh-fix

vscodeSpawnHelper = "${pkgs.vscode}/lib/vscode/resources/app/node_modules.asar.unpacked/node-pty/build/Release/spawn-helper";
find "$bin_dir" -name 'spawn-helper' -exec ln -sfT ${vscodeSpawnHelper} {} \;

Of course you will need pkgs.vscode to be version >=1.75 (only in nixos-unstable currently) for it to have the patched spawn_helper binary.