2012-09-13 14:35:35 +02:00
|
|
|
{ stdenv, runCommand, nodejs, neededNatives}:
|
2012-07-25 23:46:21 +02:00
|
|
|
|
2013-06-05 18:25:41 +02:00
|
|
|
args @ { name, src, deps ? [], 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
|
|
|
|
'';
|
|
|
|
|
|
|
|
requireName = (builtins.parseDrvName name).name;
|
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
|
|
|
|
${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
|
2013-05-29 17:53:36 +02:00
|
|
|
npm --registry http://www.example.com --nodedir=${sources} install ${src} ${npmFlags}
|
2012-07-25 23:46:21 +02:00
|
|
|
runHook postBuild
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
2013-06-05 18:25:41 +02:00
|
|
|
mkdir -p $out/node_modules
|
|
|
|
mv node_modules/${requireName} $out/node_modules
|
|
|
|
mv node_modules/.bin $out/node_modules 2>/dev/null || true
|
|
|
|
mv node_modules $out/node_modules/${requireName}
|
2012-07-25 23:46:21 +02:00
|
|
|
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 21:35:00 +02:00
|
|
|
|
|
|
|
preFixup = ''
|
|
|
|
find $out -type f -print0 | xargs -0 sed -i 's|${src}|${src.name}|g'
|
|
|
|
'';
|
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-06-06 18:21:49 +02:00
|
|
|
nativeBuildInputs = (args.nativeBuildInputs or []) ++ deps ++ neededNatives;
|
2013-05-29 17:53:36 +02:00
|
|
|
} )
|