diff --git a/pkgs/nim-packages/generic.nix b/pkgs/nim-packages/generic.nix index c658e05..14f8c9b 100644 --- a/pkgs/nim-packages/generic.nix +++ b/pkgs/nim-packages/generic.nix @@ -10,10 +10,29 @@ let 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); + + copyNimDeps = '' + mkdir -p $NIMBLE_DIR/pkgs + if [ ! -f $NIMBLE_DIR/packages_official.json ]; then + echo "[]" > $NIMBLE_DIR/packages_official.json + fi + '' + 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 + ''; in stdenv.mkDerivation { name = name; @@ -24,34 +43,29 @@ stdenv.mkDerivation { nimDeps = nimDeps; patchPhase = patchPhase; LD_LIBRARY_PATH = makeLibraryPath (rBuildInputs ++ rNativeBuildInputs); + 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 - # nimble >= 0.20.0 wants to store a nimblemeta.json here - chmod u+w $HOME/.nimble/pkgs/${dep.name} - '' - ) nimDeps) + '' + NIMBLE_DIR=$HOME/.nimble + '' + copyNimDeps + '' nimble install ''; + installPhase = '' mkdir $out - nimbleDir=$TMPDIR/.nimble - if [ -d $nimbleDir/bin ]; then - cp -RL $nimbleDir/bin $out + if [ -d $NIMBLE_DIR/bin ]; then + cp -RL $NIMBLE_DIR/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) + numberNimFiles=$(find $NIMBLE_DIR/pkgs/${name} -type f -name "*.nim" | wc -l) + numberDirectories=$(find $NIMBLE_DIR/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 + cp -R $NIMBLE_DIR/pkgs $out/.nimble fi ''; + + shellHook = '' + export NIMBLE_DIR=$PWD/.nimble + '' + copyNimDeps; }