Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
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{ lib, stdenv, buildPackages, haskellPackages 6, writeText 7}: 8 9# This argument is a function which selects a list of Haskell packages from any 10# passed Haskell package set. 11# 12# Example: 13# (hpkgs: [ hpkgs.mtl hpkgs.lens ]) 14selectPackages: 15 16let 17 inherit (haskellPackages) ghc hoogle; 18 packages = selectPackages haskellPackages; 19 20 wrapper = ./hoogle-local-wrapper.sh; 21 isGhcjs = ghc.isGhcjs or false; 22 opts = lib.optionalString; 23 haddockExe = 24 if !isGhcjs 25 then "haddock" 26 else "haddock-ghcjs"; 27 ghcDocLibDir = 28 if !isGhcjs 29 then ghc.doc + "/share/doc/ghc*/html/libraries" 30 else ghc + "/doc/lib"; 31 # On GHCJS, use a stripped down version of GHC's prologue.txt 32 prologue = 33 if !isGhcjs 34 then "${ghcDocLibDir}/prologue.txt" 35 else writeText "ghcjs-prologue.txt" '' 36 This index includes documentation for many Haskell modules. 37 ''; 38 39 docPackages = lib.closePropagation 40 # we grab the doc outputs 41 (map (lib.getOutput "doc") packages); 42 43in 44buildPackages.stdenv.mkDerivation { 45 name = "hoogle-with-packages"; 46 buildInputs = [ghc hoogle]; 47 48 # compiling databases takes less time than copying the results 49 # between machines. 50 preferLocalBuild = true; 51 52 # we still allow substitutes because a database is relatively small and if it 53 # is already built downloading is probably faster. The substitution will only 54 # trigger for users who have already cached the database on a substituter and 55 # thus probably intend to substitute it. 56 allowSubstitutes = true; 57 58 inherit docPackages; 59 60 passAsFile = ["buildCommand"]; 61 62 buildCommand = '' 63 ${let # Filter out nulls here to work around https://github.com/NixOS/nixpkgs/issues/82245 64 # If we don't then grabbing `p.name` here will fail. 65 packages' = lib.filter (p: p != null) packages; 66 in lib.optionalString (packages' != [] -> docPackages == []) 67 ("echo WARNING: localHoogle package list empty, even though" 68 + " the following were specified: " 69 + lib.concatMapStringsSep ", " (p: p.name) packages')} 70 mkdir -p $out/share/doc/hoogle 71 72 echo importing builtin packages 73 for docdir in ${ghcDocLibDir}"/"*; do 74 name="$(basename $docdir)" 75 ${opts isGhcjs ''docdir="$docdir/html"''} 76 if [[ -d $docdir ]]; then 77 ln -sfn $docdir $out/share/doc/hoogle/$name 78 fi 79 done 80 81 echo importing other packages 82 ${lib.concatMapStringsSep "\n" (el: '' 83 ln -sfn ${el.haddockDir} "$out/share/doc/hoogle/${el.name}" 84 '') 85 (lib.filter (el: el.haddockDir != null) 86 (builtins.map (p: { haddockDir = if p ? haddockDir then p.haddockDir p else null; 87 name = p.pname; }) 88 docPackages))} 89 90 echo building hoogle database 91 hoogle generate --database $out/share/doc/hoogle/default.hoo --local=$out/share/doc/hoogle 92 93 echo building haddock index 94 # adapted from GHC's gen_contents_index 95 cd $out/share/doc/hoogle 96 97 args= 98 for hdfile in $(ls -1 *"/"*.haddock | grep -v '/ghc\.haddock' | sort); do 99 name_version=`echo "$hdfile" | sed 's#/.*##'` 100 args="$args --read-interface=$name_version,$hdfile" 101 done 102 103 ${ghc}/bin/${haddockExe} --gen-index --gen-contents -o . \ 104 -t "Haskell Hierarchical Libraries" \ 105 -p ${prologue} \ 106 $args 107 108 echo finishing up 109 mkdir -p $out/bin 110 substitute ${wrapper} $out/bin/hoogle \ 111 --subst-var out --subst-var-by shell ${stdenv.shell} \ 112 --subst-var-by hoogle ${hoogle} 113 chmod +x $out/bin/hoogle 114 ''; 115 116 passthru = { 117 isHaskellLibrary = false; # for the filter in ./with-packages-wrapper.nix 118 }; 119 120 meta = { 121 description = "A local Hoogle database"; 122 platforms = ghc.meta.platforms; 123 hydraPlatforms = with lib.platforms; none; 124 maintainers = with lib.maintainers; [ ttuegel ]; 125 }; 126}