diff --git a/nixos/tests/vscode-remote-ssh.nix b/nixos/tests/vscode-remote-ssh.nix index 87fdc0bd504d..de7cc6badc9a 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 7b7007910a5c..6d1c20c85541 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 b857d29224e4..d1df522f4024 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 519a4b6f1942..b281099a689e 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;