1{ stdenv, fetchurl, openssl, python2, zlib, libuv, utillinux, http-parser
2, pkgconfig, which
3# Updater dependencies
4, writeScript, coreutils, gnugrep, jq, curl, common-updater-scripts, nix, runtimeShell
5, gnupg
6, darwin, xcbuild
7, procps
8}:
9
10with stdenv.lib;
11
12{ enableNpm ? true, version, sha256, patches ? [] } @args:
13
14let
15 inherit (darwin.apple_sdk.frameworks) CoreServices ApplicationServices;
16
17 majorVersion = versions.major version;
18 minorVersion = versions.minor version;
19
20 baseName = if enableNpm then "nodejs" else "nodejs-slim";
21
22 useSharedHttpParser = !stdenv.isDarwin && versionOlder "${majorVersion}.${minorVersion}" "11.4";
23
24 sharedLibDeps = { inherit openssl zlib libuv; } // (optionalAttrs useSharedHttpParser { inherit http-parser; });
25
26 sharedConfigureFlags = concatMap (name: [
27 "--shared-${name}"
28 "--shared-${name}-libpath=${getLib sharedLibDeps.${name}}/lib"
29 /** Closure notes: we explicitly avoid specifying --shared-*-includes,
30 * as that would put the paths into bin/nodejs.
31 * Including pkgconfig in build inputs would also have the same effect!
32 */
33 ]) (builtins.attrNames sharedLibDeps);
34
35 copyLibHeaders =
36 map
37 (name: "${getDev sharedLibDeps.${name}}/include/*")
38 (builtins.attrNames sharedLibDeps);
39
40 extraConfigFlags = optionals (!enableNpm) [ "--without-npm" ];
41in
42
43 stdenv.mkDerivation {
44 inherit version;
45
46 name = "${baseName}-${version}";
47
48 src = fetchurl {
49 url = "https://nodejs.org/dist/v${version}/node-v${version}.tar.xz";
50 inherit sha256;
51 };
52
53 buildInputs = optionals stdenv.isDarwin [ CoreServices ApplicationServices ]
54 ++ [ python2 zlib libuv openssl http-parser ];
55
56 nativeBuildInputs = [ which utillinux ]
57 ++ optionals stdenv.isDarwin [ pkgconfig xcbuild ];
58
59 configureFlags = sharedConfigureFlags ++ [ "--without-dtrace" ] ++ extraConfigFlags;
60
61 dontDisableStatic = true;
62
63 enableParallelBuilding = true;
64
65 passthru.interpreterName = "nodejs";
66
67 setupHook = ./setup-hook.sh;
68
69 pos = builtins.unsafeGetAttrPos "version" args;
70
71 inherit patches;
72
73 postPatch = ''
74 patchShebangs .
75 sed -i 's/raise.*No Xcode or CLT version detected.*/version = "7.0.0"/' tools/gyp/pylib/gyp/xcode_emulation.py
76
77 # fix tests
78 for a in test/parallel/test-child-process-env.js \
79 test/parallel/test-child-process-exec-env.js \
80 test/parallel/test-child-process-default-options.js \
81 test/fixtures/syntax/good_syntax_shebang.js \
82 test/fixtures/syntax/bad_syntax_shebang.js ; do
83 substituteInPlace $a \
84 --replace "/usr/bin/env" "${coreutils}/bin/env"
85 done
86 '' + optionalString stdenv.isDarwin ''
87 sed -i -e "s|tr1/type_traits|type_traits|g" \
88 -e "s|std::tr1|std|" src/util.h
89 '';
90
91 checkInputs = [ procps ];
92 doCheck = false; # fails 4 out of 1453 tests
93
94 postInstall = ''
95 PATH=$out/bin:$PATH patchShebangs $out
96
97 ${optionalString enableNpm ''
98 mkdir -p $out/share/bash-completion/completions/
99 $out/bin/npm completion > $out/share/bash-completion/completions/npm
100 ''}
101
102 # install the missing headers for node-gyp
103 cp -r ${concatStringsSep " " copyLibHeaders} $out/include/node
104 '';
105
106 passthru.updateScript = import ./update.nix {
107 inherit stdenv writeScript coreutils gnugrep jq curl common-updater-scripts gnupg nix runtimeShell;
108 inherit (stdenv) lib;
109 inherit majorVersion;
110 };
111
112 meta = {
113 description = "Event-driven I/O framework for the V8 JavaScript engine";
114 homepage = https://nodejs.org;
115 license = licenses.mit;
116 maintainers = with maintainers; [ goibhniu gilligan cko ];
117 platforms = platforms.linux ++ platforms.darwin;
118 };
119
120 passthru.python = python2; # to ensure nodeEnv uses the same version
121}