mirror of
https://github.com/nix-community/dream2nix.git
synced 2025-01-05 13:29:29 +03:00
stop using string substitutions in installPhase
This commit is contained in:
parent
9e2b46edfd
commit
9d8292878a
@ -99,7 +99,7 @@ let
|
|||||||
|
|
||||||
pname = utils.sanitizeDerivationName name;
|
pname = utils.sanitizeDerivationName name;
|
||||||
|
|
||||||
inherit version;
|
inherit nodeSources version;
|
||||||
|
|
||||||
src = getSource name version;
|
src = getSource name version;
|
||||||
|
|
||||||
@ -107,24 +107,23 @@ let
|
|||||||
|
|
||||||
ignoreScripts = true;
|
ignoreScripts = true;
|
||||||
|
|
||||||
inherit nodeSources;
|
dontUnpack = true;
|
||||||
|
|
||||||
dontNpmInstall = false;
|
dontNpmInstall = false;
|
||||||
|
|
||||||
dependencies_json = writeText "dependencies.json"
|
fixPackage = "${./fix-package.py}";
|
||||||
(b.toJSON
|
|
||||||
(lib.listToAttrs
|
dependencies_json = b.toJSON
|
||||||
(b.map
|
(lib.listToAttrs
|
||||||
(dep: lib.nameValuePair dep.name dep.version)
|
(b.map
|
||||||
deps)));
|
(dep: lib.nameValuePair dep.name dep.version)
|
||||||
|
deps));
|
||||||
|
|
||||||
nodeDeps =
|
nodeDeps =
|
||||||
lib.forEach
|
lib.forEach
|
||||||
deps
|
deps
|
||||||
(dep: allPackages."${dep.name}"."${dep.version}" );
|
(dep: allPackages."${dep.name}"."${dep.version}" );
|
||||||
|
|
||||||
dontUnpack = true;
|
|
||||||
|
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
runHook preInstall
|
runHook preInstall
|
||||||
|
|
||||||
@ -134,13 +133,13 @@ let
|
|||||||
|
|
||||||
cd $TMPDIR
|
cd $TMPDIR
|
||||||
|
|
||||||
unpackFile ${src}
|
unpackFile $src
|
||||||
|
|
||||||
# Make the base dir in which the target dependency resides first
|
# Make the base dir in which the target dependency resides first
|
||||||
mkdir -p "$(dirname "$nodeModules/${packageName}")"
|
mkdir -p "$(dirname "$nodeModules/$packageName")"
|
||||||
|
|
||||||
# install source
|
# install source
|
||||||
if [ -f "${src}" ]
|
if [ -f "$src" ]
|
||||||
then
|
then
|
||||||
# Figure out what directory has been unpacked
|
# Figure out what directory has been unpacked
|
||||||
packageDir="$(find . -maxdepth 1 -type d | tail -1)"
|
packageDir="$(find . -maxdepth 1 -type d | tail -1)"
|
||||||
@ -150,22 +149,22 @@ let
|
|||||||
chmod -R u+w "$packageDir"
|
chmod -R u+w "$packageDir"
|
||||||
|
|
||||||
# Move the extracted tarball into the output folder
|
# Move the extracted tarball into the output folder
|
||||||
mv "$packageDir" "$nodeModules/${packageName}"
|
mv "$packageDir" "$nodeModules/$packageName"
|
||||||
elif [ -d "${src}" ]
|
elif [ -d "$src" ]
|
||||||
then
|
then
|
||||||
strippedName="$(stripHash ${src})"
|
strippedName="$(stripHash $src)"
|
||||||
|
|
||||||
# Restore write permissions
|
# Restore write permissions
|
||||||
chmod -R u+w "$strippedName"
|
chmod -R u+w "$strippedName"
|
||||||
|
|
||||||
# Move the extracted directory into the output folder
|
# Move the extracted directory into the output folder
|
||||||
mv "$strippedName" "$nodeModules/${packageName}"
|
mv "$strippedName" "$nodeModules/$packageName"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# repair 'link:' -> 'file:'
|
# repair 'link:' -> 'file:'
|
||||||
mv $nodeModules/${packageName}/package.json $nodeModules/${packageName}/package.json.old
|
mv $nodeModules/$packageName/package.json $nodeModules/$packageName/package.json.old
|
||||||
cat $nodeModules/${packageName}/package.json.old | sed 's!link:!file\:!g' > $nodeModules/${packageName}/package.json
|
cat $nodeModules/$packageName/package.json.old | sed 's!link:!file\:!g' > $nodeModules/$packageName/package.json
|
||||||
rm $nodeModules/${packageName}/package.json.old
|
rm $nodeModules/$packageName/package.json.old
|
||||||
|
|
||||||
# symlink dependency packages into node_modules
|
# symlink dependency packages into node_modules
|
||||||
for dep in $nodeDeps; do
|
for dep in $nodeDeps; do
|
||||||
@ -173,30 +172,31 @@ let
|
|||||||
for module in $(ls $dep/lib/node_modules); do
|
for module in $(ls $dep/lib/node_modules); do
|
||||||
if [[ $module == @* ]]; then
|
if [[ $module == @* ]]; then
|
||||||
for submodule in $(ls $dep/lib/node_modules/$module); do
|
for submodule in $(ls $dep/lib/node_modules/$module); do
|
||||||
mkdir -p $nodeModules/${packageName}/node_modules/$module
|
mkdir -p $nodeModules/$packageName/node_modules/$module
|
||||||
echo "ln -s $dep/lib/node_modules/$module/$submodule $nodeModules/${packageName}/node_modules/$module/$submodule"
|
echo "ln -s $dep/lib/node_modules/$module/$submodule $nodeModules/$packageName/node_modules/$module/$submodule"
|
||||||
ln -s $dep/lib/node_modules/$module/$submodule $nodeModules/${packageName}/node_modules/$module/$submodule
|
ln -s $dep/lib/node_modules/$module/$submodule $nodeModules/$packageName/node_modules/$module/$submodule
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
mkdir -p $nodeModules/${packageName}/node_modules/
|
mkdir -p $nodeModules/$packageName/node_modules/
|
||||||
echo "ln -s $dep/lib/node_modules/$module $nodeModules/${packageName}/node_modules/$module"
|
echo "ln -s $dep/lib/node_modules/$module $nodeModules/$packageName/node_modules/$module"
|
||||||
ln -s $dep/lib/node_modules/$module $nodeModules/${packageName}/node_modules/$module
|
ln -s $dep/lib/node_modules/$module $nodeModules/$packageName/node_modules/$module
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
export NODE_PATH="$NODE_PATH:$nodeModules/${packageName}/node_modules"
|
export NODE_PATH="$NODE_PATH:$nodeModules/$packageName/node_modules"
|
||||||
cd "$nodeModules/${packageName}"
|
|
||||||
|
cd "$nodeModules/$packageName"
|
||||||
|
|
||||||
export HOME=$TMPDIR
|
export HOME=$TMPDIR
|
||||||
|
|
||||||
# delete package-lock.json as it can lead to conflicts
|
# delete package-lock.json as it can lead to conflicts
|
||||||
rm -f package-lock.json
|
rm -f package-lock.json
|
||||||
|
|
||||||
# fix malformed dependency versions in package.json
|
# pin dependency versions in package.json
|
||||||
cp package.json package.json.bak
|
cp package.json package.json.bak
|
||||||
python ${./fix-package-json.py} $dependencies_json package.json \
|
python $fixPackage \
|
||||||
|| \
|
|| \
|
||||||
# exit code 3 -> the package is incompatible to the current platform
|
# exit code 3 -> the package is incompatible to the current platform
|
||||||
if [ "$?" == "3" ]; then
|
if [ "$?" == "3" ]; then
|
||||||
@ -207,6 +207,7 @@ let
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# set flags for npm install
|
||||||
flags=("--offline" "--production" "--nodedir=$nodeSources")
|
flags=("--offline" "--production" "--nodedir=$nodeSources")
|
||||||
if [ -n "$ignoreScripts" ]; then
|
if [ -n "$ignoreScripts" ]; then
|
||||||
flags+=("--ignore-scripts")
|
flags+=("--ignore-scripts")
|
||||||
@ -217,24 +218,24 @@ let
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Create symlink to the deployed executable folder, if applicable
|
# Create symlink to the deployed executable folder, if applicable
|
||||||
if [ -d "$nodeModules/.bin" ]
|
if [ -d "$nodeModules/.bin" ]
|
||||||
then
|
then
|
||||||
ln -s $nodeModules/.bin $out/bin
|
ln -s $nodeModules/.bin $out/bin
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create symlinks to the deployed manual page folders, if applicable
|
# Create symlinks to the deployed manual page folders, if applicable
|
||||||
if [ -d "$nodeModules/${packageName}/man" ]
|
if [ -d "$nodeModules/$packageName/man" ]
|
||||||
then
|
then
|
||||||
mkdir -p $out/share
|
mkdir -p $out/share
|
||||||
for dir in "$nodeModules/${packageName}/man/"*
|
for dir in "$nodeModules/$packageName/man/"*
|
||||||
do
|
do
|
||||||
mkdir -p $out/share/man/$(basename "$dir")
|
mkdir -p $out/share/man/$(basename "$dir")
|
||||||
for page in "$dir"/*
|
for page in "$dir"/*
|
||||||
do
|
do
|
||||||
ln -s $page $out/share/man/$(basename "$dir")
|
ln -s $page $out/share/man/$(basename "$dir")
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
runHook postInstall
|
runHook postInstall
|
||||||
'';
|
'';
|
||||||
|
@ -3,10 +3,9 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
with open(sys.argv[1]) as f:
|
actual_deps = json.loads(os.environ.get('dependencies_json'))
|
||||||
actual_deps = json.load(f)
|
|
||||||
|
|
||||||
with open(sys.argv[2]) as f:
|
with open('package.json') as f:
|
||||||
package_json = json.load(f)
|
package_json = json.load(f)
|
||||||
|
|
||||||
changed = False
|
changed = False
|
||||||
@ -65,5 +64,5 @@ if 'dependencies' in package_json:
|
|||||||
|
|
||||||
# write changes to package.json
|
# write changes to package.json
|
||||||
if changed:
|
if changed:
|
||||||
with open(sys.argv[2], 'w') as f:
|
with open('package.json', 'w') as f:
|
||||||
json.dump(package_json, f, indent=2)
|
json.dump(package_json, f, indent=2)
|
Loading…
Reference in New Issue
Block a user