50 lines
1.5 KiB
Nix
50 lines
1.5 KiB
Nix
{ stdenv, nim }:
|
|
|
|
{ name, src, nimDeps ? [], buildInputs ? [], patches ? [], patchPhase ? "", ... }:
|
|
|
|
let
|
|
getRecursiveBuildInputs = deps: with stdenv.lib.lists;
|
|
optionals (deps != []) ((head deps).buildInputs ++
|
|
(getRecursiveBuildInputs (head deps).nimDeps) ++
|
|
(getRecursiveBuildInputs (tail deps)));
|
|
recursiveBuildInputs = buildInputs ++ (getRecursiveBuildInputs nimDeps);
|
|
in
|
|
stdenv.mkDerivation {
|
|
name = name;
|
|
src = src;
|
|
patches = patches;
|
|
nativeBuildInputs = [ nim ];
|
|
buildInputs = recursiveBuildInputs;
|
|
nimDeps = nimDeps;
|
|
patchPhase = patchPhase;
|
|
LD_LIBRARY_PATH = stdenv.lib.makeLibraryPath recursiveBuildInputs;
|
|
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
|
|
''
|
|
) 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
|
|
'';
|
|
}
|
|
|