nixpkgs/pkgs/development/web/nodejs/nodejs.nix

122 lines
3.8 KiB
Nix
Raw Normal View History

{ stdenv, fetchurl, openssl, python2, zlib, libuv, utillinux, http-parser
, pkgconfig, which
2018-02-18 14:19:01 +00:00
# Updater dependencies
, writeScript, coreutils, gnugrep, jq, curl, common-updater-scripts, nix
, gnupg
, darwin, xcbuild
2018-08-08 21:17:04 +00:00
, procps
2016-04-25 14:10:10 +00:00
}:
with stdenv.lib;
2016-04-25 14:10:10 +00:00
{ enableNpm ? true, version, sha256, patches ? [] } @args:
2016-04-25 14:10:10 +00:00
let
inherit (darwin.apple_sdk.frameworks) CoreServices ApplicationServices;
2016-04-25 14:10:10 +00:00
2018-10-23 19:22:50 +00:00
majorVersion = versions.major version;
minorVersion = versions.minor version;
baseName = if enableNpm then "nodejs" else "nodejs-slim";
2018-10-23 19:22:50 +00:00
useSharedHttpParser = !stdenv.isDarwin && versionOlder "${majorVersion}.${minorVersion}" "11.4";
sharedLibDeps = { inherit openssl zlib libuv; } // (optionalAttrs useSharedHttpParser { inherit http-parser; });
sharedConfigureFlags = concatMap (name: [
2016-04-25 14:10:10 +00:00
"--shared-${name}"
"--shared-${name}-libpath=${getLib sharedLibDeps.${name}}/lib"
/** Closure notes: we explicitly avoid specifying --shared-*-includes,
* as that would put the paths into bin/nodejs.
* Including pkgconfig in build inputs would also have the same effect!
*/
]) (builtins.attrNames sharedLibDeps);
2016-04-25 14:10:10 +00:00
copyLibHeaders =
map
(name: "${getDev sharedLibDeps.${name}}/include/*")
(builtins.attrNames sharedLibDeps);
extraConfigFlags = optionals (!enableNpm) [ "--without-npm" ];
in
2016-04-25 14:10:10 +00:00
stdenv.mkDerivation {
inherit version;
name = "${baseName}-${version}";
src = fetchurl {
2018-09-11 03:28:05 +00:00
url = "https://nodejs.org/dist/v${version}/node-v${version}.tar.xz";
inherit sha256;
};
2016-04-25 14:10:10 +00:00
buildInputs = optionals stdenv.isDarwin [ CoreServices ApplicationServices ]
++ [ python2 zlib libuv openssl http-parser ];
nativeBuildInputs = [ which utillinux ]
++ optionals stdenv.isDarwin [ pkgconfig xcbuild ];
2016-04-25 14:10:10 +00:00
configureFlags = sharedConfigureFlags ++ [ "--without-dtrace" ] ++ extraConfigFlags;
2016-04-25 14:10:10 +00:00
dontDisableStatic = true;
2016-04-25 14:10:10 +00:00
enableParallelBuilding = true;
passthru.interpreterName = "nodejs";
2016-04-25 14:10:10 +00:00
setupHook = ./setup-hook.sh;
pos = builtins.unsafeGetAttrPos "version" args;
inherit patches;
2018-08-08 21:17:04 +00:00
postPatch = ''
patchShebangs .
sed -i 's/raise.*No Xcode or CLT version detected.*/version = "7.0.0"/' tools/gyp/pylib/gyp/xcode_emulation.py
2018-08-08 21:17:04 +00:00
# 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
'' + optionalString stdenv.isDarwin ''
sed -i -e "s|tr1/type_traits|type_traits|g" \
-e "s|std::tr1|std|" src/util.h
'';
2016-04-25 14:10:10 +00:00
2018-08-08 21:17:04 +00:00
checkInputs = [ procps ];
doCheck = false; # fails 4 out of 1453 tests
postInstall = ''
PATH=$out/bin:$PATH patchShebangs $out
2016-12-11 13:57:49 +00:00
${optionalString enableNpm ''
2016-12-11 13:57:49 +00:00
mkdir -p $out/share/bash-completion/completions/
$out/bin/npm completion > $out/share/bash-completion/completions/npm
''}
# install the missing headers for node-gyp
cp -r ${concatStringsSep " " copyLibHeaders} $out/include/node
'';
2016-04-25 14:10:10 +00:00
2018-02-18 14:19:01 +00:00
passthru.updateScript = import ./update.nix {
2018-12-03 00:49:37 +00:00
inherit stdenv writeScript coreutils gnugrep jq curl common-updater-scripts gnupg nix;
2018-02-18 14:19:01 +00:00
inherit (stdenv) lib;
2018-10-23 19:22:50 +00:00
inherit majorVersion;
2018-02-18 14:19:01 +00:00
};
meta = {
description = "Event-driven I/O framework for the V8 JavaScript engine";
homepage = https://nodejs.org;
license = licenses.mit;
maintainers = with maintainers; [ goibhniu gilligan cko ];
platforms = platforms.linux ++ platforms.darwin;
};
passthru.python = python2; # to ensure nodeEnv uses the same version
2016-04-25 14:10:10 +00:00
}