1{ stdenv, fetchurl, openssl, python2, zlib, libuv, v8, utillinux, http-parser
2, pkgconfig, runCommand, which, libtool, fetchpatch
3, callPackage
4, darwin ? null
5, enableNpm ? true
6}:
7
8with stdenv.lib;
9
10let
11
12 inherit (darwin.apple_sdk.frameworks) CoreServices ApplicationServices;
13
14 sharedLibDeps = { inherit openssl zlib libuv; } // (optionalAttrs (!stdenv.isDarwin) { inherit http-parser; });
15
16 sharedConfigureFlags = concatMap (name: [
17 "--shared-${name}"
18 "--shared-${name}-libpath=${getLib sharedLibDeps.${name}}/lib"
19 /** Closure notes: we explicitly avoid specifying --shared-*-includes,
20 * as that would put the paths into bin/nodejs.
21 * Including pkgconfig in build inputs would also have the same effect!
22 */
23 ]) (builtins.attrNames sharedLibDeps);
24
25 extraConfigFlags = optionals (!enableNpm) [ "--without-npm" ];
26in
27
28 rec {
29
30 buildInputs = optionals stdenv.isDarwin [ CoreServices ApplicationServices ]
31 ++ [ python2 which zlib libuv openssl ]
32 ++ optionals stdenv.isLinux [ utillinux http-parser ]
33 ++ optionals stdenv.isDarwin [ pkgconfig libtool ];
34
35 configureFlags = sharedConfigureFlags ++ [ "--without-dtrace" ] ++ extraConfigFlags;
36
37 dontDisableStatic = true;
38
39 enableParallelBuilding = true;
40
41 passthru.interpreterName = "nodejs";
42
43
44 setupHook = ./setup-hook.sh;
45
46 patches = optionals stdenv.isDarwin [ ./no-xcode.patch ];
47
48 preBuild = optionalString stdenv.isDarwin ''
49 sed -i -e "s|tr1/type_traits|type_traits|g" \
50 -e "s|std::tr1|std|" src/util.h
51 '';
52
53 prePatch = ''
54 patchShebangs .
55 sed -i 's/raise.*No Xcode or CLT version detected.*/version = "7.0.0"/' tools/gyp/pylib/gyp/xcode_emulation.py
56 '';
57
58 postInstall = ''
59 paxmark m $out/bin/node
60 PATH=$out/bin:$PATH patchShebangs $out
61
62 ${optionalString enableNpm ''
63 mkdir -p $out/share/bash-completion/completions/
64 $out/bin/npm completion > $out/share/bash-completion/completions/npm
65 ''}
66 '';
67
68 meta = {
69 description = "Event-driven I/O framework for the V8 JavaScript engine";
70 homepage = https://nodejs.org;
71 license = licenses.mit;
72 maintainers = with maintainers; [ goibhniu havvy gilligan cko ];
73 platforms = platforms.linux ++ platforms.darwin;
74 };
75
76 passthru.python = python2; # to ensure nodeEnv uses the same version
77}