2021-02-05 17:12:51 +00:00
|
|
|
{ lib, stdenv, fetchurl, openssl, python, zlib, libuv, util-linux, http-parser
|
2022-04-27 09:35:20 +00:00
|
|
|
, pkg-config, which, buildPackages
|
2021-12-06 16:07:01 +00:00
|
|
|
# for `.pkgs` attribute
|
|
|
|
, callPackage
|
2020-04-24 23:36:52 +00:00
|
|
|
# Updater dependencies
|
|
|
|
, writeScript, coreutils, gnugrep, jq, curl, common-updater-scripts, nix, runtimeShell
|
|
|
|
, gnupg
|
|
|
|
, darwin, xcbuild
|
|
|
|
, procps, icu
|
|
|
|
}:
|
|
|
|
|
|
|
|
{ enableNpm ? true, version, sha256, patches ? [] } @args:
|
|
|
|
|
|
|
|
let
|
|
|
|
inherit (darwin.apple_sdk.frameworks) CoreServices ApplicationServices;
|
|
|
|
|
2023-02-02 18:25:31 +00:00
|
|
|
majorVersion = lib.versions.major version;
|
|
|
|
minorVersion = lib.versions.minor version;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-02-10 20:34:41 +00:00
|
|
|
pname = if enableNpm then "nodejs" else "nodejs-slim";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-02-02 18:25:31 +00:00
|
|
|
useSharedHttpParser = !stdenv.isDarwin && lib.versionOlder "${majorVersion}.${minorVersion}" "11.4";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-02-02 18:25:31 +00:00
|
|
|
sharedLibDeps = { inherit openssl zlib libuv; } // (lib.optionalAttrs useSharedHttpParser { inherit http-parser; });
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-02-02 18:25:31 +00:00
|
|
|
sharedConfigureFlags = lib.concatMap (name: [
|
2020-04-24 23:36:52 +00:00
|
|
|
"--shared-${name}"
|
2023-02-02 18:25:31 +00:00
|
|
|
"--shared-${name}-libpath=${lib.getLib sharedLibDeps.${name}}/lib"
|
2020-04-24 23:36:52 +00:00
|
|
|
/** Closure notes: we explicitly avoid specifying --shared-*-includes,
|
|
|
|
* as that would put the paths into bin/nodejs.
|
2021-02-05 17:12:51 +00:00
|
|
|
* Including pkg-config in build inputs would also have the same effect!
|
2020-04-24 23:36:52 +00:00
|
|
|
*/
|
|
|
|
]) (builtins.attrNames sharedLibDeps) ++ [
|
|
|
|
"--with-intl=system-icu"
|
|
|
|
];
|
|
|
|
|
|
|
|
copyLibHeaders =
|
|
|
|
map
|
2023-02-02 18:25:31 +00:00
|
|
|
(name: "${lib.getDev sharedLibDeps.${name}}/include/*")
|
2020-04-24 23:36:52 +00:00
|
|
|
(builtins.attrNames sharedLibDeps);
|
|
|
|
|
2023-02-02 18:25:31 +00:00
|
|
|
extraConfigFlags = lib.optionals (!enableNpm) [ "--without-npm" ];
|
2021-12-06 16:07:01 +00:00
|
|
|
self = stdenv.mkDerivation {
|
2022-02-10 20:34:41 +00:00
|
|
|
inherit pname version;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
src = fetchurl {
|
|
|
|
url = "https://nodejs.org/dist/v${version}/node-v${version}.tar.xz";
|
|
|
|
inherit sha256;
|
|
|
|
};
|
|
|
|
|
2022-04-27 09:35:20 +00:00
|
|
|
CC_host = "cc";
|
|
|
|
CXX_host = "c++";
|
|
|
|
depsBuildBuild = [ buildPackages.stdenv.cc openssl libuv zlib ];
|
|
|
|
|
2023-02-02 18:25:31 +00:00
|
|
|
buildInputs = lib.optionals stdenv.isDarwin [ CoreServices ApplicationServices ]
|
2020-04-24 23:36:52 +00:00
|
|
|
++ [ zlib libuv openssl http-parser icu ];
|
|
|
|
|
2021-02-16 17:04:54 +00:00
|
|
|
nativeBuildInputs = [ which pkg-config python ]
|
2023-02-02 18:25:31 +00:00
|
|
|
++ lib.optionals stdenv.isDarwin [ xcbuild ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-12-19 01:06:50 +00:00
|
|
|
outputs = [ "out" "libv8" ];
|
|
|
|
setOutputFlags = false;
|
|
|
|
moveToDev = false;
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
configureFlags = let
|
|
|
|
isCross = stdenv.hostPlatform != stdenv.buildPlatform;
|
2021-03-09 03:18:52 +00:00
|
|
|
inherit (stdenv.hostPlatform) gcc isAarch32;
|
2023-02-02 18:25:31 +00:00
|
|
|
in sharedConfigureFlags ++ lib.optionals (lib.versionOlder version "19") [
|
2020-04-24 23:36:52 +00:00
|
|
|
"--without-dtrace"
|
2023-02-02 18:25:31 +00:00
|
|
|
] ++ (lib.optionals isCross [
|
2020-04-24 23:36:52 +00:00
|
|
|
"--cross-compiling"
|
|
|
|
"--without-intl"
|
|
|
|
"--without-snapshot"
|
2022-04-27 09:35:20 +00:00
|
|
|
"--dest-cpu=${let platform = stdenv.hostPlatform; in
|
|
|
|
if platform.isAarch32 then "arm"
|
|
|
|
else if platform.isAarch64 then "arm64"
|
|
|
|
else if platform.isMips32 && platform.isLittleEndian then "mipsel"
|
|
|
|
else if platform.isMips32 && !platform.isLittleEndian then "mips"
|
|
|
|
else if platform.isMips64 && platform.isLittleEndian then "mips64el"
|
|
|
|
else if platform.isPower && platform.is32bit then "ppc"
|
|
|
|
else if platform.isPower && platform.is64bit then "ppc64"
|
|
|
|
else if platform.isx86_64 then "x86_64"
|
|
|
|
else if platform.isx86_32 then "x86"
|
|
|
|
else if platform.isS390 && platform.is64bit then "s390x"
|
|
|
|
else if platform.isRiscV && platform.is64bit then "riscv64"
|
|
|
|
else throw "unsupported cpu ${stdenv.hostPlatform.uname.processor}"}"
|
2023-02-02 18:25:31 +00:00
|
|
|
]) ++ (lib.optionals (isCross && isAarch32 && lib.hasAttr "fpu" gcc) [
|
2021-02-05 17:12:51 +00:00
|
|
|
"--with-arm-fpu=${gcc.fpu}"
|
2023-02-02 18:25:31 +00:00
|
|
|
]) ++ (lib.optionals (isCross && isAarch32 && lib.hasAttr "float-abi" gcc) [
|
2021-02-05 17:12:51 +00:00
|
|
|
"--with-arm-float-abi=${gcc.float-abi}"
|
2020-04-24 23:36:52 +00:00
|
|
|
]) ++ extraConfigFlags;
|
|
|
|
|
|
|
|
configurePlatforms = [];
|
|
|
|
|
|
|
|
dontDisableStatic = true;
|
|
|
|
|
|
|
|
enableParallelBuilding = true;
|
|
|
|
|
2023-04-29 16:46:19 +00:00
|
|
|
# Don't allow enabling content addressed conversion as `nodejs`
|
|
|
|
# checksums it's image before conversion happens and image loading
|
|
|
|
# breaks:
|
|
|
|
# $ nix build -f. nodejs --arg config '{ contentAddressedByDefault = true; }'
|
|
|
|
# $ ./result/bin/node
|
|
|
|
# Check failed: VerifyChecksum(blob).
|
|
|
|
__contentAddressed = false;
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
passthru.interpreterName = "nodejs";
|
|
|
|
|
2021-12-06 16:07:01 +00:00
|
|
|
passthru.pkgs = callPackage ../../node-packages/default.nix {
|
|
|
|
nodejs = self;
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
setupHook = ./setup-hook.sh;
|
|
|
|
|
|
|
|
pos = builtins.unsafeGetAttrPos "version" args;
|
|
|
|
|
|
|
|
inherit patches;
|
|
|
|
|
|
|
|
postPatch = ''
|
|
|
|
patchShebangs .
|
|
|
|
|
|
|
|
# fix tests
|
|
|
|
for a in test/parallel/test-child-process-env.js \
|
|
|
|
test/parallel/test-child-process-exec-env.js \
|
|
|
|
test/parallel/test-child-process-default-options.js \
|
|
|
|
test/fixtures/syntax/good_syntax_shebang.js \
|
|
|
|
test/fixtures/syntax/bad_syntax_shebang.js ; do
|
|
|
|
substituteInPlace $a \
|
|
|
|
--replace "/usr/bin/env" "${coreutils}/bin/env"
|
|
|
|
done
|
2023-02-02 18:25:31 +00:00
|
|
|
'' + lib.optionalString stdenv.isDarwin ''
|
2020-04-24 23:36:52 +00:00
|
|
|
sed -i -e "s|tr1/type_traits|type_traits|g" \
|
|
|
|
-e "s|std::tr1|std|" src/util.h
|
|
|
|
'';
|
|
|
|
|
2023-02-02 18:25:31 +00:00
|
|
|
nativeCheckInputs = [ procps ];
|
2020-04-24 23:36:52 +00:00
|
|
|
doCheck = false; # fails 4 out of 1453 tests
|
|
|
|
|
|
|
|
postInstall = ''
|
|
|
|
PATH=$out/bin:$PATH patchShebangs $out
|
|
|
|
|
2023-02-02 18:25:31 +00:00
|
|
|
${lib.optionalString (enableNpm && stdenv.hostPlatform == stdenv.buildPlatform) ''
|
2020-04-24 23:36:52 +00:00
|
|
|
mkdir -p $out/share/bash-completion/completions/
|
2022-04-27 09:35:20 +00:00
|
|
|
HOME=$TMPDIR $out/bin/npm completion > $out/share/bash-completion/completions/npm
|
2020-04-24 23:36:52 +00:00
|
|
|
for dir in "$out/lib/node_modules/npm/man/"*; do
|
|
|
|
mkdir -p $out/share/man/$(basename "$dir")
|
|
|
|
for page in "$dir"/*; do
|
|
|
|
ln -rs $page $out/share/man/$(basename "$dir")
|
|
|
|
done
|
|
|
|
done
|
|
|
|
''}
|
|
|
|
|
|
|
|
# install the missing headers for node-gyp
|
2023-02-02 18:25:31 +00:00
|
|
|
cp -r ${lib.concatStringsSep " " copyLibHeaders} $out/include/node
|
2021-12-19 01:06:50 +00:00
|
|
|
|
|
|
|
# assemble a static v8 library and put it in the 'libv8' output
|
|
|
|
mkdir -p $libv8/lib
|
|
|
|
pushd out/Release/obj.target
|
|
|
|
find . -path "./torque_*/**/*.o" -or -path "./v8*/**/*.o" | sort -u >files
|
|
|
|
${if stdenv.buildPlatform.isGnu then ''
|
|
|
|
ar -cqs $libv8/lib/libv8.a @files
|
|
|
|
'' else ''
|
|
|
|
cat files | while read -r file; do
|
|
|
|
ar -cqS $libv8/lib/libv8.a $file
|
|
|
|
done
|
|
|
|
''}
|
|
|
|
popd
|
|
|
|
|
|
|
|
# copy v8 headers
|
|
|
|
cp -r deps/v8/include $libv8/
|
|
|
|
|
|
|
|
# create a pkgconfig file for v8
|
|
|
|
major=$(grep V8_MAJOR_VERSION deps/v8/include/v8-version.h | cut -d ' ' -f 3)
|
|
|
|
minor=$(grep V8_MINOR_VERSION deps/v8/include/v8-version.h | cut -d ' ' -f 3)
|
|
|
|
patch=$(grep V8_PATCH_LEVEL deps/v8/include/v8-version.h | cut -d ' ' -f 3)
|
|
|
|
mkdir -p $libv8/lib/pkgconfig
|
|
|
|
cat > $libv8/lib/pkgconfig/v8.pc << EOF
|
|
|
|
Name: v8
|
|
|
|
Description: V8 JavaScript Engine
|
|
|
|
Version: $major.$minor.$patch
|
|
|
|
Libs: -L$libv8/lib -lv8 -pthread -licui18n
|
|
|
|
Cflags: -I$libv8/include
|
|
|
|
EOF
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
passthru.updateScript = import ./update.nix {
|
|
|
|
inherit writeScript coreutils gnugrep jq curl common-updater-scripts gnupg nix runtimeShell;
|
2021-02-05 17:12:51 +00:00
|
|
|
inherit lib;
|
2020-04-24 23:36:52 +00:00
|
|
|
inherit majorVersion;
|
|
|
|
};
|
|
|
|
|
2023-02-02 18:25:31 +00:00
|
|
|
meta = with lib; {
|
2020-04-24 23:36:52 +00:00
|
|
|
description = "Event-driven I/O framework for the V8 JavaScript engine";
|
|
|
|
homepage = "https://nodejs.org";
|
2021-10-17 09:34:42 +00:00
|
|
|
changelog = "https://github.com/nodejs/node/releases/tag/v${version}";
|
2020-04-24 23:36:52 +00:00
|
|
|
license = licenses.mit;
|
2020-07-18 16:06:22 +00:00
|
|
|
maintainers = with maintainers; [ goibhniu gilligan cko marsam ];
|
2020-04-24 23:36:52 +00:00
|
|
|
platforms = platforms.linux ++ platforms.darwin;
|
2021-05-03 20:48:10 +00:00
|
|
|
mainProgram = "node";
|
2023-05-24 13:37:59 +00:00
|
|
|
knownVulnerabilities = optional (versionOlder version "18") "This NodeJS release has reached its end of life. See https://nodejs.org/en/about/releases/.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
passthru.python = python; # to ensure nodeEnv uses the same version
|
2021-12-06 16:07:01 +00:00
|
|
|
};
|
|
|
|
in self
|