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

vscode extension not starting on nixos #321

Closed
tengkuizdihar opened this issue Dec 21, 2024 · 6 comments · Fixed by #330
Closed

vscode extension not starting on nixos #321

tengkuizdihar opened this issue Dec 21, 2024 · 6 comments · Fixed by #330

Comments

@tengkuizdihar
Copy link

The extension is not running on nixos, because this OS doesn't play nicely with dynamically linked libraries from third parties. There's already harper-ls and harper-cli in nix package registry, is there a way for me to change the path of the language server in harper? Below is the log from the extension.

[Error - 8:44:21 AM] Client Harper: connection to server is erroring.
write EPIPE
Shutting down server.
[Error - 8:44:21 AM] Client Harper: connection to server is erroring.
write EPIPE
[Error - 8:44:21 AM] Stopping server failed
Error: Client is not running and can't be stopped. It's current state is: starting
	at td.shutdown (/{HOME}/.vscode-oss/extensions/elijah-potter.harper-0.12.0-linux-x64/build/extension.js:41:8468)
	at td.stop (/{HOME}/.vscode-oss/extensions/elijah-potter.harper-0.12.0-linux-x64/build/extension.js:41:8047)
	at td.stop (/{HOME}/.vscode-oss/extensions/elijah-potter.harper-0.12.0-linux-x64/build/extension.js:44:30480)
	at td.handleConnectionError (/{HOME}/.vscode-oss/extensions/elijah-potter.harper-0.12.0-linux-x64/build/extension.js:43:63)
	at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[Error - 8:44:21 AM] Server initialization failed.
  Message: write EPIPE
  Code: -32099 
[Error - 8:44:21 AM] Harper client: couldn't create connection to server.
  Message: write EPIPE
  Code: -32099 
[Info  - 8:44:21 AM] Connection to server got closed. Server will restart.
true
Could not start dynamically linked executable: /{HOME}/.vscode-oss/extensions/elijah-potter.harper-0.12.0-linux-x64/bin/harper-ls
NixOS cannot run dynamically linked executables intended for generic
linux environments out of the box. For more information, see:
https://nix.dev/permalink/stub-ld
[Error - 8:44:21 AM] Server process exited with code 127.
[Error - 8:44:21 AM] Server process exited with code 127.
[Error - 8:44:21 AM] Client Harper: connection to server is erroring.
Cannot call write after a stream was destroyed
[Error - 8:44:21 AM] Server initialization failed.
  Message: Cannot call write after a stream was destroyed
  Code: -32099 
[Error - 8:44:21 AM] Harper client: couldn't create connection to server.
  Message: Cannot call write after a stream was destroyed
  Code: -32099 
[Error - 8:44:21 AM] Restarting server failed
  Message: Cannot call write after a stream was destroyed
  Code: -32099 
[Info  - 8:44:21 AM] Connection to server got closed. Server will restart.
true
Could not start dynamically linked executable: /{HOME}/.vscode-oss/extensions/elijah-potter.harper-0.12.0-linux-x64/bin/harper-ls
NixOS cannot run dynamically linked executables intended for generic
linux environments out of the box. For more information, see:
https://nix.dev/permalink/stub-ld
[Error - 8:44:21 AM] Client Harper: connection to server is erroring.
write EPIPE
Shutting down server.
[Error - 8:44:21 AM] Client Harper: connection to server is erroring.
write EPIPE
[Error - 8:44:21 AM] Stopping server failed
Error: Client is not running and can't be stopped. It's current state is: starting
	at td.shutdown (/{HOME}/.vscode-oss/extensions/elijah-potter.harper-0.12.0-linux-x64/build/extension.js:41:8468)
	at td.stop (/{HOME}/.vscode-oss/extensions/elijah-potter.harper-0.12.0-linux-x64/build/extension.js:41:8047)
	at td.stop (/{HOME}/.vscode-oss/extensions/elijah-potter.harper-0.12.0-linux-x64/build/extension.js:44:30480)
	at td.handleConnectionError (/{HOME}/.vscode-oss/extensions/elijah-potter.harper-0.12.0-linux-x64/build/extension.js:43:63)
	at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[Error - 8:44:21 AM] Server initialization failed.
  Message: write EPIPE
  Code: -32099 
[Error - 8:44:21 AM] Harper client: couldn't create connection to server.
  Message: write EPIPE
  Code: -32099 
[Error - 8:44:21 AM] Restarting server failed
  Message: write EPIPE
  Code: -32099 
[Info  - 8:44:21 AM] Connection to server got closed. Server will restart.
true
Could not start dynamically linked executable: /{HOME}/.vscode-oss/extensions/elijah-potter.harper-0.12.0-linux-x64/bin/harper-ls
NixOS cannot run dynamically linked executables intended for generic
linux environments out of the box. For more information, see:
https://nix.dev/permalink/stub-ld
[Error - 8:44:21 AM] Server process exited with code 127.
[Error - 8:44:21 AM] Server process exited with code 127.
[Error - 8:44:21 AM] Client Harper: connection to server is erroring.
Cannot call write after a stream was destroyed
[Error - 8:44:21 AM] Server initialization failed.
  Message: Cannot call write after a stream was destroyed
  Code: -32099 
[Error - 8:44:21 AM] Harper client: couldn't create connection to server.
  Message: Cannot call write after a stream was destroyed
  Code: -32099 
[Error - 8:44:21 AM] Restarting server failed
  Message: Cannot call write after a stream was destroyed
  Code: -32099 
[Info  - 8:44:21 AM] Connection to server got closed. Server will restart.
true
Could not start dynamically linked executable: /{HOME}/.vscode-oss/extensions/elijah-potter.harper-0.12.0-linux-x64/bin/harper-ls
NixOS cannot run dynamically linked executables intended for generic
linux environments out of the box. For more information, see:
https://nix.dev/permalink/stub-ld
[Error - 8:44:21 AM] Client Harper: connection to server is erroring.
write EPIPE
Shutting down server.
[Error - 8:44:21 AM] Client Harper: connection to server is erroring.
write EPIPE
[Error - 8:44:21 AM] Stopping server failed
Error: Client is not running and can't be stopped. It's current state is: starting
	at td.shutdown (/{HOME}/.vscode-oss/extensions/elijah-potter.harper-0.12.0-linux-x64/build/extension.js:41:8468)
	at td.stop (/{HOME}/.vscode-oss/extensions/elijah-potter.harper-0.12.0-linux-x64/build/extension.js:41:8047)
	at td.stop (/{HOME}/.vscode-oss/extensions/elijah-potter.harper-0.12.0-linux-x64/build/extension.js:44:30480)
	at td.handleConnectionError (/{HOME}/.vscode-oss/extensions/elijah-potter.harper-0.12.0-linux-x64/build/extension.js:43:63)
	at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[Error - 8:44:21 AM] Server initialization failed.
  Message: write EPIPE
  Code: -32099 
[Error - 8:44:21 AM] Harper client: couldn't create connection to server.
  Message: write EPIPE
  Code: -32099 
[Error - 8:44:21 AM] Restarting server failed
  Message: write EPIPE
  Code: -32099 
[Error - 8:44:21 AM] The Harper server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information.
Could not start dynamically linked executable: /{HOME}/.vscode-oss/extensions/elijah-potter.harper-0.12.0-linux-x64/bin/harper-ls
NixOS cannot run dynamically linked executables intended for generic
linux environments out of the box. For more information, see:
https://nix.dev/permalink/stub-ld
[Error - 8:44:21 AM] Server process exited with code 127.
@mcecode
Copy link
Contributor

mcecode commented Dec 21, 2024

I can see three possible solutions to this, from easiest to hardest to do:

  1. As suggested, expose a setting that allows the user to point to whatever harper-ls binary they want to run. Though, this would kind of defeat the purpose of bundling harper-ls with the extension so we can track one-to-one that extension version x is running harper-ls version x.
  2. Detect if the OS running the extension is NixOS and use the globally available binary rather than the bundled binary. Though, I imagine if we go this route that we'd also have to do the same for other immutable distros in the future.
  3. Try to make harper-ls completely portable by compiling it with musl instead of glibc, since that's the only library that's dynamically linked AFAIK. Would this type of solution work for NixOS @tengkuizdihar?

What do you think @elijah-potter?

@tengkuizdihar
Copy link
Author

As suggested, expose a setting that allows the user to point to whatever harper-ls binary they want to run. Though, this would kind of defeat the purpose of bundling harper-ls with the extension so we can track one-to-one that extension version x is running harper-ls version x.

If memory serves, this is what most extension does even if they have an option to use a "bundled" binary in the extension. I can see how this would defeat the purpose of bundling the binary, but I instead think of it as adding another option. The default (to cater most os) imo is to still use the bundled binary.

Detect if the OS running the extension is NixOS and use the globally available binary rather than the bundled binary. Though, I imagine if we go this route that we'd also have to do the same for other immutable distros in the future.

IIRC rust analyzer does this, but I think it would put a burden on your side for maintaining each OS. The first option should suffice.

Try to make harper-ls completely portable by compiling it with musl instead of glibc, since that's the only library that's dynamically linked AFAIK. Would this type of solution work for NixOS @tengkuizdihar?

I think the binary found glibc, I ran this command on the bundled binary and got the libraries except for one, the libstdc++ one.

[notroot@nixos:~/.vscode-oss/extensions/elijah-potter.harper-0.12.0-linux-x64/bin]$ ldd ./harper-ls
	linux-vdso.so.1 (0x00007fff720fb000)
	libstdc++.so.6 => not found
	libgcc_s.so.1 => /nix/store/2y852kcvb7shrj8f3z8j22pa0iybcbgj-xgcc-13.2.0-libgcc/lib/libgcc_s.so.1 (0x00007fbcd20e9000)
	libpthread.so.0 => /nix/store/c10zhkbp6jmyh0xc5kd123ga8yy2p4hk-glibc-2.39-52/lib/libpthread.so.0 (0x00007fbcd20e4000)
	libm.so.6 => /nix/store/c10zhkbp6jmyh0xc5kd123ga8yy2p4hk-glibc-2.39-52/lib/libm.so.6 (0x00007fbcd2001000)
	libdl.so.2 => /nix/store/c10zhkbp6jmyh0xc5kd123ga8yy2p4hk-glibc-2.39-52/lib/libdl.so.2 (0x00007fbcd1ffc000)
	libc.so.6 => /nix/store/c10zhkbp6jmyh0xc5kd123ga8yy2p4hk-glibc-2.39-52/lib/libc.so.6 (0x00007fbcd0213000)
	/lib64/ld-linux-x86-64.so.2 => /nix/store/c10zhkbp6jmyh0xc5kd123ga8yy2p4hk-glibc-2.39-52/lib64/ld-linux-x86-64.so.2 (0x00007fbcd2110000)

@mcecode
Copy link
Contributor

mcecode commented Dec 21, 2024

I think the binary found glibc, I ran this command on the bundled binary and got the libraries except for one, the libstdc++ one.

Interesting. I thought any dynamically linked binary wouldn't be able to resolve its dependencies in NixOS because of how immutable distos work, but only the C++ standard library (libstdc++) is missing.

Anyway, I was probably overthinking this. I guess exposing a setting would suffice. I'll try to get a PR up soon.

@mcecode
Copy link
Contributor

mcecode commented Dec 28, 2024

Hi @tengkuizdihar, by the next release, you can set "harper-ls.path": "harper-ls" in your settings.json and it should just pick up the harper-ls you've globally installed in your PATH.

If you have some time and would like to give it a try now, you can try following the "Packaging and Installing the Extension" section of the Development Guide.

@tengkuizdihar
Copy link
Author

thank you @mcecode

@tengkuizdihar
Copy link
Author

It works! @mcecode

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