Skip to content

Instantly share code, notes, and snippets.

@swdunlop
Last active May 7, 2021 18:50
Show Gist options
  • Save swdunlop/3fed235d6c6e5a58fc2f39291f5936f9 to your computer and use it in GitHub Desktop.
Save swdunlop/3fed235d6c6e5a58fc2f39291f5936f9 to your computer and use it in GitHub Desktop.
A script to fix Visual Code Remoting via SSH to NixOS after the April 2021 update

NixOS does not normally install libraries in a FHS layout, which means that binaries compiled for other Linux platforms typically will not work. Visual Studio Code's Remote SSH extension transfers a NodeJS binary and a binary library built by Microsoft that must be patched to be used on NixOS.

Prior to April 2021, this could simply be done by replacing .vscode-server/bin/*/node with nodejs-12_x; after April 2021, there is also a library module that is not compatible with nodejs-12_x. Therefore, it is necessary to patch these two ELF files.

What happens if you just replace nodejs (the pre-April solution from nixos.wiki)

The following will occur when you try to open a terminal

The terminal process failed to launch: A native exception occurred during launch (The module '.../.vscode-
server/bin/cfa2e218100323074ac1948c885448fdf4de2a7f/node_modules/node-pty/build/Release/pty.node' was compiled against a
different Node.js version using NODE_MODULE_VERSION 83. This version of Node.js requires NODE_MODULE_VERSION 72. Please try
re-compiling or re-installing the module (for instance, using `npm rebuild` or `npm install`).).

Why does this happen?

No clue. I am not a NodeJS developer, nor do I work for Microsoft.

#!/usr/bin/env bash
interpreter=$(nix eval --raw '((import <nixpkgs> { }).stdenv.glibc)')/lib/ld-linux-x86-64.so.2
libstdcxx=$(nix eval --raw '((import <nixpkgs> { }).stdenv.cc.cc.lib)')/lib/libstdc++.so.6
for dir in ~/.vscode-server/bin/*; do
cd $dir
patchelf \
--set-interpreter $interpreter \
--replace-needed libstdc++.so.6 $libstdcxx \
node
patchelf \
--replace-needed libstdc++.so.6 $libstdcxx \
node_modules/node-pty/build/Release/pty.node
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment