Skip to content

Instantly share code, notes, and snippets.

@ivan
Last active March 29, 2026 03:58
Show Gist options
  • Select an option

  • Save ivan/4728f8ef9af8db43cd2bd9194b687e9b to your computer and use it in GitHub Desktop.

Select an option

Save ivan/4728f8ef9af8db43cd2bd9194b687e9b to your computer and use it in GitHub Desktop.
Fix vscode server for NixOS
# Based on https://gist.github.com/sonowz/d70b03177c344f4bbbc674de5e5bb937
with import <nixpkgs> {};
let
pname = "fix-vscode-server-binaries";
script = pkgs.writeShellScriptBin pname ''
set -eu -o pipefail
SCRIPT_DIR="$(dirname -- "$(readlink -f -- "$0")")"
interpreter=$(patchelf --print-interpreter /run/current-system/sw/bin/sh)
libstdc=$(nix-build '<nixpkgs>' --no-out-link -A stdenv.cc.cc.lib)/lib
libssl=$(ldd /run/current-system/sw/bin/openssl | rg -m 1 -F libssl.so | rg -m 1 -o '/nix/store/[^ ]+')
for i in ~/.vscode-server/cli/servers/*/server/; do
ls -l "$i/node.orig" || mv -fT "$i/node" "$i/node.orig"
ln -sfT "$SCRIPT_DIR/node" "$i/node"
done
# Patch vsce-sign to run on NixOS.
# https://github.com/nix-community/nixos-vscode-server/commit/92ce71c3ba5a94f854e02d57b14af4997ab54ef0
for i in ~/.vscode-server/cli/servers/*/server/node_modules/@vscode/vsce-sign/bin/vsce-sign; do
patchelf --set-interpreter "$interpreter" "$i"
patchelf --add-needed "$libssl" "$i"
patchelf --set-rpath "$libstdc" "$i"
done
# Replace the vscode-downloaded ripgrep binary with our faster LTO build
for i in ~/.vscode-server/cli/servers/*/server/node_modules/@vscode/ripgrep/bin/rg; do
ln -sfT /run/current-system/sw/bin/rg "$i"
done
# Patch the C++ tools to run on NixOS.
for i in ~/.vscode-server/extensions/ms-vscode.*/bin/cpptools*; do
patchelf --set-interpreter "$interpreter" "$i"
done
# Patch the Oxc tools to run on NixOS.
for i in ~/.vscode-server/extensions/oxc.oxc-vscode-*/target/release/oxc_language_server; do
patchelf --set-interpreter "$interpreter" "$i"
done
'';
in
{}:
stdenv.mkDerivation rec {
name = pname;
nodePackage = nodejs_22;
src = ./.;
installPhase = ''
mkdir -p $out/bin
cp ${script}/bin/${pname} $out/bin/${pname}
cp ${nodePackage}/bin/node $out/bin/node
chmod +x $out/bin/${pname}
'';
buildInputs = [ script nodePackage ];
}
#!/bin/sh
set -eu -o pipefail -o verbose
cd ~/bin
nix-build fix-vscode-server-binaries.nix
./result/bin/fix-vscode-server-binaries
@Hoverbear

Copy link
Copy Markdown

@grahamc suggested:

This is great! I bet you could "simplify" the rpath bit to this:

patchelf --set-rpath "$(patchelf --print-rpath "$(which patchelf)")" "$i"

https://twitter.com/grhmc/status/1357425019580801026?s=20

@ivan

ivan commented Jun 13, 2021

Copy link
Copy Markdown
Author

My code no longer works (patchelf to take libstdc++.so.6 from node 16) and for vscode 1.57, I've started symlinking NixOS's node 14 binary. Thanks to samuela/nixos-fix-vscode-remote@f105e97 for the hint.

@ivan

ivan commented Oct 11, 2021

Copy link
Copy Markdown
Author

Updated the fix here to using nix-build to get node 14, based on https://gist.github.com/sonowz/d70b03177c344f4bbbc674de5e5bb937

@Enzime

Enzime commented Mar 14, 2022

Copy link
Copy Markdown

I've made a PR to fix this for those using the remote-ssh extension from Nixpkgs :) NixOS/nixpkgs#163797

@ivan

ivan commented Apr 9, 2022

Copy link
Copy Markdown
Author

Updated the fix here to use node 16.

Using node 14 with a vscode 1.66 client appears to work at first, but actually causes the node ... bootstrap-fork process to use > 100% CPU forever.

@ivan

ivan commented Sep 16, 2024

Copy link
Copy Markdown
Author

Updated again for the new ~/.vscode-server paths, and for node 20.

Note that vscode-remote immediately tries to run the server it downloads and deletes the directory if it fails (microsoft/vscode-remote-release#9855), so you need to race vscode-remote several times to successfully patch the server.

@ivan

ivan commented Mar 29, 2026

Copy link
Copy Markdown
Author

Updated for vscode 1.113.0.

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