From b2ff7ceff25d3e7cb0f6e18ee84d7921cee03d7d Mon Sep 17 00:00:00 2001 From: Michael Hoang Date: Sun, 13 Mar 2022 18:16:34 +1100 Subject: [PATCH 1/5] nixos/tests: Test that Remote SSH can patch Node --- nixos/tests/all-tests.nix | 1 + nixos/tests/vscode-remote-ssh.nix | 145 ++++++++++++++++++ .../ms-vscode-remote.remote-ssh/default.nix | 3 + pkgs/applications/editors/vscode/vscode.nix | 8 +- pkgs/build-support/src-only/default.nix | 3 +- 5 files changed, 157 insertions(+), 3 deletions(-) create mode 100644 nixos/tests/vscode-remote-ssh.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index e597a26f31b..d98c4116cdd 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -812,6 +812,7 @@ in { victoriametrics = handleTest ./victoriametrics.nix {}; vikunja = handleTest ./vikunja.nix {}; virtualbox = handleTestOn ["x86_64-linux"] ./virtualbox.nix {}; + vscode-remote-ssh = handleTestOn ["x86_64-linux"] ./vscode-remote-ssh.nix {}; vscodium = discoverTests (import ./vscodium.nix); vsftpd = handleTest ./vsftpd.nix {}; warzone2100 = handleTest ./warzone2100.nix {}; diff --git a/nixos/tests/vscode-remote-ssh.nix b/nixos/tests/vscode-remote-ssh.nix new file mode 100644 index 00000000000..3d0468fa5f4 --- /dev/null +++ b/nixos/tests/vscode-remote-ssh.nix @@ -0,0 +1,145 @@ +import ./make-test-python.nix ({ lib, ... }: let + pkgs = (import ../..) { + config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [ + "vscode" "vscode-with-extensions" "vscode-extension-ms-vscode-remote-remote-ssh" + ]; + }; + + inherit (import ./ssh-keys.nix pkgs) snakeOilPrivateKey snakeOilPublicKey; + + # 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. + # e.g. git rev-parse 1.77.0 + rev = "7f329fe6c66b0f86ae1574c2911b681ad5a45d63"; + shortRev = builtins.substring 0 8 rev; + + # Our tests run without networking so the remote-ssh extension will always fail to + # download the VSCode server so we can copy it onto the server ourselves. + vscode-server = pkgs.srcOnly { + name = "vscode-server-${shortRev}"; + src = pkgs.fetchurl { + name = "vscode-server-${shortRev}.tar.gz"; + url = "https://update.code.visualstudio.com/commit:${rev}/server-linux-x64/stable"; + sha256 = "11g234lwl3jn5q3637n9sxz5ghhzqvq137lk42vl2nbb57hgyqgq"; + }; + }; +in { + name = "vscode-remote-ssh"; + meta.maintainers = with lib.maintainers; [ Enzime ]; + + nodes = let + serverAddress = "192.168.0.2"; + clientAddress = "192.168.0.1"; + in { + server = { ... }: { + networking.interfaces.eth1.ipv4.addresses = [ { address = serverAddress; prefixLength = 24; } ]; + services.openssh.enable = true; + users.users.root.openssh.authorizedKeys.keys = [ snakeOilPublicKey ]; + virtualisation.additionalPaths = [ pkgs.nodejs-14_x pkgs.nodejs-16_x ]; + }; + client = { ... }: { + imports = [ ./common/x11.nix ./common/user-account.nix ]; + networking.interfaces.eth1.ipv4.addresses = [ { address = clientAddress; prefixLength = 24; } ]; + networking.hosts.${serverAddress} = [ "server" ]; + test-support.displayManager.auto.user = "alice"; + environment.systemPackages = [ + (pkgs.vscode-with-extensions.override { + vscodeExtensions = [ + pkgs.vscode-extensions.ms-vscode-remote.remote-ssh + ]; + }) + ]; + }; + }; + + enableOCR = true; + + testScript = let + jq = "${pkgs.jq}/bin/jq"; + + ssh-config = builtins.toFile "ssh.conf" '' + UserKnownHostsFile=/dev/null + StrictHostKeyChecking=no + ''; + + vscode-config = builtins.toFile "settings.json" '' + { + "window.zoomLevel": 1, + "security.workspace.trust.startupPrompt": "always" + } + ''; + in '' + def connect_with_remote_ssh(screenshot, should_succeed): + print(f"connect_with_remote_ssh({screenshot=}, {should_succeed=})") + + if server.execute("test -d ~/.vscode-server")[0] == 0: + server.succeed("rm -r ~/.vscode-server") + + server.succeed("mkdir -p ~/.vscode-server/bin") + server.succeed("cp -r ${vscode-server} ~/.vscode-server/bin/${rev}") + + client.succeed("sudo -u alice code --remote=ssh-remote+root@server /root") + client.wait_for_window("Visual Studio Code") + + client.wait_for_text("Do you trust the authors" if should_succeed else "Disconnected from SSH") + client.screenshot(screenshot) + + if should_succeed: + # Press the Don't Trust button + client.send_key("tab") + client.send_key("tab") + client.send_key("tab") + client.send_key("\n") + else: + # Close the error dialog + client.send_key("esc") + + client.send_key("ctrl-q") + client.wait_until_fails("pidof code") + + + start_all() + server.wait_for_open_port(22) + + VSCODE_COMMIT = server.execute("${jq} -r .commit ${pkgs.vscode}/lib/vscode/resources/app/product.json")[1].rstrip() + SERVER_COMMIT = server.execute("${jq} -r .commit ${vscode-server}/product.json")[1].rstrip() + + print(f"{VSCODE_COMMIT=} {SERVER_COMMIT=}") + assert VSCODE_COMMIT == SERVER_COMMIT, "VSCODE_COMMIT and SERVER_COMMIT do not match" + + client.wait_until_succeeds("ping -c1 server") + client.succeed("sudo -u alice mkdir ~alice/.ssh") + client.succeed("sudo -u alice install -Dm 600 ${snakeOilPrivateKey} ~alice/.ssh/id_ecdsa") + client.succeed("sudo -u alice install ${ssh-config} ~alice/.ssh/config") + client.succeed("sudo -u alice install -Dm 644 ${vscode-config} ~alice/.config/Code/User/settings.json") + + client.wait_for_x() + client.wait_for_file("~alice/.Xauthority") + client.succeed("xauth merge ~alice/.Xauthority") + # Move the mouse out of the way + client.succeed("${pkgs.xdotool}/bin/xdotool mousemove 0 0") + + with subtest("fails to connect when Node is broken"): + server.fail("node -v") + connect_with_remote_ssh(screenshot="no_node_installed", should_succeed=False) + server.succeed("test -e ~/.vscode-server/bin/*/node") + server.fail("~/.vscode-server/bin/*/node -v") + + with subtest("fails to connect when server has the wrong Node installed"): + 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("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) + ''; +}) diff --git a/pkgs/applications/editors/vscode/extensions/ms-vscode-remote.remote-ssh/default.nix b/pkgs/applications/editors/vscode/extensions/ms-vscode-remote.remote-ssh/default.nix index de191e97e0d..b22705b3e5d 100644 --- a/pkgs/applications/editors/vscode/extensions/ms-vscode-remote.remote-ssh/default.nix +++ b/pkgs/applications/editors/vscode/extensions/ms-vscode-remote.remote-ssh/default.nix @@ -1,4 +1,5 @@ { lib +, nixosTests , vscode-utils , useLocalExtensions ? false }: @@ -87,6 +88,8 @@ buildVscodeMarketplaceExtension { --replace '# Start the server\n' '${patch}' ''; + passthru.tests = { inherit (nixosTests) vscode-remote-ssh; }; + meta = { description = "Use any remote machine with a SSH server as your development environment."; license = lib.licenses.unfree; diff --git a/pkgs/applications/editors/vscode/vscode.nix b/pkgs/applications/editors/vscode/vscode.nix index fb1dd7596ec..333bf848ada 100644 --- a/pkgs/applications/editors/vscode/vscode.nix +++ b/pkgs/applications/editors/vscode/vscode.nix @@ -1,4 +1,8 @@ -{ stdenv, lib, callPackage, fetchurl +{ stdenv +, lib +, callPackage +, fetchurl +, nixosTests , isInsiders ? false , commandLineArgs ? "" , useVSCodeRipgrep ? stdenv.isDarwin @@ -48,6 +52,8 @@ in sourceRoot = ""; + tests = { inherit (nixosTests) vscode-remote-ssh; }; + updateScript = ./update-vscode.sh; # Editing the `code` binary within the app bundle causes the bundle's signature diff --git a/pkgs/build-support/src-only/default.nix b/pkgs/build-support/src-only/default.nix index 6cf5c2ad482..2b0db0e267a 100644 --- a/pkgs/build-support/src-only/default.nix +++ b/pkgs/build-support/src-only/default.nix @@ -1,7 +1,6 @@ { stdenv }: # srcOnly is a utility builder that only fetches and unpacks the given `src`, -# maybe pathings it in the process with the optional `patches` and -# `buildInputs` attributes. +# and optionally patching with `patches` or adding build inputs. # # It can be invoked directly, or be used to wrap an existing derivation. Eg: # From fbf5e75aa21f45420853738b0a1910155fc1f696 Mon Sep 17 00:00:00 2001 From: Michael Hoang Date: Sun, 13 Mar 2022 20:38:22 +1100 Subject: [PATCH 2/5] vscode: Update remote-ssh commit hash with updater --- .../editors/vscode/update-vscode.sh | 24 +++++++++++++++++-- pkgs/applications/editors/vscode/vscode.nix | 2 +- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/pkgs/applications/editors/vscode/update-vscode.sh b/pkgs/applications/editors/vscode/update-vscode.sh index 67ec7a21b34..b857d29224e 100755 --- a/pkgs/applications/editors/vscode/update-vscode.sh +++ b/pkgs/applications/editors/vscode/update-vscode.sh @@ -14,14 +14,34 @@ if [ ! -f "$ROOT/vscode.nix" ]; then exit 1 fi +NIXPKGS_ROOT="$(git rev-parse --show-toplevel)" + +if [ ! -f "$NIXPKGS_ROOT/nixos/tests/vscode-remote-ssh.nix" ]; then + echo "ERROR: cannot find nixos/tests/vscode-remote-ssh.nix" + exit 1 +fi + # VSCode VSCODE_VER=$(curl --fail --silent https://api.github.com/repos/Microsoft/vscode/releases/latest | jq --raw-output .tag_name) sed -i "s/version = \".*\"/version = \"${VSCODE_VER}\"/" "$ROOT/vscode.nix" +TEMP_FOLDER=$(mktemp -d) + VSCODE_X64_LINUX_URL="https://update.code.visualstudio.com/${VSCODE_VER}/linux-x64/stable" -VSCODE_X64_LINUX_SHA256=$(nix-prefetch-url ${VSCODE_X64_LINUX_URL}) -sed -i "s/x86_64-linux = \".\{52\}\"/x86_64-linux = \"${VSCODE_X64_LINUX_SHA256}\"/" "$ROOT/vscode.nix" + +# Split output by newlines into Bash array +readarray -t VSCODE_X64_LINUX <<< $(nix-prefetch-url --print-path ${VSCODE_X64_LINUX_URL}) + +sed -i "s/x86_64-linux = \".\{52\}\"/x86_64-linux = \"${VSCODE_X64_LINUX[0]}\"/" "$ROOT/vscode.nix" + +tar xf $VSCODE_X64_LINUX[1] -C $TEMP_FOLDER +VSCODE_COMMIT=$(jq --raw-output .commit $TEMP_FOLDER/VSCode-linux-x64/resources/app/product.json) +sed -i "s/rev = \".\{40\}\"/rev = \"${VSCODE_COMMIT}\"/" "$NIXPKGS_ROOT/nixos/tests/vscode-remote-ssh.nix" + +SERVER_X64_LINUX_URL="https://update.code.visualstudio.com/commit:${VSCODE_COMMIT}/server-linux-x64/stable" +SERVER_X64_LINUX_SHA256=$(nix-prefetch-url ${SERVER_X64_LINUX_URL}) +sed -i "s/sha256 = \".\{51,52\}\"/sha256 = \"${SERVER_X64_LINUX_SHA256}\"/" "$NIXPKGS_ROOT/nixos/tests/vscode-remote-ssh.nix" VSCODE_X64_DARWIN_URL="https://update.code.visualstudio.com/${VSCODE_VER}/darwin/stable" VSCODE_X64_DARWIN_SHA256=$(nix-prefetch-url ${VSCODE_X64_DARWIN_URL}) diff --git a/pkgs/applications/editors/vscode/vscode.nix b/pkgs/applications/editors/vscode/vscode.nix index 333bf848ada..519a4b6f194 100644 --- a/pkgs/applications/editors/vscode/vscode.nix +++ b/pkgs/applications/editors/vscode/vscode.nix @@ -77,7 +77,7 @@ in homepage = "https://code.visualstudio.com/"; downloadPage = "https://code.visualstudio.com/Updates"; license = licenses.unfree; - maintainers = with maintainers; [ eadwu synthetica maxeaubrey bobby285271 ]; + maintainers = with maintainers; [ eadwu synthetica maxeaubrey bobby285271 Enzime ]; platforms = [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" "aarch64-linux" "armv7l-linux" ]; }; } From 3e9a51a78b9028a91e2201b5d241a884ebbe84a1 Mon Sep 17 00:00:00 2001 From: Michael Hoang Date: Mon, 14 Mar 2022 00:26:49 +1100 Subject: [PATCH 3/5] nixos/tests: Make remote-ssh test work with flakes --- nixos/tests/vscode-remote-ssh.nix | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/nixos/tests/vscode-remote-ssh.nix b/nixos/tests/vscode-remote-ssh.nix index 3d0468fa5f4..871eeab0cdb 100644 --- a/nixos/tests/vscode-remote-ssh.nix +++ b/nixos/tests/vscode-remote-ssh.nix @@ -1,9 +1,13 @@ -import ./make-test-python.nix ({ lib, ... }: let - pkgs = (import ../..) { - config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [ - "vscode" "vscode-with-extensions" "vscode-extension-ms-vscode-remote-remote-ssh" - ]; - }; +import ./make-test-python.nix ({ lib, ... }@args: let + pkgs = args.pkgs.extend (self: super: { + stdenv = super.stdenv.override { + config = super.config // { + allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [ + "vscode" "vscode-with-extensions" "vscode-extension-ms-vscode-remote-remote-ssh" + ]; + }; + }; + }); inherit (import ./ssh-keys.nix pkgs) snakeOilPrivateKey snakeOilPublicKey; From 011df7a76bfea22173cae9628eadcd2c5140d5b2 Mon Sep 17 00:00:00 2001 From: Michael Hoang Date: Thu, 25 May 2023 23:53:14 +1000 Subject: [PATCH 4/5] vscode-remote-ssh: Run patchelf on included Node --- nixos/tests/vscode-remote-ssh.nix | 30 ++++-------- .../ms-vscode-remote.remote-ssh/default.nix | 48 ++++++++++--------- 2 files changed, 36 insertions(+), 42 deletions(-) diff --git a/nixos/tests/vscode-remote-ssh.nix b/nixos/tests/vscode-remote-ssh.nix index 871eeab0cdb..87fdc0bd504 100644 --- a/nixos/tests/vscode-remote-ssh.nix +++ b/nixos/tests/vscode-remote-ssh.nix @@ -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 # want this to match the commit of VS Code in Nixpkgs. # e.g. git rev-parse 1.77.0 - rev = "7f329fe6c66b0f86ae1574c2911b681ad5a45d63"; + rev = "b3e4e68a0bc097f0ae7907b217c1119af9e03435"; shortRev = builtins.substring 0 8 rev; # 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 { name = "vscode-server-${shortRev}.tar.gz"; url = "https://update.code.visualstudio.com/commit:${rev}/server-linux-x64/stable"; - sha256 = "11g234lwl3jn5q3637n9sxz5ghhzqvq137lk42vl2nbb57hgyqgq"; + sha256 = "1gpsxlv4p3v3kh7b7b2i1lvm5g30xrq1vb7csqwhs4zjlbwfhdb2"; }; }; in { @@ -39,7 +39,7 @@ in { networking.interfaces.eth1.ipv4.addresses = [ { address = serverAddress; prefixLength = 24; } ]; services.openssh.enable = true; 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 = { ... }: { imports = [ ./common/x11.nix ./common/user-account.nix ]; @@ -98,6 +98,8 @@ in { # Close the error dialog 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.wait_until_fails("pidof code") @@ -123,25 +125,13 @@ in { # Move the mouse out of the way client.succeed("${pkgs.xdotool}/bin/xdotool mousemove 0 0") - with subtest("fails to connect when Node is broken"): - server.fail("node -v") + with subtest("fails to connect when nixpkgs isn't available"): + server.fail("nix-build '' -A hello") connect_with_remote_ssh(screenshot="no_node_installed", should_succeed=False) - server.succeed("test -e ~/.vscode-server/bin/*/node") - server.fail("~/.vscode-server/bin/*/node -v") + server.succeed("test -e ~/.vscode-server/bin/${rev}/node") + server.fail("~/.vscode-server/bin/${rev}/node -v") - with subtest("fails to connect when server has the wrong Node installed"): - 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"): + with subtest("connects when server can patch Node"): 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") connect_with_remote_ssh(screenshot="build_node_with_nix", should_succeed=True) diff --git a/pkgs/applications/editors/vscode/extensions/ms-vscode-remote.remote-ssh/default.nix b/pkgs/applications/editors/vscode/extensions/ms-vscode-remote.remote-ssh/default.nix index b22705b3e5d..d479e7d1fd5 100644 --- a/pkgs/applications/editors/vscode/extensions/ms-vscode-remote.remote-ssh/default.nix +++ b/pkgs/applications/editors/vscode/extensions/ms-vscode-remote.remote-ssh/default.nix @@ -10,8 +10,6 @@ let inherit (vscode-utils) buildVscodeMarketplaceExtension; - nodeVersion = "16"; - # As VS Code executes this code on the remote machine # we test to see if we can build Node from Nixpkgs # otherwise we check if the globally installed Node @@ -24,38 +22,44 @@ let serverNode="$serverDir/node" echo "VS Code Node: $serverNode" - # Check if VS Code Server has a non-working Node or the wrong version of Node - if ! nodeVersion=$($serverNode -v) || [ "\''${nodeVersion:1:2}" != "${nodeVersion}" ]; then + # Check if Node included with VS Code Server runs + if ! nodeVersion=$($serverNode -v); then echo "VS Code Node Version: $nodeVersion" - if nix-build "" -A nodejs-${nodeVersion}_x --out-link "$serverDir/nix" && [ -e "$serverDir/nix/bin/node" ]; then - nodePath="$serverDir/nix/bin/node" + if ! nix-build "" -A patchelf --out-link "$serverDir/patchelf" || ! "$serverDir/patchelf/bin/patchelf" --version; then + echo "Failed to get patchelf from nixpkgs" fi - echo "Node from Nix: $nodePath" - - nodeVersion=$($nodePath -v) - echo "Node from Nix Version: $nodeVersion" - - 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" + if [ -e $serverNode.orig ]; then + cp $serverNode.orig $serverNode + else + cp $serverNode $serverNode.orig fi - if [ "\''${nodeVersion:1:2}" == "${nodeVersion}" ]; then - echo PATCH: replacing $serverNode with $nodePath - ln -sf $nodePath $serverNode + if ! nix-build "" -A bintools --out-link $serverDir/bintools; then + echo "Failed to build bintools from nixpkgs" fi + + INTERPRETER=$(cat $serverDir/bintools/nix-support/dynamic-linker) + + echo "Interpreter from bintools: $INTERPRETER" + + if ! nix-build "" -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 nodeVersion=$($serverNode -v) echo "VS Code Node Version: $nodeVersion" - if [ "\''${nodeVersion:1:2}" != "${nodeVersion}" ]; then - echo "Unsupported VS Code Node version: $nodeVersion", quitting + if ! nodeVersion=$($serverNode -v); then + echo "Unable to fix Node binary, quitting" fail_with_exitcode ''${o.InstallExitCode.ServerTransferFailed} fi From 8bf8b8fd68b644f3c1ab3a52464173212da2dfaf Mon Sep 17 00:00:00 2001 From: Michael Hoang Date: Thu, 1 Jun 2023 01:09:50 +1000 Subject: [PATCH 5/5] vscode: move rev and vscodeServer to derivation --- nixos/tests/vscode-remote-ssh.nix | 29 +++++-------------- pkgs/applications/editors/vscode/generic.nix | 4 +++ .../editors/vscode/update-vscode.sh | 13 ++------- pkgs/applications/editors/vscode/vscode.nix | 14 +++++++++ 4 files changed, 28 insertions(+), 32 deletions(-) diff --git a/nixos/tests/vscode-remote-ssh.nix b/nixos/tests/vscode-remote-ssh.nix index 87fdc0bd504..de7cc6badc9 100644 --- a/nixos/tests/vscode-remote-ssh.nix +++ b/nixos/tests/vscode-remote-ssh.nix @@ -11,22 +11,7 @@ import ./make-test-python.nix ({ lib, ... }@args: let inherit (import ./ssh-keys.nix pkgs) snakeOilPrivateKey snakeOilPublicKey; - # 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. - # e.g. git rev-parse 1.77.0 - rev = "b3e4e68a0bc097f0ae7907b217c1119af9e03435"; - shortRev = builtins.substring 0 8 rev; - - # Our tests run without networking so the remote-ssh extension will always fail to - # download the VSCode server so we can copy it onto the server ourselves. - vscode-server = pkgs.srcOnly { - name = "vscode-server-${shortRev}"; - src = pkgs.fetchurl { - name = "vscode-server-${shortRev}.tar.gz"; - url = "https://update.code.visualstudio.com/commit:${rev}/server-linux-x64/stable"; - sha256 = "1gpsxlv4p3v3kh7b7b2i1lvm5g30xrq1vb7csqwhs4zjlbwfhdb2"; - }; - }; + inherit (pkgs.vscode.passthru) rev vscodeServer; in { name = "vscode-remote-ssh"; meta.maintainers = with lib.maintainers; [ Enzime ]; @@ -61,12 +46,12 @@ in { testScript = let jq = "${pkgs.jq}/bin/jq"; - ssh-config = builtins.toFile "ssh.conf" '' + sshConfig = builtins.toFile "ssh.conf" '' UserKnownHostsFile=/dev/null StrictHostKeyChecking=no ''; - vscode-config = builtins.toFile "settings.json" '' + vscodeConfig = builtins.toFile "settings.json" '' { "window.zoomLevel": 1, "security.workspace.trust.startupPrompt": "always" @@ -80,7 +65,7 @@ in { server.succeed("rm -r ~/.vscode-server") server.succeed("mkdir -p ~/.vscode-server/bin") - server.succeed("cp -r ${vscode-server} ~/.vscode-server/bin/${rev}") + server.succeed("cp -r ${vscodeServer} ~/.vscode-server/bin/${rev}") client.succeed("sudo -u alice code --remote=ssh-remote+root@server /root") client.wait_for_window("Visual Studio Code") @@ -108,7 +93,7 @@ in { server.wait_for_open_port(22) VSCODE_COMMIT = server.execute("${jq} -r .commit ${pkgs.vscode}/lib/vscode/resources/app/product.json")[1].rstrip() - SERVER_COMMIT = server.execute("${jq} -r .commit ${vscode-server}/product.json")[1].rstrip() + SERVER_COMMIT = server.execute("${jq} -r .commit ${vscodeServer}/product.json")[1].rstrip() print(f"{VSCODE_COMMIT=} {SERVER_COMMIT=}") assert VSCODE_COMMIT == SERVER_COMMIT, "VSCODE_COMMIT and SERVER_COMMIT do not match" @@ -116,8 +101,8 @@ in { client.wait_until_succeeds("ping -c1 server") client.succeed("sudo -u alice mkdir ~alice/.ssh") client.succeed("sudo -u alice install -Dm 600 ${snakeOilPrivateKey} ~alice/.ssh/id_ecdsa") - client.succeed("sudo -u alice install ${ssh-config} ~alice/.ssh/config") - client.succeed("sudo -u alice install -Dm 644 ${vscode-config} ~alice/.config/Code/User/settings.json") + client.succeed("sudo -u alice install ${sshConfig} ~alice/.ssh/config") + client.succeed("sudo -u alice install -Dm 644 ${vscodeConfig} ~alice/.config/Code/User/settings.json") client.wait_for_x() client.wait_for_file("~alice/.Xauthority") diff --git a/pkgs/applications/editors/vscode/generic.nix b/pkgs/applications/editors/vscode/generic.nix index 7b7007910a5..6d1c20c8554 100644 --- a/pkgs/applications/editors/vscode/generic.nix +++ b/pkgs/applications/editors/vscode/generic.nix @@ -13,6 +13,8 @@ , version, src, meta, sourceRoot, commandLineArgs , executableName, longName, shortName, pname, updateScript , dontFixup ? false +, rev ? null, vscodeServer ? null + # sourceExecutableName is the name of the binary in the source archive, over # which we have no control , sourceExecutableName ? executableName @@ -30,6 +32,8 @@ let inherit executableName longName tests updateScript; fhs = fhs {}; fhsWithPackages = f: fhs { additionalPkgs = f; }; + } // lib.optionalAttrs (vscodeServer != null) { + inherit rev vscodeServer; }; desktopItem = makeDesktopItem { diff --git a/pkgs/applications/editors/vscode/update-vscode.sh b/pkgs/applications/editors/vscode/update-vscode.sh index b857d29224e..d1df522f402 100755 --- a/pkgs/applications/editors/vscode/update-vscode.sh +++ b/pkgs/applications/editors/vscode/update-vscode.sh @@ -14,13 +14,6 @@ if [ ! -f "$ROOT/vscode.nix" ]; then exit 1 fi -NIXPKGS_ROOT="$(git rev-parse --show-toplevel)" - -if [ ! -f "$NIXPKGS_ROOT/nixos/tests/vscode-remote-ssh.nix" ]; then - echo "ERROR: cannot find nixos/tests/vscode-remote-ssh.nix" - exit 1 -fi - # VSCode VSCODE_VER=$(curl --fail --silent https://api.github.com/repos/Microsoft/vscode/releases/latest | jq --raw-output .tag_name) @@ -35,13 +28,13 @@ readarray -t VSCODE_X64_LINUX <<< $(nix-prefetch-url --print-path ${VSCODE_X64_L sed -i "s/x86_64-linux = \".\{52\}\"/x86_64-linux = \"${VSCODE_X64_LINUX[0]}\"/" "$ROOT/vscode.nix" -tar xf $VSCODE_X64_LINUX[1] -C $TEMP_FOLDER +tar xf ${VSCODE_X64_LINUX[1]} -C $TEMP_FOLDER VSCODE_COMMIT=$(jq --raw-output .commit $TEMP_FOLDER/VSCode-linux-x64/resources/app/product.json) -sed -i "s/rev = \".\{40\}\"/rev = \"${VSCODE_COMMIT}\"/" "$NIXPKGS_ROOT/nixos/tests/vscode-remote-ssh.nix" +sed -i "s/rev = \".\{40\}\"/rev = \"${VSCODE_COMMIT}\"/" "$ROOT/vscode.nix" SERVER_X64_LINUX_URL="https://update.code.visualstudio.com/commit:${VSCODE_COMMIT}/server-linux-x64/stable" SERVER_X64_LINUX_SHA256=$(nix-prefetch-url ${SERVER_X64_LINUX_URL}) -sed -i "s/sha256 = \".\{51,52\}\"/sha256 = \"${SERVER_X64_LINUX_SHA256}\"/" "$NIXPKGS_ROOT/nixos/tests/vscode-remote-ssh.nix" +sed -i "s/sha256 = \".\{51,52\}\"/sha256 = \"${SERVER_X64_LINUX_SHA256}\"/" "$ROOT/vscode.nix" VSCODE_X64_DARWIN_URL="https://update.code.visualstudio.com/${VSCODE_VER}/darwin/stable" VSCODE_X64_DARWIN_SHA256=$(nix-prefetch-url ${VSCODE_X64_DARWIN_URL}) diff --git a/pkgs/applications/editors/vscode/vscode.nix b/pkgs/applications/editors/vscode/vscode.nix index 519a4b6f194..b281099a689 100644 --- a/pkgs/applications/editors/vscode/vscode.nix +++ b/pkgs/applications/editors/vscode/vscode.nix @@ -3,6 +3,7 @@ , callPackage , fetchurl , nixosTests +, srcOnly , isInsiders ? false , commandLineArgs ? "" , useVSCodeRipgrep ? stdenv.isDarwin @@ -36,6 +37,9 @@ in version = "1.79.0"; pname = "vscode"; + # This is used for VS Code - Remote SSH test + rev = "b380da4ef1ee00e224a15c1d4d9793e27c2b6302"; + executableName = "code" + lib.optionalString isInsiders "-insiders"; longName = "Visual Studio Code" + lib.optionalString isInsiders " - Insiders"; shortName = "Code" + lib.optionalString isInsiders " - Insiders"; @@ -52,6 +56,16 @@ in sourceRoot = ""; + # As tests run without networking, we need to download this for the Remote SSH server + vscodeServer = srcOnly { + name = "vscode-server-${rev}.tar.gz"; + src = fetchurl { + name = "vscode-server-${rev}.tar.gz"; + url = "https://update.code.visualstudio.com/commit:${rev}/server-linux-x64/stable"; + sha256 = "0732wpl4fjknhn423k23zrcqz9psjj1iy8lqa0fc8970n1m7i58b"; + }; + }; + tests = { inherit (nixosTests) vscode-remote-ssh; }; updateScript = ./update-vscode.sh;