Open samuela opened 5 months ago
Solution proposal: Scan for all binaries in the ~/.vscode-server
directory tree, and patch each of them if they have not been patched already.
The script
#! /usr/bin/env nix-shell
#! nix-shell -i sh -p file patchelf
libpath=$(nix eval --raw --impure --expr 'with import <nixpkgs> {}; lib.makeLibraryPath [ stdenv.cc.libc stdenv.cc.cc curl icu libunwind libuuid lttng-ust openssl zlib krb5 ]')
files_to_patch=$(find ~/.vscode-server -type f -name '*node' -exec file {} + | grep 'ELF' | grep 'executable' | grep 'interpreter /lib/' | awk -F: '{print $1}')
interpreter="$(cat $(nix eval --raw --impure --expr '(import <nixpkgs> {}).stdenv.cc.outPath')/nix-support/dynamic-linker)"
for elf in $files_to_patch; do
echo "patching $elf"
patchelf --set-interpreter "$interpreter" --add-rpath "$libpath" "$elf"
done
succeeds in making the executables runnable, but it's not enough to satisfy VSCode 1.88.0 which is apparently not fooled by my patchelf shenanigans.
Update: running
cp -r /home/skainswo/.vscode-server/cli/servers/Stable-5c3e652f63e798a5ac2f31ffd0d863669328dc4c.staging/ /home/skainswo/.vscode-server/cli/servers/Stable-5c3e652f63e798a5ac2f31ffd0d863669328dc4c
along with the above script works.
Altogether now, my script is
#! /usr/bin/env nix-shell
#! nix-shell -i sh -p file patchelf
# Move the <foo>.staging directories to <foo>. Necessary since VSCode 1.88.0.
find ~/.vscode-server/cli/servers -type d -name '*.staging' -exec bash -c 'for dir; do mv "$dir" "${dir%.staging}"; done' bash {} +
libpath=$(nix eval --raw --impure --expr 'with import <nixpkgs> {}; lib.makeLibraryPath [ stdenv.cc.libc stdenv.cc.cc curl icu libunwind libuuid lttng-ust openssl zlib krb5 ]')
files_to_patch=$(find ~/.vscode-server -type f -name '*node' -exec file {} + | grep 'ELF' | grep 'executable' | grep 'interpreter /lib/' | awk -F: '{print $1}')
interpreter="$(cat $(nix eval --raw --impure --expr '(import <nixpkgs> {}).stdenv.cc.outPath')/nix-support/dynamic-linker)"
for elf in "$files_to_patch"; do
echo "patching $elf"
patchelf --set-interpreter "$interpreter" --add-rpath "$libpath" "$elf"
done
@samuela, thanks for looking into this. I think I'm running into the same problem. I just booted my little nixos machine last night for the first time in a few months and cannot get Remote Explorer to connect. It seems to be stuck looping the "Downloading VS Code Server."
Unfortunately the above script doesn't seem to work. I get a patchelf: getting info about '': No such file or directory
error running from the home directory. Can I run it as a simple shell script or does it need to be wired into something? I'm a nixos novice so I might just be missing some context. Thanks.
It seems to be stuck looping the "Downloading VS Code Server."
Yes, this is exactly the behavior I was experiencing as well.
Can I run it as a simple shell script or does it need to be wired into something?
It should run fine just as a shell script... What version of VSCode are you using?
thanks for the script @samuela. I changed the files_to_patch=
line to files_to_patch=$(find ~/.vscode-server -type f -name '*node' -exec file {} + | grep 'ELF' | grep 'executable' | awk -F: '/interpreter \/lib64?\// {print $1}')
becuase /lib/
wasn’t giving me any results. @lucianthorr that might be your problem&fix too.
@n-hass That totally did it. Thanks!
One slight typo in the above. The last single quote got "auto-incorrected" to a ’
. It needs to be a '
With https://github.com/nix-community/nixos-vscode-server/pull/78 new binary paths are handled correctly. I've switched few nixos 23.11 machines to it, so far no problems.
I've upgraded my machine to use a version that I believe includes #78, but I'm still unable to connect on newer versions of VSCode. Downgrading VSCode to 1.86.2 works and I can connect as before.
Is there more that needs to be done?
The error is:
[14:47:35.362] [server] Error installing server: error checking server integrity: failed to run command "/home/msboba/.vscode-server/cli/servers/Stable-dc96b837cf6bb4af9cd736aa3af08cf8279f7685.staging/server/bin/code-server --version" (code 127): /home/msboba/.vscode-server/cli/servers/Stable-dc96b837cf6bb4af9cd736aa3af08cf8279f7685.staging/server/bin/code-server: line 12: /home/msboba/.vscode-server/cli/servers/Stable-dc96b837cf6bb4af9cd736aa3af08cf8279f7685.staging/server/node: cannot execute: required file not found
(note that these files actually exist on my machine when I SSH into it)
My configuration is:
services.vscode-server = {
enable = true;
installPath = "$HOME/.vscode-server";
};
and in my lockfile:
"vscode-server": {
"inputs": {
"flake-utils": "flake-utils_4",
"nixpkgs": "nixpkgs_3"
},
"locked": {
"lastModified": 1713958148,
"narHash": "sha256-8PDNi/dgoI2kyM7uSiU4eoLBqUKoA+3TXuz+VWmuCOc=",
"owner": "nix-community",
"repo": "nixos-vscode-server",
"rev": "fc900c16efc6a5ed972fb6be87df018bcf3035bc",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixos-vscode-server",
"type": "github"
}
}
I just upgraded to VSCode 1.88.0 and it has broken nixos-vscode-server by moving the installation path of binaries. Logs reveal that there is a failure to execute
/home/skainswo/.vscode-server/cli/servers/Stable-5c3e652f63e798a5ac2f31ffd0d863669328dc4c.staging/server/bin/code-server
, which contains:"$ROOT/node"
resolves to /home/skainswo/.vscode-server/cli/servers/Stable-5c3e652f63e798a5ac2f31ffd0d863669328dc4c.staging/server/node which differs from previous node installation locations AFAICT. This file is not patched:IIUC adjustments to the
installPath
andbin_dir
logic in https://github.com/nix-community/nixos-vscode-server/blob/master/pkgs/auto-fix-vscode-server.nix will be required.