From c23b03c781d650dc70cd5a83cae358b3d2df3abe Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sat, 14 Sep 2024 01:09:23 +0200 Subject: [PATCH] [24.05 backport] nodejs changes (#336570) * nodejs_18: pin to Python 3.11, fix tests with OpenSSL 3.0.14 (cherry picked from commit 7c1177c514661cdd8b9592905a234db6068f0d0c) * nodejs: use upstream patch instead of custom one (cherry picked from commit f75d50324faf773abf9c66c04fa1ff1fe2bf0919) * nodejs_22: 22.4.1 -> 22.5.1 (cherry picked from commit 070791fba6ce4cf0ebb16e490f25397bcc562e59) * nodejs: use .finalPackage for ease of overriding Previously, the nodejs `passthru.pkgs` attribute refers to the package fixed point derived in the current context, without considering potential overrides to the main nodejs package. This is fixed here with the `.finalPackage` attribute, which refers to the final package fixed point, after potential overrides. For example, previously, after overriding nodejs with `nodejs.override`, `nodejs.pkgs` would still refer to the original package, instead of the overridden one. After this fix, `nodejs.pkgs` would be correctly based on the overridden `nodejs` package. (cherry picked from commit ee9a623f897b154ddce0178e1c7daa9793fc14ab) * nodejs: fix tests and disable parallel checking (cherry picked from commit d7f46fbb5c40e7e9a165adf4f82669ae35c5b055) * nodejs: disable failing tests on x86_64-darwin (cherry picked from commit 31d238110c720ab467cbd7adb715ebca76f9e09d) * nodejs: skip tests failing in sandbox in all platforms ce685a8422 added list of tests failing on sandbox, but for some reason only for Darwin. We should skip those tests on all platforms otherwise OfBorg builds are failing. (cherry picked from commit f5846d25a1335267bc8bad633ffcbdf2109b18dc) * nodejs_20: 20.15.1 -> 20.16.0 (cherry picked from commit 35b556d314ff99940619f4f16920542fd5b8f972) * nodejs: 22.5.1 -> 22.6.0 (#333210) (cherry picked from commit 4c38d8a84621ed8c0a4f133ba167cb37f2ab0c9d) * nodejs_22: 22.6.0 -> 22.7.0 (#336556) (cherry picked from commit c455cc3170d68f05b4614c41883a7d417d1c16e0) * nodejs_20: 20.16.0 -> 20.17.0 (#336388) (cherry picked from commit 45db1ff7c1aa8219a83e3fd48034fdf58706fd00) * nodejs_22: 22.7.0 -> 22.8.0 (cherry picked from commit 235ae9c70fbb260384cb6497f45c443002c5fed0) --------- Co-authored-by: K900 Co-authored-by: Bryan Lai Co-authored-by: Ivan Trubach --- pkgs/development/web/nodejs/nodejs.nix | 41 ++++++++++++++----- .../web/nodejs/use-correct-env-in-tests.patch | 7 ---- .../web/nodejs/v18-openssl-3.0.14.patch | 24 +++++++++++ pkgs/development/web/nodejs/v18.nix | 14 ++++++- pkgs/development/web/nodejs/v20.nix | 10 ++--- pkgs/development/web/nodejs/v22.nix | 6 +-- 6 files changed, 73 insertions(+), 29 deletions(-) create mode 100644 pkgs/development/web/nodejs/v18-openssl-3.0.14.patch diff --git a/pkgs/development/web/nodejs/nodejs.nix b/pkgs/development/web/nodejs/nodejs.nix index b7ad9305d68e..e2910b14a46c 100644 --- a/pkgs/development/web/nodejs/nodejs.nix +++ b/pkgs/development/web/nodejs/nodejs.nix @@ -45,7 +45,13 @@ let (builtins.attrNames sharedLibDeps); extraConfigFlags = lib.optionals (!enableNpm) [ "--without-npm" ]; - self = stdenv.mkDerivation { + + package = stdenv.mkDerivation (finalAttrs: + let + /** the final package fixed point, after potential overrides */ + self = finalAttrs.finalPackage; + in + { inherit pname version; src = fetchurl { @@ -55,10 +61,17 @@ let strictDeps = true; - env = lib.optionalAttrs (stdenv.isDarwin && stdenv.isx86_64) { + env = { + # Tell ninja to avoid ANSI sequences, otherwise we don’t see build + # progress in Nix logs. + # + # Note: do not set TERM=dumb environment variable globally, it is used in + # test-ci-js test suite to skip tests that otherwise run fine. + NINJA = "TERM=dumb ninja"; + } // lib.optionalAttrs (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isx86_64) { # Make sure libc++ uses `posix_memalign` instead of `aligned_alloc` on x86_64-darwin. # Otherwise, nodejs would require the 11.0 SDK and macOS 10.15+. - NIX_CFLAGS_COMPILE = "-D__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__=101300"; + NIX_CFLAGS_COMPILE = "-D__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__=101300 -Wno-macro-redefined"; }; depsBuildBuild = [ buildPackages.stdenv.cc openssl libuv zlib icu ]; @@ -138,6 +151,9 @@ let # Note that currently stdenv does not run check phase if build ≠ host. doCheck = true; + # See https://github.com/nodejs/node/issues/22006 + enableParallelChecking = false; + # Some dependencies required for tools/doc/node_modules (and therefore # test-addons, jstest and others) target are not included in the tarball. # Run test targets that do not require network access. @@ -176,11 +192,6 @@ let "test-tls-cli-max-version-1.3" "test-tls-client-auth" "test-tls-sni-option" - ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ - # Disable tests that don’t work under macOS sandbox. - "test-macos-app-sandbox" - "test-os" - "test-os-process-priority" # This is a bit weird, but for some reason fs watch tests fail with # sandbox. "test-fs-promises-watch" @@ -201,6 +212,16 @@ let "test-runner-run" "test-runner-watch-mode" "test-watch-mode-files_watcher" + ] ++ lib.optionals stdenv.buildPlatform.isDarwin [ + # Disable tests that don’t work under macOS sandbox. + "test-macos-app-sandbox" + "test-os" + "test-os-process-priority" + ] ++ lib.optionals (stdenv.buildPlatform.isDarwin && stdenv.buildPlatform.isx86_64) [ + # These tests fail on x86_64-darwin (even without sandbox). + # TODO: revisit at a later date. + "test-fs-readv" + "test-fs-readv-sync" ])}" ]; @@ -295,5 +316,5 @@ let }; passthru.python = python; # to ensure nodeEnv uses the same version - }; -in self + }); +in package diff --git a/pkgs/development/web/nodejs/use-correct-env-in-tests.patch b/pkgs/development/web/nodejs/use-correct-env-in-tests.patch index d2fda8d2cead..070d0e1ddfc3 100644 --- a/pkgs/development/web/nodejs/use-correct-env-in-tests.patch +++ b/pkgs/development/web/nodejs/use-correct-env-in-tests.patch @@ -1,12 +1,5 @@ `/usr/bin/env` is not available. ---- old/test/common/assertSnapshot.js -+++ new/test/common/assertSnapshot.js -@@ -81,2 +81,2 @@ async function spawnAndAssert(filename, transform = (x) => x, { tty = false, ... -- const executable = tty ? 'tools/pseudo-tty.py' : process.execPath; -- const args = tty ? [process.execPath, ...flags, filename] : [...flags, filename]; -+ const executable = tty ? 'python3' : process.execPath; -+ const args = tty ? ['tools/pseudo-tty.py', process.execPath, ...flags, filename] : [...flags, filename]; --- old/test/parallel/test-child-process-default-options.js +++ new/test/parallel/test-child-process-default-options.js @@ -35 +35 @@ if (isWindows) { diff --git a/pkgs/development/web/nodejs/v18-openssl-3.0.14.patch b/pkgs/development/web/nodejs/v18-openssl-3.0.14.patch new file mode 100644 index 000000000000..b63fb8ad1303 --- /dev/null +++ b/pkgs/development/web/nodejs/v18-openssl-3.0.14.patch @@ -0,0 +1,24 @@ +diff --git a/test/parallel/test-tls-alpn-server-client.js b/test/parallel/test-tls-alpn-server-client.js +index 522dd34ad2..3f0ee2a0f9 100644 +--- a/test/parallel/test-tls-alpn-server-client.js ++++ b/test/parallel/test-tls-alpn-server-client.js +@@ -195,7 +195,8 @@ function TestALPNCallback() { + + // Callback picks 2nd preference => undefined => ALPN rejected: + assert.strictEqual(results[1].server, undefined); +- assert.strictEqual(results[1].client.error.code, 'ECONNRESET'); ++ const allowedErrors = ['ECONNRESET', 'ERR_SSL_TLSV1_ALERT_NO_APPLICATION_PROTOCOL']; ++ assert.ok(allowedErrors.includes(results[1].client.error.code), `'${results[1].client.error.code}' was not one of ${allowedErrors}.`); + + TestBadALPNCallback(); + }); +@@ -218,7 +219,8 @@ function TestBadALPNCallback() { + runTest(clientsOptions, serverOptions, function(results) { + // Callback returns 'http/5' => doesn't match client ALPN => error & reset + assert.strictEqual(results[0].server, undefined); +- assert.strictEqual(results[0].client.error.code, 'ECONNRESET'); ++ const allowedErrors = ['ECONNRESET', 'ERR_SSL_TLSV1_ALERT_NO_APPLICATION_PROTOCOL']; ++ assert.ok(allowedErrors.includes(results[0].client.error.code), `'${results[0].client.error.code}' was not one of ${allowedErrors}.`); + + TestALPNOptionsCallback(); + }); diff --git a/pkgs/development/web/nodejs/v18.nix b/pkgs/development/web/nodejs/v18.nix index c1c087f17357..ab2edcf5e8c9 100644 --- a/pkgs/development/web/nodejs/v18.nix +++ b/pkgs/development/web/nodejs/v18.nix @@ -1,4 +1,4 @@ -{ callPackage, lib, overrideCC, pkgs, buildPackages, openssl, python3, fetchpatch2, enableNpm ? true }: +{ callPackage, lib, overrideCC, pkgs, buildPackages, openssl, python311, fetchpatch2, enableNpm ? true }: let # Clang 16+ cannot build Node v18 due to -Wenum-constexpr-conversion errors. @@ -14,7 +14,7 @@ let inherit openssl; stdenv = ensureCompatibleCC pkgs; buildPackages = buildPackages // { stdenv = ensureCompatibleCC buildPackages; }; - python = python3; + python = python311; }; gypPatches = callPackage ./gyp-patches.nix { } ++ [ @@ -32,9 +32,19 @@ buildNodejs { ./node-npm-build-npm-package-logic.patch ./trap-handler-backport.patch ./use-correct-env-in-tests.patch + ./v18-openssl-3.0.14.patch (fetchpatch2 { url = "https://github.com/nodejs/node/commit/534c122de166cb6464b489f3e6a9a544ceb1c913.patch"; hash = "sha256-4q4LFsq4yU1xRwNsM1sJoNVphJCnxaVe2IyL6AeHJ/I="; }) + (fetchpatch2 { + url = "https://github.com/nodejs/node/commit/87598d4b63ef2c827a2bebdfa0f1540c35718519.patch"; + hash = "sha256-JJi8z9aaWnu/y3nZGOSUfeNzNSCYzD9dzoHXaGkeaEA="; + includes = ["test/common/assertSnapshot.js"]; + }) + (fetchpatch2 { + url = "https://github.com/nodejs/node/commit/d0a6b605fba6cd69a82e6f12ff0363eef8fe1ee9.patch"; + hash = "sha256-TfYal/PikRZHL6zpAlC3SmkYXCe+/8Gs83dLX/X/P/k="; + }) ] ++ gypPatches; } diff --git a/pkgs/development/web/nodejs/v20.nix b/pkgs/development/web/nodejs/v20.nix index d8471cc0cc32..84b39868e611 100644 --- a/pkgs/development/web/nodejs/v20.nix +++ b/pkgs/development/web/nodejs/v20.nix @@ -1,4 +1,4 @@ -{ callPackage, fetchpatch2, openssl, python3, enableNpm ? true }: +{ callPackage, openssl, python3, enableNpm ? true }: let buildNodejs = callPackage ./nodejs.nix { @@ -12,16 +12,12 @@ let in buildNodejs { inherit enableNpm; - version = "20.15.1"; - sha256 = "sha256-/dU6VynZNmkaKhFRBG+0iXchy4sPyir5V4I6m0D+DDQ="; + version = "20.17.0"; + sha256 = "9abf03ac23362c60387ebb633a516303637145cb3c177be3348b16880fd8b28c"; patches = [ ./disable-darwin-v8-system-instrumentation-node19.patch ./bypass-darwin-xcrun-node16.patch ./node-npm-build-npm-package-logic.patch ./use-correct-env-in-tests.patch - (fetchpatch2 { - url = "https://github.com/nodejs/node/commit/534c122de166cb6464b489f3e6a9a544ceb1c913.patch"; - hash = "sha256-4q4LFsq4yU1xRwNsM1sJoNVphJCnxaVe2IyL6AeHJ/I="; - }) ] ++ gypPatches; } diff --git a/pkgs/development/web/nodejs/v22.nix b/pkgs/development/web/nodejs/v22.nix index 44737d2ba8ec..6f03749e2d22 100644 --- a/pkgs/development/web/nodejs/v22.nix +++ b/pkgs/development/web/nodejs/v22.nix @@ -1,4 +1,4 @@ -{ callPackage, fetchpatch2, openssl, python3, enableNpm ? true }: +{ callPackage, openssl, python3, enableNpm ? true }: let buildNodejs = callPackage ./nodejs.nix { @@ -12,8 +12,8 @@ let in buildNodejs { inherit enableNpm; - version = "22.4.1"; - sha256 = "sha256-ZfyFf1qoJWqvyQCzRMARXJrq4loCVB/Vzg29Tf0cX7k="; + version = "22.8.0"; + sha256 = "f130e82176d1ee0702d99afc1995d0061bf8ed357c38834a32a08c9ef74f1ac7"; patches = [ ./disable-darwin-v8-system-instrumentation-node19.patch ./bypass-darwin-xcrun-node16.patch