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