summary refs log tree commit diff
path: root/pkgs/development
diff options
context:
space:
mode:
authorJan Malakhovski <oxij@oxij.org>2015-08-17 23:55:04 +0000
committerJan Malakhovski <oxij@oxij.org>2015-08-18 19:56:17 +0000
commit00137438459949bfbd2c0311e8664a9da8bb1e53 (patch)
tree12fedfa2353933925b05c77a348acaa97cd03b62 /pkgs/development
parentd8487667cfe3f83f857b45d4927a19d9181b7f4c (diff)
downloadnixpkgs-00137438459949bfbd2c0311e8664a9da8bb1e53.tar
nixpkgs-00137438459949bfbd2c0311e8664a9da8bb1e53.tar.gz
nixpkgs-00137438459949bfbd2c0311e8664a9da8bb1e53.tar.bz2
nixpkgs-00137438459949bfbd2c0311e8664a9da8bb1e53.tar.lz
nixpkgs-00137438459949bfbd2c0311e8664a9da8bb1e53.tar.xz
nixpkgs-00137438459949bfbd2c0311e8664a9da8bb1e53.tar.zst
nixpkgs-00137438459949bfbd2c0311e8664a9da8bb1e53.zip
haskell-packages: make hoogle wrapper much more helpful
* Build most of the stuff on /tmp, not in /nix/store.
* Generate hoogle database for all the dependencies.
* Generate haddock index and contents files.
* Cleanup.
Diffstat (limited to 'pkgs/development')
-rw-r--r--pkgs/development/haskell-modules/hoogle-local-wrapper.sh3
-rw-r--r--pkgs/development/haskell-modules/hoogle.nix62
-rw-r--r--pkgs/development/haskell-modules/lib.nix1
3 files changed, 40 insertions, 26 deletions
diff --git a/pkgs/development/haskell-modules/hoogle-local-wrapper.sh b/pkgs/development/haskell-modules/hoogle-local-wrapper.sh
index 13ea889119c..471b2c81584 100644
--- a/pkgs/development/haskell-modules/hoogle-local-wrapper.sh
+++ b/pkgs/development/haskell-modules/hoogle-local-wrapper.sh
@@ -2,5 +2,4 @@
 
 COMMAND=$1
 shift
-HOOGLE_DOC_PATH=@out@/share/hoogle/doc exec @hoogle@/bin/hoogle \
-    "$COMMAND" -d @out@/share/hoogle "$@"
+exec @hoogle@/bin/hoogle "$COMMAND" -d @out@/share/doc/hoogle "$@"
diff --git a/pkgs/development/haskell-modules/hoogle.nix b/pkgs/development/haskell-modules/hoogle.nix
index 89e9b157e68..e2f6c289a80 100644
--- a/pkgs/development/haskell-modules/hoogle.nix
+++ b/pkgs/development/haskell-modules/hoogle.nix
@@ -23,7 +23,7 @@
 # This will build mmorph and monadControl, and have the hoogle installation
 # refer to their documentation via symlink so they are not garbage collected.
 
-{ stdenv, hoogle, rehoo
+{ lib, stdenv, hoogle, rehoo
 , ghc, packages ? [ ghc.ghc ]
 }:
 
@@ -35,62 +35,76 @@ stdenv.mkDerivation {
   name = "hoogle-local-0.1";
   buildInputs = [hoogle rehoo];
 
-  phases = [ "installPhase" ];
+  phases = [ "buildPhase" ];
 
-  docPackages = packages;
-  installPhase = ''
+  docPackages = (lib.closePropagation packages);
+
+  buildPhase = ''
     if [ -z "$docPackages" ]; then
         echo "ERROR: The packages attribute has not been set"
         exit 1
     fi
 
-    mkdir -p $out/share/hoogle/doc
-    export HOOGLE_DOC_PATH=$out/share/hoogle/doc
-
-    cd $out/share/hoogle
+    mkdir -p $out/share/doc/hoogle
 
     function import_dbs() {
         find $1 -name '*.txt' | while read f; do
           newname=$(basename "$f" | tr '[:upper:]' '[:lower:]')
           if [[ -f $f && ! -f ./$newname ]]; then
-            cp -p $f ./$newname
+            cp -p $f "./$newname"
             hoogle convert -d "$(dirname $f)" "./$newname"
           fi
         done
     }
 
-    for i in $docPackages; do
-        findInputs $i docPackages propagated-native-build-inputs
-        findInputs $i docPackages propagated-build-inputs
+    echo importing builtin packages
+    for docdir in ${ghc}/share/doc/ghc*/html/libraries/*; do
+      if [[ -d $docdir ]]; then
+        import_dbs $docdir
+        ln -sfn $docdir $out/share/doc/hoogle
+      fi
     done
 
+    echo importing other packages
     for i in $docPackages; do
       if [[ ! $i == $out ]]; then
         for docdir in $i/share/doc/*-ghc-*/* $i/share/doc/*; do
+          name=`basename $docdir`
+          docdir=$docdir/html
           if [[ -d $docdir ]]; then
             import_dbs $docdir
-            ln -sf $docdir $out/share/hoogle/doc
+            ln -sfn $docdir $out/share/doc/hoogle/$name
           fi
         done
       fi
     done
 
-    import_dbs ${ghc}/share/doc/ghc*/html/libraries
-    ln -sf ${ghc}/share/doc/ghc*/html/libraries/* $out/share/hoogle/doc
-
+    echo building hoogle database
+    # FIXME: rehoo is marked as depricated on Hackage
     chmod 644 *.hoo *.txt
     rehoo -j4 -c64 .
 
-    rm -fr downloads *.dep *.txt
-    mv default.hoo x || exit 0
-    rm -f *.hoo
-    mv x default.hoo || exit 1
+    mv default.hoo .x
+    rm -fr downloads *.dep *.txt *.hoo
+    mv .x $out/share/doc/hoogle/default.hoo
 
-    if [ ! -f default.hoo ]; then
-        echo "Unable to build the default Hoogle database"
-        exit 1
-    fi
+    echo building haddock index
+    # adapted from GHC's gen_contents_index
+    cd $out/share/doc/hoogle
+
+    args=
+    for hdfile in `ls -1 */*.haddock | grep -v '/ghc\.haddock' | sort`
+    do
+        name_version=`echo "$hdfile" | sed 's#/.*##'`
+        args="$args --read-interface=$name_version,$hdfile"
+    done
+
+    ${ghc}/bin/haddock --gen-index --gen-contents -o . \
+         -t "Haskell Hierarchical Libraries" \
+         -p ${ghc}/share/doc/ghc*/html/libraries/prologue.txt \
+         $args
 
+    echo finishing up
     mkdir -p $out/bin
     substitute ${wrapper} $out/bin/hoogle \
         --subst-var out --subst-var-by shell ${stdenv.shell} \
diff --git a/pkgs/development/haskell-modules/lib.nix b/pkgs/development/haskell-modules/lib.nix
index 526bb5c3248..9f9eba0675d 100644
--- a/pkgs/development/haskell-modules/lib.nix
+++ b/pkgs/development/haskell-modules/lib.nix
@@ -85,6 +85,7 @@ rec {
   withHoogle = haskellEnv: with haskellEnv.haskellPackages;
     import ./hoogle.nix {
       inherit (pkgs) stdenv;
+      inherit (pkgs.stdenv) lib;
       inherit hoogle rehoo ghc;
       packages = haskellEnv.paths;
     };