2012-09-13 13:35:35 +01:00
|
|
|
{ stdenv, runCommand, nodejs, neededNatives}:
|
2012-07-25 22:46:21 +01:00
|
|
|
|
2012-09-18 17:08:16 +01:00
|
|
|
args @ { src, deps ? [], flags ? [], ... }:
|
2012-07-25 22:46:21 +01:00
|
|
|
|
2012-09-13 13:35:35 +01:00
|
|
|
with stdenv.lib;
|
|
|
|
|
|
|
|
let npmFlags = concatStringsSep " " (map (v: "--${v}") flags);
|
|
|
|
sources = runCommand "node-sources" {} ''
|
|
|
|
tar xf ${nodejs.src}
|
2012-09-20 19:45:31 +01:00
|
|
|
mv *node* $out
|
2012-09-13 13:35:35 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
in
|
2012-07-25 22:46:21 +01:00
|
|
|
stdenv.mkDerivation ({
|
|
|
|
unpackPhase = "true";
|
|
|
|
|
|
|
|
configurePhase = ''
|
|
|
|
runHook preConfigure
|
|
|
|
mkdir node_modules
|
|
|
|
${stdenv.lib.concatStrings (map (dep: ''
|
|
|
|
ln -sv ${dep}/node_modules/${(builtins.parseDrvName dep.name).name} node_modules/
|
|
|
|
'') deps)}
|
|
|
|
export HOME=$(pwd)
|
|
|
|
runHook postConfigure
|
|
|
|
'';
|
|
|
|
|
|
|
|
buildPhase = ''
|
|
|
|
runHook preBuild
|
2012-09-13 13:35:35 +01:00
|
|
|
${nodejs}/bin/npm --registry http://www.example.com --nodedir=${sources} install ${src} ${npmFlags}
|
2012-07-25 22:46:21 +01:00
|
|
|
runHook postBuild
|
|
|
|
'';
|
|
|
|
|
2012-09-13 13:35:35 +01:00
|
|
|
buildNativeInputs = neededNatives;
|
|
|
|
|
2012-07-25 22:46:21 +01:00
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
|
|
|
mkdir $out
|
|
|
|
mv node_modules $out
|
|
|
|
if [ -d "$out/node_modules/.bin" ]; then
|
|
|
|
ln -sv node_modules/.bin $out/bin
|
|
|
|
find -L $out/node_modules/.bin/* -type f -print0 | \
|
|
|
|
xargs -0 sed --follow-symlinks -i 's@#!/usr/bin/env node@#!${nodejs}/bin/node@'
|
|
|
|
fi
|
|
|
|
runHook postInstall
|
|
|
|
'';
|
2012-08-22 20:35:00 +01:00
|
|
|
|
|
|
|
preFixup = ''
|
|
|
|
find $out -type f -print0 | xargs -0 sed -i 's|${src}|${src.name}|g'
|
|
|
|
'';
|
2012-07-25 22:46:21 +01:00
|
|
|
} // args)
|