@@ -0,0 +1,107 @@
1+# Install not only the Hoogle library and executable, but also a local Hoogle
2+# database which provides "Source" links to all specified 'packages' -- or the
3+# current Haskell Platform if no custom package set is provided.
4+#
5+# It is intended to be used in config.nix similarly to:
6+#
7+# { packageOverrides = pkgs: rec {
8+#
9+# haskellPackages =
10+# let callPackage = pkgs.lib.callPackageWith haskellPackages;
11+# in pkgs.recurseIntoAttrs (pkgs.haskellPackages.override {
12+# extension = self: super: {
13+# hoogleLocal = pkgs.haskellPackages.hoogleLocal.override {
14+# packages = with pkgs.haskellPackages; [
15+# mmorph
16+# monadControl
17+# ];
18+# };
19+# };
20+# });
21+# }}
22+#
23+# This will build mmorph and monadControl, and have the hoogle installation
24+# refer to their documentation via symlink so they are not garbage collected.
25+
26+{ stdenv, hoogle, rehoo
27+, ghc, packages ? [ ghc.ghc ]
28+}:
29+
30+let
31+ inherit (stdenv.lib) optional;
32+ wrapper = ./hoogle-local-wrapper.sh;
33+in
34+stdenv.mkDerivation {
35+ name = "hoogle-local-0.1";
36+ buildInputs = [hoogle rehoo];
37+
38+ phases = [ "installPhase" ];
39+
40+ docPackages = packages;
41+ installPhase = ''
42+ if [ -z "$docPackages" ]; then
43+ echo "ERROR: The packages attribute has not been set"
44+ exit 1
45+ fi
46+
47+ mkdir -p $out/share/hoogle/doc
48+ export HOOGLE_DOC_PATH=$out/share/hoogle/doc
49+
50+ cd $out/share/hoogle
51+
52+ function import_dbs() {
53+ find $1 -name '*.txt' | while read f; do
54+ newname=$(basename "$f" | tr '[:upper:]' '[:lower:]')
55+ if [[ -f $f && ! -f ./$newname ]]; then
56+ cp -p $f ./$newname
57+ hoogle convert -d "$(dirname $f)" "./$newname"
58+ fi
59+ done
60+ }
61+
62+ for i in $docPackages; do
63+ findInputs $i docPackages propagated-native-build-inputs
64+ findInputs $i docPackages propagated-build-inputs
65+ done
66+
67+ for i in $docPackages; do
68+ if [[ ! $i == $out ]]; then
69+ for docdir in $i/share/doc/*-ghc-*/* $i/share/doc/*; do
70+ if [[ -d $docdir ]]; then
71+ import_dbs $docdir
72+ ln -sf $docdir $out/share/hoogle/doc
73+ fi
74+ done
75+ fi
76+ done
77+
78+ import_dbs ${ghc}/share/doc/ghc*/html/libraries
79+ ln -sf ${ghc}/share/doc/ghc*/html/libraries/* $out/share/hoogle/doc
80+
81+ chmod 644 *.hoo *.txt
82+ rehoo -j4 -c64 .
83+
84+ rm -fr downloads *.dep *.txt
85+ mv default.hoo x || exit 0
86+ rm -f *.hoo
87+ mv x default.hoo || exit 1
88+
89+ if [ ! -f default.hoo ]; then
90+ echo "Unable to build the default Hoogle database"
91+ exit 1
92+ fi
93+
94+ mkdir -p $out/bin
95+ substitute ${wrapper} $out/bin/hoogle \
96+ --subst-var out --subst-var-by shell ${stdenv.shell} \
97+ --subst-var-by hoogle ${hoogle}
98+ chmod +x $out/bin/hoogle
99+ '';
100+
101+ meta = {
102+ description = "A local Hoogle database";
103+ platforms = ghc.meta.platforms;
104+ hydraPlatforms = with stdenv.lib.platforms; none;
105+ maintainers = with stdenv.lib.maintainers; [ ttuegel ];
106+ };
107+}