Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node: fix builds similar to sqlite3 where modules are bundled #4850

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 31 additions & 11 deletions pkgs/development/web/nodejs/build-node-package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,33 @@ let
mv *node* $out
'';

patchShebangs = dir: ''
node=`type -p node`
coffee=`type -p coffee || true`
find -L "${dir}" -type f -print0 | \
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"'@' || true
'';

patchedSrc = map (src:
runCommand src.name { inherit src; buildInputs = [ nodejs ]; } ''
mkdir tmp
cd tmp
if [ -d $src ]; then
mkdir package
cp -rf $src/* package/
chmod -R +w .
else
unpackFile $src
fi
${patchShebangs "."}
tar -czf $out *
''
) src;

# Convert deps to attribute set
attrDeps = if isAttrs deps then deps else
(listToAttrs (map (dep: nameValuePair dep.name dep) deps));
Expand All @@ -38,7 +65,7 @@ let
in stdenv.mkDerivation ({
unpackPhase = "true";

inherit src;
inherit patchedSrc;

configurePhase = ''
runHook preConfigure
Expand Down Expand Up @@ -71,7 +98,7 @@ let

buildPhase = ''
runHook preBuild
npm --registry http://www.example.com --nodedir=${sources} install $src ${npmFlags}
npm --registry http://www.example.com --nodedir=${sources} install $patchedSrc ${npmFlags}
runHook postBuild
'';

Expand Down Expand Up @@ -106,21 +133,14 @@ let
mv node_modules $out/.dependent-node-modules
if [ -d "$out/lib/node_modules/.bin" ]; then
ln -sv $out/lib/node_modules/.bin $out/bin
node=`type -p node`
coffee=`type -p coffee || true`
find -L $out/lib/node_modules/.bin/* -type f -print0 | \
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"'@'
${patchShebangs "$out/lib/node_modules/.bin/*"}
fi
runHook postInstall
'';

preFixup = concatStringsSep "\n" (map (src: ''
find $out -type f -print0 | xargs -0 sed -i 's|${src}|${src.name}|g'
'') src);
'') patchedSrc);

shellHook = ''
${preShellHook}
Expand Down