summary refs log tree commit diff
path: root/pkgs/development/web/nodejs/build-node-package.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/development/web/nodejs/build-node-package.nix')
-rw-r--r--pkgs/development/web/nodejs/build-node-package.nix25
1 files changed, 14 insertions, 11 deletions
diff --git a/pkgs/development/web/nodejs/build-node-package.nix b/pkgs/development/web/nodejs/build-node-package.nix
index 5c75513496b..d260b290016 100644
--- a/pkgs/development/web/nodejs/build-node-package.nix
+++ b/pkgs/development/web/nodejs/build-node-package.nix
@@ -1,15 +1,18 @@
 { stdenv, runCommand, nodejs, neededNatives}:
 
-args @ { src, deps ? [], flags ? [], ... }:
+args @ { name, src, deps ? [], flags ? [], ... }:
 
 with stdenv.lib;
 
-let npmFlags = concatStringsSep " " (map (v: "--${v}") flags);
-    sources = runCommand "node-sources" {} ''
-      tar xf ${nodejs.src}
-      mv *node* $out
-    '';
+let
+  npmFlags = concatStringsSep " " (map (v: "--${v}") flags);
 
+  sources = runCommand "node-sources" {} ''
+    tar xf ${nodejs.src}
+    mv *node* $out
+  '';
+
+  requireName = (builtins.parseDrvName name).name;
 in
 stdenv.mkDerivation ({
   unpackPhase = "true";
@@ -30,12 +33,12 @@ stdenv.mkDerivation ({
     runHook postBuild
   '';
 
-  nativeBuildInputs = neededNatives;
-
   installPhase = ''
     runHook preInstall
-    mkdir $out
-    mv node_modules $out
+    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}
     if [ -d "$out/node_modules/.bin" ]; then
       ln -sv node_modules/.bin $out/bin
       find -L $out/node_modules/.bin/* -type f -print0 | \
@@ -52,5 +55,5 @@ stdenv.mkDerivation ({
   propagatedNativeBuildInputs = (args.propagatedNativeBuildInputs or []) ++ [ nodejs ];
 
   # Make buildNodePackage useful with --run-env
-  nativeBuildInputs = (args.nativeBuildInputs or []) ++ deps;
+  nativeBuildInputs = (args.nativeBuildInputs or []) ++ deps ++ neededNatives;
 } )