mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-12-04 03:25:02 +00:00
7b1a863f1e
This is because of an error while using `nix` under Archlinux: ``` building path(s) `/nix/store/rwkcbhv9jfhzhandfslg62knl2xw0r7m-node-sources' building /nix/store/rwkcbhv9jfhzhandfslg62knl2xw0r7m-node-sources suspicious ownership or permission on `/nix/store/rwkcbhv9jfhzhandfslg62knl2xw0r7m-node-sources'; rejecting this build output cannot build derivation `/nix/store/01qsszx9y2kyx1x72zr5magy2la98720-uglify-js-2.4.15.drv': 1 dependencies couldn't be built ``` The permissions on all file are like the following: ``` drwxrwxr-x 1 root root 358 Jun 9 17:04 . drwxr-xr-x 1 root root 421110 Jul 21 15:49 .. -rw-rw-r-- 1 root root 22 Jun 9 17:04 .gitattributes ``` After the fix, permissions are OK, and no suspicious error any more. Error is encountered for any node package built. I'm not sure why it fails on Arch but work on nixos, but I believe the flag is safe to add anyway.
90 lines
2.9 KiB
Nix
90 lines
2.9 KiB
Nix
{ stdenv, runCommand, nodejs, neededNatives}:
|
|
|
|
args @ { name, src, deps ? [], peerDependencies ? [], flags ? [], ... }:
|
|
|
|
with stdenv.lib;
|
|
|
|
let
|
|
npmFlags = concatStringsSep " " (map (v: "--${v}") flags);
|
|
|
|
sources = runCommand "node-sources" {} ''
|
|
tar --no-same-owner --no-same-permissions -xf ${nodejs.src}
|
|
mv *node* $out
|
|
'';
|
|
|
|
peerDeps = listToAttrs (concatMap (dep: map (name: {
|
|
inherit name;
|
|
value = dep;
|
|
}) (filter (nm: !(elem nm (args.passthru.names or []))) dep.names)) (peerDependencies));
|
|
in
|
|
stdenv.mkDerivation ({
|
|
unpackPhase = "true";
|
|
|
|
inherit src;
|
|
|
|
configurePhase = ''
|
|
runHook preConfigure
|
|
mkdir node_modules
|
|
${concatStrings (concatMap (dep: map (name: ''
|
|
ln -sv ${dep}/lib/node_modules/${name} node_modules/
|
|
'') dep.names) deps)}
|
|
${concatStrings (mapAttrsToList (name: dep: ''
|
|
ln -sv ${dep}/lib/node_modules/${name} node_modules/
|
|
'') peerDeps)}
|
|
export HOME=$(pwd)
|
|
runHook postConfigure
|
|
'';
|
|
|
|
buildPhase = ''
|
|
runHook preBuild
|
|
npm --registry http://www.example.com --nodedir=${sources} install $src ${npmFlags}
|
|
runHook postBuild
|
|
'';
|
|
|
|
installPhase = ''
|
|
runHook preInstall
|
|
mkdir -p $out/lib/node_modules
|
|
${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 (mapAttrsToList (name: dep: ''
|
|
mv node_modules/${name} $out/lib/node_modules
|
|
'') peerDeps)}
|
|
mv node_modules/.bin $out/lib/node_modules 2>/dev/null || true
|
|
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"'@'
|
|
fi
|
|
runHook postInstall
|
|
'';
|
|
|
|
preFixup = concatStringsSep "\n" (map (src: ''
|
|
find $out -type f -print0 | xargs -0 sed -i 's|${src}|${src.name}|g'
|
|
'') src);
|
|
} // args // {
|
|
# Run the node setup hook when this package is a build input
|
|
propagatedNativeBuildInputs = (args.propagatedNativeBuildInputs or []) ++ [ nodejs ];
|
|
|
|
# Make buildNodePackage useful with --run-env
|
|
nativeBuildInputs = (args.nativeBuildInputs or []) ++ deps ++ peerDependencies ++ neededNatives;
|
|
} )
|