From baa62239046f4bd8162c0a03009faf48e8f606db Mon Sep 17 00:00:00 2001 From: Mathijs Kwik Date: Thu, 13 Sep 2012 14:35:35 +0200 Subject: [PATCH] node-packages: ability to build npms that have native extensions --- .../web/nodejs/build-node-package.nix | 18 +++++++++++++++--- pkgs/top-level/all-packages.nix | 1 + pkgs/top-level/node-packages.nix | 5 +++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/pkgs/development/web/nodejs/build-node-package.nix b/pkgs/development/web/nodejs/build-node-package.nix index 98136709170..b12e2669f06 100644 --- a/pkgs/development/web/nodejs/build-node-package.nix +++ b/pkgs/development/web/nodejs/build-node-package.nix @@ -1,7 +1,16 @@ -{ stdenv, nodejs }: +{ stdenv, runCommand, nodejs, neededNatives}: -args @ { src, deps, ... }: +args @ { src, deps ? [], nativeDeps ? [], flags ? [], ... }: +with stdenv.lib; + +let npmFlags = concatStringsSep " " (map (v: "--${v}") flags); + sources = runCommand "node-sources" {} '' + tar xf ${nodejs.src} + mv node-v${nodejs.version} $out + ''; + +in stdenv.mkDerivation ({ unpackPhase = "true"; @@ -17,10 +26,13 @@ stdenv.mkDerivation ({ buildPhase = '' runHook preBuild - ${nodejs}/bin/npm --registry http://www.example.com install ${src} + ${nodejs}/bin/npm --registry http://www.example.com --nodedir=${sources} install ${src} ${npmFlags} runHook postBuild ''; + buildNativeInputs = neededNatives; + buildInputs = nativeDeps; + installPhase = '' runHook preInstall mkdir $out diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 54d50feb875..cf6ad3172dc 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -990,6 +990,7 @@ let nodePackages = recurseIntoAttrs (import ./node-packages.nix { inherit pkgs stdenv nodejs fetchurl; + neededNatives = [python] ++ lib.optional (lib.elem system lib.platforms.linux) utillinux; }); ldns = callPackage ../development/libraries/ldns { }; diff --git a/pkgs/top-level/node-packages.nix b/pkgs/top-level/node-packages.nix index 7c083c7e0ee..2d5f6ba3ed9 100644 --- a/pkgs/top-level/node-packages.nix +++ b/pkgs/top-level/node-packages.nix @@ -1,8 +1,9 @@ -{ pkgs, stdenv, nodejs, fetchurl }: +{ pkgs, stdenv, nodejs, fetchurl, neededNatives }: let self = { buildNodePackage = import ../development/web/nodejs/build-node-package.nix { - inherit stdenv nodejs; + inherit stdenv nodejs neededNatives; + inherit (pkgs) runCommand; }; patchLatest = srcAttrs: