Skip to content

Commit b2c1ae9

Browse files
authored
haskellPackages.ghcWithHoogle: add passthru.hoogle (#403488)
2 parents 315edfe + 03c4431 commit b2c1ae9

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

pkgs/development/haskell-modules/hoogle-local-wrapper.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
COMMAND=$1
44
shift
5-
exec @hoogle@/bin/hoogle "$COMMAND" --database @out@/share/doc/hoogle/default.hoo "$@"
5+
exec @hoogle@/bin/hoogle "$COMMAND" --database @database@ "$@"

pkgs/development/haskell-modules/hoogle.nix

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
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
@@ -40,8 +41,11 @@ let
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+
4347
in
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+
})

pkgs/development/haskell-modules/with-packages-wrapper.nix

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ selectPackages:
4747
let
4848
inherit (haskellPackages) llvmPackages ghc;
4949

50-
packages =
51-
selectPackages haskellPackages
52-
++ lib.optional withHoogle (hoogleWithPackages selectPackages);
50+
hoogleWithPackages' = if withHoogle then hoogleWithPackages selectPackages else null;
51+
52+
packages = selectPackages haskellPackages ++ [ hoogleWithPackages' ];
5353

5454
isGhcjs = ghc.isGhcjs or false;
5555
isHaLVM = ghc.isHaLVM or false;
@@ -202,6 +202,8 @@ else
202202
passthru = {
203203
inherit (ghc) version meta;
204204

205+
hoogle = hoogleWithPackages';
206+
205207
# Inform users about backwards incompatibilities with <= 21.05
206208
override =
207209
_:

0 commit comments

Comments
 (0)