2021-07-24 15:53:20 +02:00
|
|
|
{ lib, stdenv, nim }:
|
2019-04-17 00:58:15 +02:00
|
|
|
|
2019-07-17 20:49:14 +02:00
|
|
|
{
|
|
|
|
name,
|
|
|
|
src,
|
|
|
|
nimDeps ? [],
|
|
|
|
nativeBuildInputs ? [],
|
|
|
|
buildInputs ? [],
|
|
|
|
patches ? [],
|
|
|
|
patchPhase ? "",
|
|
|
|
preBuild ? "",
|
|
|
|
postBuild ? "",
|
|
|
|
preInstall ? "",
|
|
|
|
postInstall ? "",
|
|
|
|
...
|
|
|
|
}:
|
2019-05-22 15:22:57 +02:00
|
|
|
|
2021-07-24 15:53:20 +02:00
|
|
|
with 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)));
|
2019-06-17 01:00:04 +02:00
|
|
|
|
2019-05-22 15:22:57 +02:00
|
|
|
rNativeBuildInputs =
|
|
|
|
nativeBuildInputs ++ (getRecursiveInputs (i: i.nativeBuildInputs) nimDeps);
|
2019-06-17 01:00:04 +02:00
|
|
|
|
2019-05-22 15:22:57 +02:00
|
|
|
rBuildInputs =
|
|
|
|
buildInputs ++ (getRecursiveInputs (i: i.buildInputs) nimDeps);
|
2019-06-17 01:00:04 +02:00
|
|
|
|
|
|
|
copyNimDeps = ''
|
|
|
|
mkdir -p $NIMBLE_DIR/pkgs
|
2019-06-17 01:06:21 +02:00
|
|
|
echo "[]" > $NIMBLE_DIR/packages_official.json
|
2019-06-17 01:00:04 +02:00
|
|
|
'' + toString (map (dep: ''
|
|
|
|
if [ -d ${dep}/.nimble ]; then
|
|
|
|
cp -R ${dep}/.nimble/pkgs $NIMBLE_DIR
|
|
|
|
else
|
|
|
|
cp -R ${dep} $NIMBLE_DIR/pkgs/${dep.name}
|
|
|
|
fi
|
|
|
|
''
|
|
|
|
) nimDeps) + ''
|
|
|
|
# nimble >= 0.20.0 wants to store nimblemeta.json here
|
|
|
|
chmod -R u+w $NIMBLE_DIR/pkgs
|
|
|
|
'';
|
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-07-17 20:49:14 +02:00
|
|
|
preBuild = preBuild;
|
|
|
|
postBuild = postBuild;
|
|
|
|
preInstall = preInstall;
|
|
|
|
postInstall = postInstall;
|
2019-05-22 15:22:57 +02:00
|
|
|
LD_LIBRARY_PATH = makeLibraryPath (rBuildInputs ++ rNativeBuildInputs);
|
2019-06-17 01:00:04 +02:00
|
|
|
|
2019-04-17 00:58:15 +02:00
|
|
|
buildPhase = ''
|
2019-06-17 12:03:04 +02:00
|
|
|
runHook preBuild
|
|
|
|
|
2019-04-17 00:58:15 +02:00
|
|
|
HOME=$TMPDIR
|
2019-06-17 01:00:04 +02:00
|
|
|
NIMBLE_DIR=$HOME/.nimble
|
|
|
|
'' + copyNimDeps + ''
|
2019-04-17 00:58:15 +02:00
|
|
|
nimble install
|
2019-06-17 12:03:04 +02:00
|
|
|
|
|
|
|
runHook PostBuild
|
2019-04-17 00:58:15 +02:00
|
|
|
'';
|
2019-06-17 01:00:04 +02:00
|
|
|
|
2019-04-17 00:58:15 +02:00
|
|
|
installPhase = ''
|
2019-06-17 12:03:04 +02:00
|
|
|
runHook preInstall
|
|
|
|
|
2019-04-17 00:58:15 +02:00
|
|
|
mkdir $out
|
2019-06-17 01:00:04 +02:00
|
|
|
if [ -d $NIMBLE_DIR/bin ]; then
|
|
|
|
cp -RL $NIMBLE_DIR/bin $out
|
2019-04-17 00:58:15 +02:00
|
|
|
fi
|
2019-06-17 01:00:04 +02:00
|
|
|
numberNimFiles=$(find $NIMBLE_DIR/pkgs/${name} -type f -name "*.nim" | wc -l)
|
|
|
|
numberDirectories=$(find $NIMBLE_DIR/pkgs/${name} -mindepth 1 -type d | wc -l)
|
2019-04-17 00:58:15 +02:00
|
|
|
if [ $numberNimFiles -gt 0 ] || [ $numberDirectories -gt 0 ]; then
|
|
|
|
mkdir -p $out/.nimble
|
2019-06-17 01:00:04 +02:00
|
|
|
cp -R $NIMBLE_DIR/pkgs $out/.nimble
|
2019-04-17 00:58:15 +02:00
|
|
|
fi
|
2019-06-17 12:03:04 +02:00
|
|
|
|
|
|
|
runHook postInstall
|
2019-04-17 00:58:15 +02:00
|
|
|
'';
|
2019-06-17 01:00:04 +02:00
|
|
|
|
|
|
|
shellHook = ''
|
|
|
|
export NIMBLE_DIR=$PWD/.nimble
|
|
|
|
'' + copyNimDeps;
|
2019-04-17 00:58:15 +02:00
|
|
|
}
|
|
|
|
|