Having a working setup for hoogle would be very useful for a large-ish project I’m working on. The flake.nix uses developPackage so just entering a shell allows me to run hoogle server. However, how do I set it up so I can use hoogle on
the package I’m working on, and
the set of packages I’ve installed locally, and
ideally with local links, i.e. no links to hackage?
I’ve tried to work this out through the documentation for hoogle but without success.
This sequence of commands gives me a hoogle on localhost:8080 for the local package:
> cabal haddock --haddock-internal --haddock-quickjump --haddock-hoogle --haddock-html
> hoogle generate --local=./dist-newstyle/build/x86_64-linux/ghc-9.8.2/pkg-0.0.1/doc/html/pkg --database=./local.hoo
> hoogle server --local --database=./local.hoo
but I can’t work out how to include the locally installed packages as well (i.e. the packages by ghc-pkg list, more or less).
Any help or pointers to instructions would be more appreciated.
magthe
July 13, 2024, 3:50pm
2
I found a way of getting an almost working setup for this:
cabal haddock --haddock-internal --haddock-quickjump --haddock-hoogle --haddock-html
hoogle_dir=$(dirname $(dirname $(readlink -f $(which hoogle))))
hoogle generate --database=local.hoo \
$(for d in $(fd -L .txt ${hoogle_dir}); do printf "--local=%s " $(dirname $d); done) \
--local=./dist-newstyle/build/x86_64-linux/ghc-9.8.2/pkg-0.0.1/doc/html/pkg
hoogle server --local --database=local.foo
The “almost working” part is that links in documentation are working.
joncol
September 24, 2024, 10:07am
3
Hi @magthe ,
Try something like the following perhaps:
ghc_version=9.8.2 # Change to whatever you use.
project_name=pkg # Change to whatever you use.
project_version=0.0.1 # Change to whatever you use.
html_dir=dist-newstyle/build/x86_64-linux/ghc-${ghc_version}/${project_name}-${project_version}/doc/html
cabal haddock-project --local
cabal haddock --haddock-hoogle
cp -v haddocks/*.* ${html_dir}
hoogle generate -v --local=${html_dir}/${project_name} --local=haddocks --database=${project_name}.hoo
hoogle server --database=${project_name}.hoo --local
I hope the above helps.
1 Like
@joncol thanks for the solution! I got it working on my end with the following modifications:
#!/bin/bash
set -euo pipefail
ghc_version=9.10.3
project_name=my-pkg
project_version=0.1.0.0
platform=aarch64-osx # <--- I'm not on x86
html_dir=dist-newstyle/build/${platform}/ghc-${ghc_version}/${project_name}-${project_version}/doc/html
cabal haddock-project # <--- no `--local` flag on cabal 3.16.0.0 (haddock 2.31.1)
cabal haddock --haddock-hoogle
cp -v haddocks/*.* ${html_dir}
hoogle generate -v --local=${html_dir}/${project_name} --local=haddocks --database=${project_name}.hoo
hoogle server --database=${project_name}.hoo --local
1 Like