Unverified Commit 2c0ff143 authored by Doron Behar's avatar Doron Behar Committed by GitHub
Browse files

openvscode-server: 1.88.1 -> 1.99.3 (#410777)

parents 4a2c6cc5 a81cfab9
Loading
Loading
Loading
Loading
+145 −153
Original line number Diff line number Diff line
@@ -9,9 +9,7 @@
  jq,
  git,
  pkg-config,
  yarn,
  python3,
  esbuild,
  runCommand,
  nodejs,
  node-gyp,
  libsecret,
@@ -20,17 +18,11 @@
  ripgrep,
  cctools,
  nixosTests,
  prefetch-npm-deps,
}:

let
  system = stdenv.hostPlatform.system;

  yarn' = yarn.override { inherit nodejs; };
  defaultYarnOpts = [
    "frozen-lockfile"
    "non-interactive"
    "no-progress"
  ];
  system = stdenv.hostPlatform.system;

  vsBuildTarget =
    {
@@ -41,74 +33,76 @@ let
    }
    .${system} or (throw "Unsupported system ${system}");

  esbuild' = esbuild.override {
    buildGoModule =
      args:
      buildGoModule (
        args
        // rec {
          version = "0.17.14";
          src = fetchFromGitHub {
            owner = "evanw";
            repo = "esbuild";
            rev = "v${version}";
            hash = "sha256-4TC1d5FOZHUMuEMTcTOBLZZM+sFUswhyblI5HVWyvPA=";
          };
          vendorHash = "sha256-+BfxCyg0KkDQpHt/wycy/8CTG6YBA/VJvJFhhzUnSiQ=";
        }
      );
  };

  # replaces esbuild's download script with a binary from nixpkgs
  patchEsbuild = path: version: ''
    mkdir -p ${path}/node_modules/esbuild/bin
    jq "del(.scripts.postinstall)" ${path}/node_modules/esbuild/package.json | sponge ${path}/node_modules/esbuild/package.json
    sed -i 's/${version}/${esbuild'.version}/g' ${path}/node_modules/esbuild/lib/main.js
    ln -s -f ${esbuild'}/bin/esbuild ${path}/node_modules/esbuild/bin/esbuild
  '';
in
stdenv.mkDerivation (finalAttrs: {
  pname = "openvscode-server";
  version = "1.88.1";
  version = "1.99.3";

  src = fetchFromGitHub {
    owner = "gitpod-io";
    repo = "openvscode-server";
    rev = "openvscode-server-v${finalAttrs.version}";
    hash = "sha256-Yc16L13Z8AmsGoSFbvy+4+KBdHxvqLMwZLeU2/dAQVU=";
    hash = "sha256-nA+StCJgutWjD7vgCCcj9B91QSF7dEHnlNtj7zgJRwI=";
  };

  yarnCache = stdenv.mkDerivation {
    name = "${finalAttrs.pname}-${finalAttrs.version}-${system}-yarn-cache";
    inherit (finalAttrs) src;
    nativeBuildInputs = [
      cacert
      yarn'
      git
    ];
    buildPhase = ''
      export HOME=$PWD

      yarn config set yarn-offline-mirror $out
      find "$PWD" -name "yarn.lock" -printf "%h\n" | \
        xargs -I {} yarn --cwd {} \
          --frozen-lockfile --ignore-scripts --ignore-platform \
          --ignore-engines --no-progress --non-interactive
    '';

    installPhase = ''
      echo yarnCache
    '';

  ## fetchNpmDeps doesn't correctly process git dependencies
  ## presumably because of https://github.com/npm/cli/issues/5170
  ## therefore, we're fetching all the node_module folders into
  ## a single FOD, and unpack it in configurePhase
  nodeModules =
    runCommand "openvscode-server-node-modules"
      {
        inherit (finalAttrs) src nativeBuildInputs;
        outputHashMode = "recursive";
        outputHashAlgo = "sha256";
    outputHash = "sha256-89c6GYLT2RzHqwxBKegYqB6g5rEJ6/nH53cnfV7b0Ts=";
        outputHash = "sha256-lgzNpWFAIGNxjDZ60kRw80fP1qEItk3FN1s5t7KdxGA=";
        env = {
          FORCE_EMPTY_CACHE = true;
          FORCE_GIT_DEPS = true;
          npm_config_progress = false;
          npm_config_cafile = "${cacert}/etc/ssl/certs/ca-bundle.crt";
        };
      }
      ''
        runPhase unpackPhase
        export HOME=$TMPDIR/home
        mkdir $out
        for p in $(find -name package-lock.json)
        do (
          ${prefetch-npm-deps}/bin/prefetch-npm-deps "$p" "$out"
          local lockpath=$out/lockfiles/$p
          mkdir -p "$(dirname $lockpath)"
          mv $out/package-lock.json "$lockpath"
        )
        done
      '';

  env = {
    NODE_OPTIONS = "--openssl-legacy-provider";
    NODE_ENV = "development";

    # skip unnecessary binary downloads
    PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD = "1";
    ELECTRON_SKIP_BINARY_DOWNLOAD = "1";

    # ensure the correct node-gyp (from nixpkgs) is used
    NIX_NODEJS_BUILDNPMPACKAGE = "1";
    npm_config_nodedir = nodejs;
    npm_config_node_gyp = "${nodejs}/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js";

    # use local npm cache (see <nixpkgs/pkgs/build-support/node/build-npm-package/hooks/npm-config-hook.sh>)
    npm_config_cache = finalAttrs.nodeModules;
    npm_config_offline = true;
    npm_config_progress = false;

    # for --fixup-lockfile
    prefetchNpmDeps = "${prefetch-npm-deps}/bin/prefetch-npm-deps";
    forceGitDeps = true;

  };
  nativeBuildInputs = [
    nodejs
    yarn'
    python3
    nodejs.python
    pkg-config
    makeWrapper
    git
@@ -127,19 +121,10 @@ stdenv.mkDerivation (finalAttrs: {
      cctools
    ];

  patches = [
    # Patch out remote download of nodejs from build script
    ./remove-node-download.patch
  ];

  # Disable NAPI_EXPERIMENTAL to allow to build with Node.js≥18.20.0.
  env.NIX_CFLAGS_COMPILE = "-DNODE_API_EXPERIMENTAL_NOGC_ENV_OPT_OUT";

  postPatch = ''
    export HOME=$PWD

  # remove all built-in extensions, as these are 3rd party extensions that
  # get downloaded from vscode marketplace
  postPatch =
    ''
      jq --slurp '.[0] * .[1]' "product.json" <(
        cat << EOF
      {
@@ -147,81 +132,89 @@ stdenv.mkDerivation (finalAttrs: {
      }
      EOF
      ) | sponge product.json
      echo "Updated product.json"
    ''
    ## build/lib/node.ts picks up nodejs version from remote/.npmrc
    ## and prefetches it into .build/node/v{version}/{target}/node
    ## so we pre-seed it here
    + ''
      sed -i 's/target=.*/target="${nodejs.version}"/' remote/.npmrc
      mkdir -p .build/node/v${nodejs.version}/${vsBuildTarget}
      ln -s ${nodejs}/bin/node .build/node/v${nodejs.version}/${vsBuildTarget}/node
    '';

  configurePhase = ''
    runHook preConfigure

    # set default yarn opts
    ${lib.concatMapStrings (option: ''
      yarn --offline config set ${option}
    '') defaultYarnOpts}

    # set offline mirror to yarn cache we created in previous steps
    yarn --offline config set yarn-offline-mirror "${finalAttrs.yarnCache}"

    # set nodedir to prevent node-gyp from downloading headers
    # taken from https://nixos.org/manual/nixpkgs/stable/#javascript-tool-specific
    mkdir -p $HOME/.node-gyp/${nodejs.version}
    echo 9 > $HOME/.node-gyp/${nodejs.version}/installVersion
    ln -sfv ${nodejs}/include $HOME/.node-gyp/${nodejs.version}
    export npm_config_nodedir=${nodejs}

    # use updated node-gyp. fixes the following error on Darwin:
    # PermissionError: [Errno 1] Operation not permitted: '/usr/sbin/pkgutil'
    export npm_config_node_gyp=${node-gyp}/lib/node_modules/node-gyp/bin/node-gyp.js

    runHook postConfigure
  preConfigure = ''
    export HOME=$TMPDIR/home
    mkdir -p $HOME
    mkdir -p $TMPDIR/cache/_cacache
    # ln -s $nodeModules/_cacache/* $TMPDIR/cache/_cacache
    # mkdir -p $TMPDIR/cache
    cp -R $nodeModules/_cacache $TMPDIR/cache
    chmod -R +w $TMPDIR/cache
    export npm_config_cache=$TMPDIR/cache
  '';

  buildPhase =
  configurePhase =
    ''
      runHook preBuild

      # install dependencies
      yarn --offline --ignore-scripts

      # run yarn install everywhere, skipping postinstall so we can patch esbuild
      find . -path "*node_modules" -prune -o \
        -path "./*/*" -name "yarn.lock" -printf "%h\n" | \
          xargs -I {} yarn --cwd {} \
            --frozen-lockfile --offline --ignore-scripts --ignore-engines

      ${patchEsbuild "./build" "0.12.6"}
      ${patchEsbuild "./extensions" "0.11.23"}

      # patch shebangs of node_modules to allow binary packages to build
      patchShebangs ./remote/node_modules

      # put ripgrep binary into bin so postinstall does not try to download it
      runHook preConfigure
    ''
    ## unpack all of the prefetched node_modules folders
    + ''
      for p in $(find -name package-lock.json -exec dirname {} \;)
      do (
        echo "Setting up $p/node_modules"
        cd $p
        if [ -e node_modules ]
        then
          echo >&2 "File exists $p/node_modules"
          exit 0
        fi
        npm ci --ignore-scripts
        patchShebangs node_modules
      )
      done
    ''
    ## put ripgrep binary into bin so postinstall does not try to download it
    + ''
      find -path "*@vscode/ripgrep" -type d \
        -execdir mkdir -p {}/bin \; \
        -execdir ln -s ${ripgrep}/bin/rg {}/bin/rg \;
    ''
    + lib.optionalString stdenv.hostPlatform.isDarwin ''
      # use prebuilt binary for @parcel/watcher, which requires macOS SDK 10.13+
      # (see issue #101229)
      pushd ./remote/node_modules/@parcel/watcher
      mkdir -p ./build/Release
      mv ./prebuilds/darwin-x64/node.napi.glibc.node ./build/Release/watcher.node
      jq "del(.scripts) | .gypfile = false" ./package.json | sponge ./package.json
      popd
    ## pre-seed node-gyp
    + ''
      mkdir -p $HOME/.node-gyp/${nodejs.version}
      echo 11 > $HOME/.node-gyp/${nodejs.version}/installVersion
      ln -sfv ${nodejs}/include $HOME/.node-gyp/${nodejs.version}
    ''
    ## node-pty build fix
    + ''
      export NODE_OPTIONS=--openssl-legacy-provider

      # rebuild binaries, we use npm here, as yarn does not provide an alternative
      # that would not attempt to try to reinstall everything and break our
      # patching attempts
      npm --prefix ./remote rebuild --build-from-source
      substituteInPlace remote/node_modules/node-pty/scripts/post-install.js \
        --replace-fail "npx node-gyp" "$npm_config_node_gyp"
    ''
    ## rebuild native binaries
    + ''
      echo >&2 "Rebuilding from source in ./remote"
      npm --offline --prefix ./remote rebuild --build-from-source
    ''
    ## run postinstall scripts
    + ''
      find -name package.json -type f -exec sh -c '
        if jq -e ".scripts.postinstall" {} >-
        then
          echo >&2 "Running postinstall script in $(dirname {})"
          npm --offline --prefix=$(dirname {}) run postinstall
        fi
        exit 0
      ' \;
    ''
    + ''
      runHook postConfigure
    '';

      # run postinstall scripts after patching
      find . -path "*node_modules" -prune -o \
        -path "./*/*" -name "yarn.lock" -printf "%h\n" | \
          xargs -I {} sh -c 'jq -e ".scripts.postinstall" {}/package.json >/dev/null && yarn --cwd {} postinstall --frozen-lockfile --offline || true'
  buildPhase = ''
    runHook preBuild

      # build and minify
      yarn --offline gulp vscode-reh-web-${vsBuildTarget}-min
    npm run gulp vscode-reh-web-${vsBuildTarget}-min

    runHook postBuild
  '';
@@ -231,7 +224,7 @@ stdenv.mkDerivation (finalAttrs: {

    mkdir -p $out
    cp -R -T ../vscode-reh-web-${vsBuildTarget} $out
    ln -s ${nodejs}/bin/node $out
    ln -sf ${nodejs}/bin/node $out

    runHook postInstall
  '';
@@ -252,6 +245,7 @@ stdenv.mkDerivation (finalAttrs: {
      dguenther
      ghuntley
      emilytrau
      bendlas
    ];
    platforms = [
      "x86_64-linux"
@@ -259,8 +253,6 @@ stdenv.mkDerivation (finalAttrs: {
      "x86_64-darwin"
      "aarch64-darwin"
    ];
    # Depends on nodejs_18 that has been removed.
    broken = true;
    mainProgram = "openvscode-server";
  };
})
+0 −30
Original line number Diff line number Diff line
diff --git a/build/gulpfile.reh.js b/build/gulpfile.reh.js
index 4630eaad3cc..96b165b0949 100644
--- a/build/gulpfile.reh.js
+++ b/build/gulpfile.reh.js
@@ -271,9 +271,6 @@ function packageTask(type, platform, arch, sourceFolderName, destinationFolderNa
 			.pipe(util.stripSourceMappingURL())
 			.pipe(jsFilter.restore);

-		const nodePath = `.build/node/v${nodeVersion}/${platform}-${arch}`;
-		const node = gulp.src(`${nodePath}/**`, { base: nodePath, dot: true });
-
 		let web = [];
 		if (type === 'reh-web') {
 			web = [
@@ -290,7 +287,6 @@ function packageTask(type, platform, arch, sourceFolderName, destinationFolderNa
 			license,
 			sources,
 			deps,
-			node,
 			...web
 		);

@@ -408,7 +404,6 @@ function tweakProductForServerWeb(product) {
 			const destinationFolderName = `vscode-${type}${dashed(platform)}${dashed(arch)}`;

 			const serverTaskCI = task.define(`vscode-${type}${dashed(platform)}${dashed(arch)}${dashed(minified)}-ci`, task.series(
-				gulp.task(`node-${platform}-${arch}`),
 				util.rimraf(path.join(BUILD_ROOT, destinationFolderName)),
 				packageTask(type, platform, arch, sourceFolderName, destinationFolderName)
 			));
+1 −3
Original line number Diff line number Diff line
@@ -14464,9 +14464,7 @@ with pkgs;
    vscode-generic = ../applications/editors/vscode/generic.nix;
  };
  openvscode-server = callPackage ../servers/openvscode-server {
    nodejs = nodejs_20;
  };
  openvscode-server = callPackage ../servers/openvscode-server { };
  code-server = callPackage ../servers/code-server {
    nodejs = nodejs_20;