2019-04-17 00:58:15 +02:00
|
|
|
{ stdenv, nim }:
|
|
|
|
|
2019-05-22 15:22:57 +02:00
|
|
|
{ name, src, nimDeps ? [], nativeBuildInputs ? [], buildInputs ? [],
|
|
|
|
patches ? [], patchPhase ? "", ... }:
|
|
|
|
|
|
|
|
with stdenv.lib;
|
2019-04-17 00:58:15 +02:00
|
|
|
|
2019-05-22 14:12:55 +02:00
|
|
|
let
|
2019-05-22 15:22:57 +02:00
|
|
|
getRecursiveInputs = getInputsFn: deps:
|
|
|
|
optionals (deps != []) ((getInputsFn (head deps)) ++
|
|
|
|
(getRecursiveInputs getInputsFn (head deps).nimDeps) ++
|
|
|
|
(getRecursiveInputs getInputsFn (tail deps)));
|
|
|
|
rNativeBuildInputs =
|
|
|
|
nativeBuildInputs ++ (getRecursiveInputs (i: i.nativeBuildInputs) nimDeps);
|
|
|
|
rBuildInputs =
|
|
|
|
buildInputs ++ (getRecursiveInputs (i: i.buildInputs) nimDeps);
|
2019-05-22 14:12:55 +02:00
|
|
|
in
|
2019-04-17 00:58:15 +02:00
|
|
|
stdenv.mkDerivation {
|
|
|
|
name = name;
|
|
|
|
src = src;
|
|
|
|
patches = patches;
|
2019-05-22 15:22:57 +02:00
|
|
|
nativeBuildInputs = [ nim ] ++ (filter (i: i != nim) rNativeBuildInputs);
|
|
|
|
buildInputs = rBuildInputs;
|
2019-05-22 14:12:55 +02:00
|
|
|
nimDeps = nimDeps;
|
|
|
|
patchPhase = patchPhase;
|
2019-05-22 15:22:57 +02:00
|
|
|
LD_LIBRARY_PATH = makeLibraryPath (rBuildInputs ++ rNativeBuildInputs);
|
2019-04-17 00:58:15 +02:00
|
|
|
buildPhase = ''
|
|
|
|
HOME=$TMPDIR
|
|
|
|
mkdir -p $HOME/.nimble/pkgs
|
|
|
|
echo "[]" > $HOME/.nimble/packages_official.json
|
|
|
|
'' + toString (map (dep: ''
|
|
|
|
if [ -d ${dep}/.nimble ]; then
|
|
|
|
cp -R ${dep}/.nimble/pkgs $HOME/.nimble/
|
|
|
|
else
|
|
|
|
cp -R ${dep} $HOME/.nimble/pkgs/${dep.name}
|
|
|
|
fi
|
2019-06-08 15:36:36 +02:00
|
|
|
# nimble >= 0.20.0 wants to store a nimblemeta.json here
|
|
|
|
chmod u+w $HOME/.nimble/pkgs/${dep.name}
|
2019-04-17 00:58:15 +02:00
|
|
|
''
|
|
|
|
) nimDeps) + ''
|
|
|
|
nimble install
|
|
|
|
'';
|
|
|
|
installPhase = ''
|
|
|
|
mkdir $out
|
|
|
|
nimbleDir=$TMPDIR/.nimble
|
|
|
|
if [ -d $nimbleDir/bin ]; then
|
|
|
|
cp -RL $nimbleDir/bin $out
|
|
|
|
fi
|
|
|
|
numberNimFiles=$(find $nimbleDir/pkgs/${name} -type f -name "*.nim" | wc -l)
|
|
|
|
numberDirectories=$(find $nimbleDir/pkgs/${name} -mindepth 1 -type d | wc -l)
|
|
|
|
if [ $numberNimFiles -gt 0 ] || [ $numberDirectories -gt 0 ]; then
|
|
|
|
mkdir -p $out/.nimble
|
|
|
|
cp -R $nimbleDir/pkgs $out/.nimble
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
|