88 buildPackages ,
99 haskellPackages ,
1010 writeText ,
11+ runCommand ,
1112} :
1213
1314# This argument is a function which selects a list of Haskell packages from any
4041 # we grab the doc outputs
4142 ( map ( lib . getOutput "doc" ) packages ) ;
4243
44+ # Hoogle database path, relative to `$out`.
45+ databasePath = "share/doc/hoogle/default.hoo" ;
46+
4347in
44- buildPackages . stdenv . mkDerivation {
48+ buildPackages . stdenv . mkDerivation ( finalAttrs : {
4549 name = "hoogle-with-packages" ;
4650 buildInputs = [
4751 ghc
@@ -101,8 +105,10 @@ buildPackages.stdenv.mkDerivation {
101105 )
102106 }
103107
108+ databasePath="$out/"${ lib . escapeShellArg databasePath }
109+
104110 echo building hoogle database
105- hoogle generate --database $out/share/doc/hoogle/default.hoo --local=$out/share/doc/hoogle
111+ hoogle generate --database "$databasePath" --local=$out/share/doc/hoogle
106112
107113 echo building haddock index
108114 # adapted from GHC's gen_contents_index
@@ -122,13 +128,23 @@ buildPackages.stdenv.mkDerivation {
122128 echo finishing up
123129 mkdir -p $out/bin
124130 substitute ${ wrapper } $out/bin/hoogle \
125- --subst-var out --subst-var-by shell ${ stdenv . shell } \
131+ --subst-var-by shell ${ stdenv . shell } \
132+ --subst-var-by database "$databasePath" \
126133 --subst-var-by hoogle ${ hoogle }
127134 chmod +x $out/bin/hoogle
128135 '' ;
129136
130137 passthru = {
131138 isHaskellLibrary = false ; # for the filter in ./with-packages-wrapper.nix
139+
140+ # The path to the Hoogle database.
141+ database = "${ finalAttrs . finalPackage } /${ databasePath } " ;
142+
143+ tests . can-search-database = runCommand "can-search-database" { } ''
144+ # This succeeds even if no results are found, but `Prelude.map` should
145+ # always be available.
146+ ${ finalAttrs . finalPackage } /bin/hoogle search Prelude.map > $out
147+ '' ;
132148 } ;
133149
134150 meta = {
@@ -137,4 +153,4 @@ buildPackages.stdenv.mkDerivation {
137153 hydraPlatforms = with lib . platforms ; none ;
138154 maintainers = with lib . maintainers ; [ ttuegel ] ;
139155 } ;
140- }
156+ } )
0 commit comments