2015-01-22 23:10:08 +00:00
|
|
|
# Install not only the Hoogle library and executable, but also a local Hoogle
|
|
|
|
# database which provides "Source" links to all specified 'packages' -- or the
|
|
|
|
# current Haskell Platform if no custom package set is provided.
|
|
|
|
|
2021-11-20 16:43:12 +00:00
|
|
|
{ lib, stdenv, buildPackages, haskellPackages
|
|
|
|
, writeText
|
2015-01-22 23:10:08 +00:00
|
|
|
}:
|
|
|
|
|
2021-11-20 16:43:12 +00:00
|
|
|
# This argument is a function which selects a list of Haskell packages from any
|
|
|
|
# passed Haskell package set.
|
|
|
|
#
|
|
|
|
# Example:
|
|
|
|
# (hpkgs: [ hpkgs.mtl hpkgs.lens ])
|
|
|
|
selectPackages:
|
|
|
|
|
2015-01-22 23:10:08 +00:00
|
|
|
let
|
2021-11-20 16:43:12 +00:00
|
|
|
inherit (haskellPackages) ghc hoogle;
|
|
|
|
packages = selectPackages haskellPackages;
|
|
|
|
|
2015-01-22 23:10:08 +00:00
|
|
|
wrapper = ./hoogle-local-wrapper.sh;
|
2016-02-01 04:00:43 +00:00
|
|
|
isGhcjs = ghc.isGhcjs or false;
|
2016-02-01 05:10:45 +00:00
|
|
|
opts = lib.optionalString;
|
2016-02-01 04:00:43 +00:00
|
|
|
haddockExe =
|
|
|
|
if !isGhcjs
|
|
|
|
then "haddock"
|
|
|
|
else "haddock-ghcjs";
|
2017-02-14 21:50:29 +00:00
|
|
|
ghcDocLibDir =
|
2016-02-01 04:00:43 +00:00
|
|
|
if !isGhcjs
|
2021-01-24 09:19:10 +00:00
|
|
|
then ghc.doc + "/share/doc/ghc*/html/libraries"
|
|
|
|
else ghc + "/doc/lib";
|
2016-02-01 04:00:43 +00:00
|
|
|
# On GHCJS, use a stripped down version of GHC's prologue.txt
|
|
|
|
prologue =
|
|
|
|
if !isGhcjs
|
2017-02-14 21:50:29 +00:00
|
|
|
then "${ghcDocLibDir}/prologue.txt"
|
2016-02-01 04:00:43 +00:00
|
|
|
else writeText "ghcjs-prologue.txt" ''
|
|
|
|
This index includes documentation for many Haskell modules.
|
|
|
|
'';
|
2016-11-21 19:44:42 +00:00
|
|
|
|
2017-08-06 20:02:50 +00:00
|
|
|
# TODO: closePropagation is deprecated; replace
|
|
|
|
docPackages = lib.closePropagation
|
|
|
|
# we grab the doc outputs
|
2018-06-22 12:21:44 +00:00
|
|
|
(map (lib.getOutput "doc") packages);
|
2016-11-21 19:44:42 +00:00
|
|
|
|
2015-01-22 23:10:08 +00:00
|
|
|
in
|
2019-12-24 23:17:41 +00:00
|
|
|
buildPackages.stdenv.mkDerivation {
|
2021-11-20 16:43:12 +00:00
|
|
|
name = "hoogle-with-packages";
|
2016-08-31 09:53:18 +00:00
|
|
|
buildInputs = [ghc hoogle];
|
2015-01-22 23:10:08 +00:00
|
|
|
|
2016-11-21 19:44:42 +00:00
|
|
|
inherit docPackages;
|
2015-08-17 23:55:04 +00:00
|
|
|
|
2019-08-22 02:38:03 +00:00
|
|
|
passAsFile = ["buildCommand"];
|
|
|
|
|
|
|
|
buildCommand = ''
|
2021-06-16 02:32:20 +00:00
|
|
|
${let # Filter out nulls here to work around https://github.com/NixOS/nixpkgs/issues/82245
|
|
|
|
# If we don't then grabbing `p.name` here will fail.
|
|
|
|
packages' = lib.filter (p: p != null) packages;
|
|
|
|
in lib.optionalString (packages' != [] -> docPackages == [])
|
2017-08-06 20:02:50 +00:00
|
|
|
("echo WARNING: localHoogle package list empty, even though"
|
|
|
|
+ " the following were specified: "
|
2021-06-16 02:32:20 +00:00
|
|
|
+ lib.concatMapStringsSep ", " (p: p.name) packages')}
|
2015-08-17 23:55:04 +00:00
|
|
|
mkdir -p $out/share/doc/hoogle
|
2015-01-22 23:10:08 +00:00
|
|
|
|
2015-08-17 23:55:04 +00:00
|
|
|
echo importing builtin packages
|
2017-08-19 14:37:56 +00:00
|
|
|
for docdir in ${ghcDocLibDir}"/"*; do
|
2016-02-01 05:10:45 +00:00
|
|
|
name="$(basename $docdir)"
|
|
|
|
${opts isGhcjs ''docdir="$docdir/html"''}
|
2015-08-17 23:55:04 +00:00
|
|
|
if [[ -d $docdir ]]; then
|
2016-02-01 05:10:45 +00:00
|
|
|
ln -sfn $docdir $out/share/doc/hoogle/$name
|
2015-08-17 23:55:04 +00:00
|
|
|
fi
|
2015-01-22 23:10:08 +00:00
|
|
|
done
|
|
|
|
|
2015-08-17 23:55:04 +00:00
|
|
|
echo importing other packages
|
2017-08-06 20:02:50 +00:00
|
|
|
${lib.concatMapStringsSep "\n" (el: ''
|
|
|
|
ln -sfn ${el.haddockDir} "$out/share/doc/hoogle/${el.name}"
|
|
|
|
'')
|
2018-06-22 12:21:44 +00:00
|
|
|
(lib.filter (el: el.haddockDir != null)
|
|
|
|
(builtins.map (p: { haddockDir = if p ? haddockDir then p.haddockDir p else null;
|
|
|
|
name = p.pname; })
|
|
|
|
docPackages))}
|
2015-01-22 23:10:08 +00:00
|
|
|
|
2015-08-17 23:55:04 +00:00
|
|
|
echo building hoogle database
|
2016-08-31 09:53:18 +00:00
|
|
|
hoogle generate --database $out/share/doc/hoogle/default.hoo --local=$out/share/doc/hoogle
|
2015-01-22 23:10:08 +00:00
|
|
|
|
2015-08-17 23:55:04 +00:00
|
|
|
echo building haddock index
|
|
|
|
# adapted from GHC's gen_contents_index
|
|
|
|
cd $out/share/doc/hoogle
|
|
|
|
|
|
|
|
args=
|
2017-08-19 14:37:56 +00:00
|
|
|
for hdfile in $(ls -1 *"/"*.haddock | grep -v '/ghc\.haddock' | sort); do
|
2015-08-17 23:55:04 +00:00
|
|
|
name_version=`echo "$hdfile" | sed 's#/.*##'`
|
|
|
|
args="$args --read-interface=$name_version,$hdfile"
|
|
|
|
done
|
|
|
|
|
2016-02-01 04:00:43 +00:00
|
|
|
${ghc}/bin/${haddockExe} --gen-index --gen-contents -o . \
|
2015-08-17 23:55:04 +00:00
|
|
|
-t "Haskell Hierarchical Libraries" \
|
2016-02-01 04:00:43 +00:00
|
|
|
-p ${prologue} \
|
2015-08-17 23:55:04 +00:00
|
|
|
$args
|
2015-01-22 23:10:08 +00:00
|
|
|
|
2015-08-17 23:55:04 +00:00
|
|
|
echo finishing up
|
2015-01-22 23:10:08 +00:00
|
|
|
mkdir -p $out/bin
|
|
|
|
substitute ${wrapper} $out/bin/hoogle \
|
|
|
|
--subst-var out --subst-var-by shell ${stdenv.shell} \
|
|
|
|
--subst-var-by hoogle ${hoogle}
|
|
|
|
chmod +x $out/bin/hoogle
|
|
|
|
'';
|
|
|
|
|
2015-08-17 19:45:13 +00:00
|
|
|
passthru = {
|
|
|
|
isHaskellLibrary = false; # for the filter in ./with-packages-wrapper.nix
|
|
|
|
};
|
|
|
|
|
2015-01-22 23:10:08 +00:00
|
|
|
meta = {
|
|
|
|
description = "A local Hoogle database";
|
|
|
|
platforms = ghc.meta.platforms;
|
2021-01-23 17:15:07 +00:00
|
|
|
hydraPlatforms = with lib.platforms; none;
|
|
|
|
maintainers = with lib.maintainers; [ ttuegel ];
|
2015-01-22 23:10:08 +00:00
|
|
|
};
|
|
|
|
}
|