vscode-remote-ssh: Run patchelf on included Node

This commit is contained in:
Michael Hoang 2023-05-25 23:53:14 +10:00
parent 3e9a51a78b
commit 011df7a76b
2 changed files with 36 additions and 42 deletions

View File

@ -14,7 +14,7 @@ import ./make-test-python.nix ({ lib, ... }@args: let
# Every VS Code server build corresponds to a specific commit of VS Code, so we # Every VS Code server build corresponds to a specific commit of VS Code, so we
# want this to match the commit of VS Code in Nixpkgs. # want this to match the commit of VS Code in Nixpkgs.
# e.g. git rev-parse 1.77.0 # e.g. git rev-parse 1.77.0
rev = "7f329fe6c66b0f86ae1574c2911b681ad5a45d63"; rev = "b3e4e68a0bc097f0ae7907b217c1119af9e03435";
shortRev = builtins.substring 0 8 rev; shortRev = builtins.substring 0 8 rev;
# Our tests run without networking so the remote-ssh extension will always fail to # Our tests run without networking so the remote-ssh extension will always fail to
@ -24,7 +24,7 @@ import ./make-test-python.nix ({ lib, ... }@args: let
src = pkgs.fetchurl { src = pkgs.fetchurl {
name = "vscode-server-${shortRev}.tar.gz"; name = "vscode-server-${shortRev}.tar.gz";
url = "https://update.code.visualstudio.com/commit:${rev}/server-linux-x64/stable"; url = "https://update.code.visualstudio.com/commit:${rev}/server-linux-x64/stable";
sha256 = "11g234lwl3jn5q3637n9sxz5ghhzqvq137lk42vl2nbb57hgyqgq"; sha256 = "1gpsxlv4p3v3kh7b7b2i1lvm5g30xrq1vb7csqwhs4zjlbwfhdb2";
}; };
}; };
in { in {
@ -39,7 +39,7 @@ in {
networking.interfaces.eth1.ipv4.addresses = [ { address = serverAddress; prefixLength = 24; } ]; networking.interfaces.eth1.ipv4.addresses = [ { address = serverAddress; prefixLength = 24; } ];
services.openssh.enable = true; services.openssh.enable = true;
users.users.root.openssh.authorizedKeys.keys = [ snakeOilPublicKey ]; users.users.root.openssh.authorizedKeys.keys = [ snakeOilPublicKey ];
virtualisation.additionalPaths = [ pkgs.nodejs-14_x pkgs.nodejs-16_x ]; virtualisation.additionalPaths = with pkgs; [ patchelf bintools stdenv.cc.cc.lib ];
}; };
client = { ... }: { client = { ... }: {
imports = [ ./common/x11.nix ./common/user-account.nix ]; imports = [ ./common/x11.nix ./common/user-account.nix ];
@ -98,6 +98,8 @@ in {
# Close the error dialog # Close the error dialog
client.send_key("esc") client.send_key("esc")
# Don't send Ctrl-q too quickly otherwise it might not get sent to VS Code
client.sleep(1)
client.send_key("ctrl-q") client.send_key("ctrl-q")
client.wait_until_fails("pidof code") client.wait_until_fails("pidof code")
@ -123,25 +125,13 @@ in {
# Move the mouse out of the way # Move the mouse out of the way
client.succeed("${pkgs.xdotool}/bin/xdotool mousemove 0 0") client.succeed("${pkgs.xdotool}/bin/xdotool mousemove 0 0")
with subtest("fails to connect when Node is broken"): with subtest("fails to connect when nixpkgs isn't available"):
server.fail("node -v") server.fail("nix-build '<nixpkgs>' -A hello")
connect_with_remote_ssh(screenshot="no_node_installed", should_succeed=False) connect_with_remote_ssh(screenshot="no_node_installed", should_succeed=False)
server.succeed("test -e ~/.vscode-server/bin/*/node") server.succeed("test -e ~/.vscode-server/bin/${rev}/node")
server.fail("~/.vscode-server/bin/*/node -v") server.fail("~/.vscode-server/bin/${rev}/node -v")
with subtest("fails to connect when server has the wrong Node installed"): with subtest("connects when server can patch Node"):
server.succeed("nix-env -i ${pkgs.nodejs-14_x}")
connect_with_remote_ssh(screenshot="wrong_node_installed", should_succeed=False)
server.fail("~/.vscode-server/bin/*/node -v")
with subtest("connects when server has the correct Node installed"):
server.succeed("nix-env -i ${pkgs.nodejs-16_x}")
connect_with_remote_ssh(screenshot="correct_node_installed", should_succeed=True)
server.succeed("~/.vscode-server/bin/*/node -v")
server.succeed("kill $(pgrep -f [v]scode-server)")
server.succeed("nix-env -e nodejs")
with subtest("connects when server can build Node from Nixpkgs"):
server.succeed("mkdir -p /nix/var/nix/profiles/per-user/root/channels") server.succeed("mkdir -p /nix/var/nix/profiles/per-user/root/channels")
server.succeed("ln -s ${pkgs.path} /nix/var/nix/profiles/per-user/root/channels/nixos") server.succeed("ln -s ${pkgs.path} /nix/var/nix/profiles/per-user/root/channels/nixos")
connect_with_remote_ssh(screenshot="build_node_with_nix", should_succeed=True) connect_with_remote_ssh(screenshot="build_node_with_nix", should_succeed=True)

View File

@ -10,8 +10,6 @@
let let
inherit (vscode-utils) buildVscodeMarketplaceExtension; inherit (vscode-utils) buildVscodeMarketplaceExtension;
nodeVersion = "16";
# As VS Code executes this code on the remote machine # As VS Code executes this code on the remote machine
# we test to see if we can build Node from Nixpkgs # we test to see if we can build Node from Nixpkgs
# otherwise we check if the globally installed Node # otherwise we check if the globally installed Node
@ -24,38 +22,44 @@ let
serverNode="$serverDir/node" serverNode="$serverDir/node"
echo "VS Code Node: $serverNode" echo "VS Code Node: $serverNode"
# Check if VS Code Server has a non-working Node or the wrong version of Node # Check if Node included with VS Code Server runs
if ! nodeVersion=$($serverNode -v) || [ "\''${nodeVersion:1:2}" != "${nodeVersion}" ]; then if ! nodeVersion=$($serverNode -v); then
echo "VS Code Node Version: $nodeVersion" echo "VS Code Node Version: $nodeVersion"
if nix-build "<nixpkgs>" -A nodejs-${nodeVersion}_x --out-link "$serverDir/nix" && [ -e "$serverDir/nix/bin/node" ]; then if ! nix-build "<nixpkgs>" -A patchelf --out-link "$serverDir/patchelf" || ! "$serverDir/patchelf/bin/patchelf" --version; then
nodePath="$serverDir/nix/bin/node" echo "Failed to get patchelf from nixpkgs"
fi fi
echo "Node from Nix: $nodePath" if [ -e $serverNode.orig ]; then
cp $serverNode.orig $serverNode
nodeVersion=$($nodePath -v) else
echo "Node from Nix Version: $nodeVersion" cp $serverNode $serverNode.orig
if [ "\''${nodeVersion:1:2}" != "${nodeVersion}" ]; then
echo "Getting Node from Nix failed, use Local Node instead"
nodePath=$(which node)
echo "Local Node: $nodePath"
nodeVersion=$($nodePath -v)
echo "Local Node Version: $nodeVersion"
fi fi
if [ "\''${nodeVersion:1:2}" == "${nodeVersion}" ]; then if ! nix-build "<nixpkgs>" -A bintools --out-link $serverDir/bintools; then
echo PATCH: replacing $serverNode with $nodePath echo "Failed to build bintools from nixpkgs"
ln -sf $nodePath $serverNode
fi fi
INTERPRETER=$(cat $serverDir/bintools/nix-support/dynamic-linker)
echo "Interpreter from bintools: $INTERPRETER"
if ! nix-build "<nixpkgs>" -A stdenv.cc.cc.lib --out-link $serverDir/cc; then
echo "Failed to build stdenv.cc.cc.lib from nixpkgs"
fi
if ! $serverDir/patchelf/bin/patchelf --set-interpreter $INTERPRETER --set-rpath $serverDir/cc-lib/lib $serverNode; then
echo "Failed to patch Node binary"
fi
rm "$serverDir/patchelf"
fi fi
nodeVersion=$($serverNode -v) nodeVersion=$($serverNode -v)
echo "VS Code Node Version: $nodeVersion" echo "VS Code Node Version: $nodeVersion"
if [ "\''${nodeVersion:1:2}" != "${nodeVersion}" ]; then if ! nodeVersion=$($serverNode -v); then
echo "Unsupported VS Code Node version: $nodeVersion", quitting echo "Unable to fix Node binary, quitting"
fail_with_exitcode ''${o.InstallExitCode.ServerTransferFailed} fail_with_exitcode ''${o.InstallExitCode.ServerTransferFailed}
fi fi