Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)

haskellPackages.mkDerivation: add doHaddockInterfaces option

This adds a new builder option `doHaddockInterfaces` to enable the -haddock flag in GHC,
which results in Haddock comments parsed at compile-time and embedded in
interface files. These are used by the :doc command in GHCi, as well as IDE
tools like ghcide and hls to display docs on hover.

The `-haddock` flag has been around since at least 8.2, even though it does not
get a mention in the GHC Users guide.

There are two downsides to turning on this flag:

1. Increased compile times, since Haddocks must be parsed and then encoded
2. Haddock parse errors now become compile errors for GHC < 9.0.1
(https://gitlab.haskell.org/ghc/ghc/-/issues/8944)

Thus we only enable the feature if we have GHC 9.0.1 and haddock is
enabled; when 9.0.1 becomes the default GHC, we may need to reevaluate
the performance concern.

Co-authored-by: sternenseemann <sternenseemann@systemli.org>

authored by

Pepe Iborra
sternenseemann
and committed by
sternenseemann
d68033af da2c9c6e

+6 -1
+6 -1
pkgs/development/haskell-modules/generic-builder.nix
··· 56 56 , mainProgram ? null 57 57 , doCoverage ? false 58 58 , doHaddock ? !(ghc.isHaLVM or false) 59 + , doHaddockInterfaces ? doHaddock && lib.versionAtLeast ghc.version "9.0.1" 59 60 , passthru ? {} 60 61 , pkg-configDepends ? [], libraryPkgconfigDepends ? [], executablePkgconfigDepends ? [], testPkgconfigDepends ? [], benchmarkPkgconfigDepends ? [] 61 62 , testDepends ? [], testHaskellDepends ? [], testSystemDepends ? [], testFrameworkDepends ? [] ··· 226 227 ] ++ optionals isCross ([ 227 228 "--configure-option=--host=${stdenv.hostPlatform.config}" 228 229 ] ++ crossCabalFlags 229 - ) ++ optionals enableSeparateBinOutput ["--bindir=${binDir}"]; 230 + ) ++ optionals enableSeparateBinOutput [ 231 + "--bindir=${binDir}" 232 + ] ++ optionals (doHaddockInterfaces && isLibrary) [ 233 + "--ghc-options=-haddock" 234 + ]; 230 235 231 236 setupCompileFlags = [ 232 237 (optionalString (!coreSetup) "-${nativePackageDbFlag}=$setupPackageConfDir")