Skip to content

Instantly share code, notes, and snippets.

@ivan
Last active May 29, 2022 00:54
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ivan/4728f8ef9af8db43cd2bd9194b687e9b to your computer and use it in GitHub Desktop.
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)
for i in ~/.vscode-server/bin/*; do
ln -sfT "$SCRIPT_DIR/node" "$i/node"
done
# Replace the vscode-downloaded ripgrep binary with our faster LTO build
for i in ~/.vscode-server/bin/*/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
'';
in
{}:
stdenv.mkDerivation rec {
name = pname;
nodePackage = nodejs-16_x;
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

@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
Copy link
Author

ivan commented Jun 13, 2021

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
Copy link
Author

ivan commented Oct 11, 2021

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

@Enzime
Copy link

Enzime commented Mar 14, 2022

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

@ivan
Copy link
Author

ivan commented Apr 9, 2022

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.

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