From 7be94d3b5956cfd0b1ca36d932490c830b4c2f51 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Mon, 12 May 2014 16:48:51 -0500 Subject: [PATCH] Add an expression for build fullly local Hoogle docs --- .../haskell/hoogle/hoogle-local.diff | 28 +++++ .../libraries/haskell/hoogle/local.nix | 116 ++++++++++++++++++ pkgs/top-level/haskell-packages.nix | 3 + 3 files changed, 147 insertions(+) create mode 100644 pkgs/development/libraries/haskell/hoogle/hoogle-local.diff create mode 100644 pkgs/development/libraries/haskell/hoogle/local.nix diff --git a/pkgs/development/libraries/haskell/hoogle/hoogle-local.diff b/pkgs/development/libraries/haskell/hoogle/hoogle-local.diff new file mode 100644 index 00000000000..df507c5a470 --- /dev/null +++ b/pkgs/development/libraries/haskell/hoogle/hoogle-local.diff @@ -0,0 +1,28 @@ +diff --git a/src/CmdLine/All.hs b/src/CmdLine/All.hs +index 94b1d48..f41f270 100644 +--- a/src/CmdLine/All.hs ++++ b/src/CmdLine/All.hs +@@ -86,8 +86,10 @@ guessLocal = do + ghc <- findExecutable "ghc" + home <- getHomeDirectory + lib <- getLibDir ++ path <- lookup "HOOGLE_DOC_PATH" <$> getEnvironment + let xs = [takeDirectory (takeDirectory lib) "doc" {- Windows, installed with Cabal -} ] ++ + [takeDirectory (takeDirectory ghc) "doc/html/libraries" | Just ghc <- [ghc] {- Windows, installed by GHC -} ] ++ ++ maybeToList path ++ + [home ".cabal/share/doc" {- Linux -} ] + filterM doesDirectoryExist xs + +diff --git a/src/Hoogle/Language/Haskell.hs b/src/Hoogle/Language/Haskell.hs +index b037f11..f2ac047 100644 +--- a/src/Hoogle/Language/Haskell.hs ++++ b/src/Hoogle/Language/Haskell.hs +@@ -112,7 +112,7 @@ setPriority pkg mod x = x{itemPriority = pri} + + setModuleURL (Just pkg) _ x | itemLevel x == 1 = x{itemURL=if null $ itemURL x then f $ itemName x else itemURL x} + where f xs = if "http://hackage.haskell.org/package/" `isPrefixOf` itemURL pkg +- then "http://hackage.haskell.org/packages/archive/" ++ itemName pkg ++ "/latest/doc/html/" ++ file ++ then "http://hackage.haskell.org/package/" ++ itemName pkg ++ "/docs/" ++ file + else takeDirectory (itemURL pkg) ++ "/" ++ file + where file = reps '.' '-' xs ++ ".html" + setModuleURL _ _ x = x diff --git a/pkgs/development/libraries/haskell/hoogle/local.nix b/pkgs/development/libraries/haskell/hoogle/local.nix new file mode 100644 index 00000000000..20816d3b2f9 --- /dev/null +++ b/pkgs/development/libraries/haskell/hoogle/local.nix @@ -0,0 +1,116 @@ +# 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. +# +# It is intended to be used in config.nix similarly to: +# +# { packageOverrides = pkgs: rec { +# +# haskellPackages = +# let callPackage = pkgs.lib.callPackageWith haskellPackages; +# in pkgs.recurseIntoAttrs (pkgs.haskellPackages.override { +# extraPrefs = self: { +# hoogleLocal = pkgs.haskellPackages.hoogleLocal.override { +# packages = with pkgs.haskellPackages; [ +# mmorph +# monadControl +# ] +# }; +# }; +# }); +# }} +# +# This will build mmorph and monadControl, and have the hoogle installation +# refer to their documentation via symlink so they are not garbage collected. + +{ cabal, aeson, binary, blazeBuilder, Cabal, caseInsensitive +, cmdargs, conduit, deepseq, filepath, haskellSrcExts, httpTypes +, parsec, QuickCheck, random, resourcet, safe, shake, tagsoup, text +, time, transformers, uniplate, vector, vectorAlgorithms, wai, warp + +, parallel, perl, wget, rehoo, haskellPlatform +, packages ? haskellPlatform.propagatedUserEnvPkgs +}: + +cabal.mkDerivation (self: rec { + pname = "hoogle"; + version = "4.2.32"; + sha256 = "1rhr7xh4x9fgflcszbsl176r8jq6rm81bwzmbz73f3pa1zf1v0zc"; + isLibrary = true; + isExecutable = true; + buildInputs = [ self.ghc Cabal parallel perl wget rehoo ] + ++ self.extraBuildInputs ++ packages; + buildDepends = [ + aeson binary blazeBuilder Cabal caseInsensitive cmdargs conduit + deepseq filepath haskellSrcExts httpTypes parsec QuickCheck random + resourcet safe shake tagsoup text time transformers uniplate vector + vectorAlgorithms wai warp parallel perl wget rehoo + ]; + testDepends = [ filepath ]; + testTarget = "--test-option=--no-net"; + + # The tests will fail because of the added documentation. + doCheck = false; + patches = [ ./hoogle-local.diff ]; + + docPackages = packages; + + postInstall = '' + if [ -z "$docPackages" ]; then + echo "ERROR: The packages attribute has not been set" + exit 1 + fi + + ensureDir $out/share/hoogle/doc + export HOOGLE_DOC_PATH=$out/share/hoogle/doc + + cd $out/share/hoogle + + function import_dbs() { + find $1 -name '*.txt' \ + | parallel -j$NIX_BUILD_CORES 'cp -p {} .; perl -i -pe "print \"\@url file://{//}/index.html\n\" if /^\@version/;" {/}; $out/bin/hoogle convert {/}' + } + + for i in $docPackages; do + import_dbs $i/share/doc + ln -sf $i/share/doc/* $out/share/hoogle/doc + done + + import_dbs ${self.ghc}/share/doc/ghc*/html/libraries + ln -sf ${self.ghc}/share/doc/ghc*/html/libraries/* $out/share/hoogle/doc + + unset http_proxy + unset ftp_proxy + + chmod 644 *.hoo *.txt + $out/bin/hoogle data -d $PWD --redownload -l $(echo *.txt | sed 's/\.txt//g') + PATH=$out/bin:$PATH ${rehoo}/bin/rehoo -j4 -c64 . + + rm -fr downloads *.txt *.dep + mv default.hoo x || exit 0 + rm -f *.hoo + mv x default.hoo || exit 1 + + if [ ! -f default.hoo ]; then + echo "Unable to build the default Hoogle database" + exit 1 + fi + + mv $out/bin/hoogle $out/bin/.hoogle-wrapped + cat - > $out/bin/hoogle <