@@ -16,6 +16,7 @@
16, preBuild ? null, postBuild ? null
16, preBuild ? null, postBuild ? null
17, preCheck ? null, postCheck ? null
17, preCheck ? null, postCheck ? null
18, preInstall ? null, postInstall ? null
18, preInstall ? null, postInstall ? null
19+, preHaddock ? null, postHaddock ? null
19, shellHook ? null
20, shellHook ? null
21, doCheck ? component.doCheck || haskellLib.isTest componentId
22, doCheck ? component.doCheck || haskellLib.isTest componentId
@@ -25,6 +26,11 @@
26, static ? stdenv.hostPlatform.isMusl
27, static ? stdenv.hostPlatform.isMusl
27, deadCodeElimination ? true
28, deadCodeElimination ? true
30+# Options for Haddock generation
31+, doHaddock ? component.doHaddock # Enable haddock and hoogle generation
32+, doHoogle ? true # Also build a hoogle index
33+, hyperlinkSource ? true # Link documentation to the source code
@@ -164,7 +170,8 @@ let
164 # other flags
170 # other flags
165 "--enable-executable-stripping"
171 "--enable-executable-stripping"
166 "--enable-library-stripping"
172 "--enable-library-stripping"
173+ ] ++ lib.optional doHaddock' "--docdir=${docdir "$doc"}"
167− ] ++ lib.optional (deadCodeElimination && stdenv.hostPlatform.isLinux) "--enable-split-sections"
174+ ++ lib.optional (deadCodeElimination && stdenv.hostPlatform.isLinux) "--enable-split-sections"
168 ++ lib.optional (static) "--enable-static"
175 ++ lib.optional (static) "--enable-static"
169 ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) (
176 ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) (
170 map (arg: "--hsc2hs-option=" + arg) ["--cross-compile" "--via-asm"]
177 map (arg: "--hsc2hs-option=" + arg) ["--cross-compile" "--via-asm"]
@@ -182,7 +189,14 @@ let
182 inherit package configFiles;
189 inherit package configFiles;
192+ # the target dir for haddock documentation
193+ docdir = docoutput: docoutput + "/share/doc/" + componentId.cname;
195+ doHaddock' = doHaddock && (haskellLib.isLibrary componentId);
197+in stdenv.lib.fix (drv:
185−in stdenv.mkDerivation ({
199+stdenv.mkDerivation ({
186 name = fullName;
200 name = fullName;
188 inherit src doCheck doCrossCheck dontPatchELF dontStrip;
202 inherit src doCheck doCrossCheck dontPatchELF dontStrip;
@@ -192,6 +206,10 @@ in stdenv.mkDerivation ({
192 config = component;
206 config = component;
193 inherit configFiles;
207 inherit configFiles;
194 env = shellWrappers;
208 env = shellWrappers;
210+ # The directory containing the haddock documentation.
211+ # `null' if no haddock documentation was built.
212+ haddockDir = if doHaddock' then "${docdir drv.doc}/html" else null;
@@ -216,13 +234,17 @@ in stdenv.mkDerivation ({
216 ++ component.pkgconfig;
234 ++ component.pkgconfig;
218 nativeBuildInputs =
236 nativeBuildInputs =
219− [ghc]
237+ [ghc buildPackages.removeReferencesTo]
220 ++ lib.optional (component.pkgconfig != []) pkgconfig
238 ++ lib.optional (component.pkgconfig != []) pkgconfig
221 ++ executableToolDepends;
239 ++ executableToolDepends;
223 SETUP_HS = setup + /bin/Setup;
241 SETUP_HS = setup + /bin/Setup;
243+ outputs = ["out" ] ++ (lib.optional doHaddock' "doc");
246+ preInstallPhases = lib.optional doHaddock' "haddockPhase";
226 prePatch = lib.optionalString (cabalFile != null) ''
248 prePatch = lib.optionalString (cabalFile != null) ''
227 cat ${cabalFile} > ${package.identifier.name}.cabal
249 cat ${cabalFile} > ${package.identifier.name}.cabal
@@ -250,6 +272,32 @@ in stdenv.mkDerivation ({
250 runHook postCheck
272 runHook postCheck
277+ docdir="${docdir "$doc"}"
282+ ${lib.optionalString doHoogle "--hoogle"} \
283+ ${lib.optionalString hyperlinkSource "--hyperlink-source"} \
284+ ${lib.concatStringsSep " " component.setupHaddockFlags}
286+ html="dist/doc/html/${componentId.cname}"
288+ if [ -d "$html" ]; then
289+ # Ensure that libraries are not pulled into the docs closure.
290+ # As an example, the prettified source code of a
291+ # Paths_package module will contain store paths of the library package.
292+ for x in "$html/src/"*.html; do
293+ remove-references-to -t $out $x
296+ cp -R "$html" "$docdir"/html
253 # Note: Cabal does *not* copy test executables during the `install` phase.
301 # Note: Cabal does *not* copy test executables during the `install` phase.
254 installPhase = ''
302 installPhase = ''
255 runHook preInstall
303 runHook preInstall
@@ -278,15 +326,10 @@ in stdenv.mkDerivation ({
279# patches can (if they like) depend on the version and revision of the package.
327# patches can (if they like) depend on the version and revision of the package.
280// lib.optionalAttrs (patches != []) { patches = map (p: if builtins.isFunction p then p { inherit (package.identifier) version; inherit revision; } else p) patches; }
328// lib.optionalAttrs (patches != []) { patches = map (p: if builtins.isFunction p then p { inherit (package.identifier) version; inherit revision; } else p) patches; }
281−// lib.optionalAttrs (preUnpack != "") { inherit preUnpack; }
329+// haskellLib.optionalHooks {
282−// lib.optionalAttrs (postUnpack != "") { inherit postUnpack; }
330+ inherit preUnpack postUnpack preConfigure postConfigure
283−// lib.optionalAttrs (preConfigure != "") { inherit preConfigure; }
331+ preBuild postBuild preCheck postCheck
284−// lib.optionalAttrs (postConfigure != "") { inherit postConfigure; }
332+ preInstall postInstall preHaddock postHaddock;
285−// lib.optionalAttrs (preBuild != "") { inherit preBuild; }
333+}
286−// lib.optionalAttrs (postBuild != "") { inherit postBuild; }
287−// lib.optionalAttrs (preCheck != "") { inherit preCheck; }
288−// lib.optionalAttrs (postCheck != "") { inherit postCheck; }
289−// lib.optionalAttrs (preInstall != "") { inherit preInstall; }
290−// lib.optionalAttrs (postInstall != "") { inherit postInstall; }
291// lib.optionalAttrs (stdenv.buildPlatform.libc == "glibc"){ LOCALE_ARCHIVE = "${buildPackages.glibcLocales}/lib/locale/locale-archive"; }
334// lib.optionalAttrs (stdenv.buildPlatform.libc == "glibc"){ LOCALE_ARCHIVE = "${buildPackages.glibcLocales}/lib/locale/locale-archive"; }