2012-09-13 14:35:35 +02:00
|
|
|
{ stdenv, runCommand, nodejs, neededNatives}:
|
2012-07-25 23:46:21 +02:00
|
|
|
|
2013-08-21 00:56:13 +02:00
|
|
|
args @ { name, src, deps ? [], peerDependencies ? [], flags ? [], ... }:
|
2012-07-25 23:46:21 +02:00
|
|
|
|
2012-09-13 14:35:35 +02:00
|
|
|
with stdenv.lib;
|
|
|
|
|
2013-06-05 18:25:41 +02:00
|
|
|
let
|
|
|
|
npmFlags = concatStringsSep " " (map (v: "--${v}") flags);
|
2012-09-13 14:35:35 +02:00
|
|
|
|
2013-06-05 18:25:41 +02:00
|
|
|
sources = runCommand "node-sources" {} ''
|
|
|
|
tar xf ${nodejs.src}
|
|
|
|
mv *node* $out
|
|
|
|
'';
|
2012-09-13 14:35:35 +02:00
|
|
|
in
|
2012-07-25 23:46:21 +02:00
|
|
|
stdenv.mkDerivation ({
|
|
|
|
unpackPhase = "true";
|
|
|
|
|
|
|
|
configurePhase = ''
|
|
|
|
runHook preConfigure
|
|
|
|
mkdir node_modules
|
2013-08-21 00:56:13 +02:00
|
|
|
${concatStrings (concatMap (dep: map (name: ''
|
|
|
|
ln -sv ${dep}/lib/node_modules/${name} node_modules/
|
|
|
|
'') dep.names) deps)}
|
|
|
|
${concatStrings (concatMap (dep: map (name: ''
|
|
|
|
ln -sv ${dep}/lib/node_modules/${name} node_modules/
|
|
|
|
'') dep.names) peerDependencies)}
|
2012-07-25 23:46:21 +02:00
|
|
|
export HOME=$(pwd)
|
|
|
|
runHook postConfigure
|
|
|
|
'';
|
|
|
|
|
|
|
|
buildPhase = ''
|
|
|
|
runHook preBuild
|
2013-08-21 00:56:13 +02:00
|
|
|
npm --registry http://www.example.com --nodedir=${sources} install ${concatStringsSep " " src} ${npmFlags}
|
2012-07-25 23:46:21 +02:00
|
|
|
runHook postBuild
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
2013-07-27 19:23:35 +02:00
|
|
|
mkdir -p $out/lib/node_modules
|
2013-08-21 00:56:13 +02:00
|
|
|
${concatStrings (map (name: ''
|
|
|
|
mv node_modules/${name} $out/lib/node_modules
|
|
|
|
rm -fR $out/lib/node_modules/${name}/node_modules
|
|
|
|
ln -sv $out/.dependent-node-modules $out/lib/node_modules/${name}/node_modules
|
|
|
|
if [ -e "$out/lib/node_modules/${name}/man" ]; then
|
|
|
|
mkdir -p $out/share
|
|
|
|
for dir in "$out/lib/node_modules/${name}/man/"*; do
|
|
|
|
mkdir -p $out/share/man/$(basename "$dir")
|
|
|
|
for page in "$dir"/*; do
|
|
|
|
ln -sv $page $out/share/man/$(basename "$dir")
|
|
|
|
done
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
'') args.passthru.names)}
|
|
|
|
${concatStrings (concatMap (dep: map (name: ''
|
2013-08-30 15:02:44 +02:00
|
|
|
mv node_modules/${name} $out/lib/node_modules
|
2013-08-21 00:56:13 +02:00
|
|
|
'') dep.names) peerDependencies)}
|
2013-07-27 19:23:35 +02:00
|
|
|
mv node_modules/.bin $out/lib/node_modules 2>/dev/null || true
|
2013-08-21 00:56:13 +02:00
|
|
|
mv node_modules $out/.dependent-node-modules
|
2013-07-27 19:23:35 +02:00
|
|
|
if [ -d "$out/lib/node_modules/.bin" ]; then
|
2013-07-28 17:46:40 +02:00
|
|
|
ln -sv $out/lib/node_modules/.bin $out/bin
|
2013-07-18 21:44:48 +02:00
|
|
|
node=`type -p node`
|
|
|
|
coffee=`type -p coffee || true`
|
2013-07-27 19:23:35 +02:00
|
|
|
find -L $out/lib/node_modules/.bin/* -type f -print0 | \
|
2013-07-18 21:44:48 +02:00
|
|
|
xargs -0 sed --follow-symlinks -i \
|
|
|
|
-e 's@#!/usr/bin/env node@#!'"$node"'@' \
|
|
|
|
-e 's@#!/usr/bin/env coffee@#!'"$coffee"'@' \
|
|
|
|
-e 's@#!/.*/node@#!'"$node"'@' \
|
|
|
|
-e 's@#!/.*/coffee@#!'"$coffee"'@'
|
2012-07-25 23:46:21 +02:00
|
|
|
fi
|
|
|
|
runHook postInstall
|
|
|
|
'';
|
2012-08-22 21:35:00 +02:00
|
|
|
|
2013-08-21 00:56:13 +02:00
|
|
|
preFixup = concatStringsSep "\n" (map (src: ''
|
2012-08-22 21:35:00 +02:00
|
|
|
find $out -type f -print0 | xargs -0 sed -i 's|${src}|${src.name}|g'
|
2013-08-21 00:56:13 +02:00
|
|
|
'') src);
|
2013-05-29 17:53:36 +02:00
|
|
|
} // args // {
|
|
|
|
# Run the node setup hook when this package is a build input
|
|
|
|
propagatedNativeBuildInputs = (args.propagatedNativeBuildInputs or []) ++ [ nodejs ];
|
|
|
|
|
|
|
|
# Make buildNodePackage useful with --run-env
|
2013-08-21 00:56:13 +02:00
|
|
|
nativeBuildInputs = (args.nativeBuildInputs or []) ++ deps ++ peerDependencies ++ neededNatives;
|
2013-05-29 17:53:36 +02:00
|
|
|
} )
|