ghc.withPackages: install documentation to -with-packages output

* Will make it so that GHC.Paths's docdir NIX_GHC_DOCDIR points to an
  actual directory.

* Documentation of all packages in the environment is available in
  `$out/share/doc`.

This has previously been attempted in #76842 and reverted in #77442,
since documentation can collide when the libraries wouldn't (thanks to
the hash in the lib filename). `symlinkJoin` allows collision, so this
solution should be akin to #77523 (minus `buildEnv`, one step at a
time). `installDocumentation = false` restores the old behavior.

Collision in the documentation only happen if the dependency closure of
the given packages has more than one different derivation for the same
library of the very same version. I'm personally inclined not to claim
that our infrastructure does anything sensible in this case.
Additionally, the documentation is likely largely the same in such
cases (unless it is heavily patched).

Resolves #150666.
Resolves #76837.
Closes #150968.
Closes #77523.
This commit is contained in:
sternenseemann 2021-12-16 09:13:30 -04:00
parent 02cbec616a
commit 727491cd95
3 changed files with 26 additions and 2 deletions

View file

@ -344,6 +344,17 @@
<literal>nixos/modules/profiles/minimal.nix</literal> profile.
</para>
</listitem>
<listitem>
<para>
The <literal>ghcWithPackages</literal> and
<literal>ghcWithHoogle</literal> wrappers will now also
symlink GHCs and all included libraries documentation to
<literal>$out/share/doc</literal> for convenience. If
undesired, the old behavior can be restored by overriding the
builders with
<literal>{ installDocumentation = false; }</literal>.
</para>
</listitem>
<listitem>
<para>
<literal>mastodon</literal> now supports connection to a

View file

@ -94,6 +94,11 @@ In addition to numerous new and upgraded packages, this release has the followin
- The minimal ISO image now uses the `nixos/modules/profiles/minimal.nix` profile.
- The `ghcWithPackages` and `ghcWithHoogle` wrappers will now also symlink GHC's
and all included libraries' documentation to `$out/share/doc` for convenience.
If undesired, the old behavior can be restored by overriding the builders with
`{ installDocumentation = false; }`.
- `mastodon` now supports connection to a remote `PostgreSQL` database.
- `services.peertube` now requires you to specify the secret file `secrets.secretsFile`. It can be generated by running `openssl rand -hex 32`.

View file

@ -4,6 +4,8 @@
# platform that has NCG support
, useLLVM ? false
, withHoogle ? false
# Whether to install `doc` outputs for GHC and all included libraries.
, installDocumentation ? true
, hoogleWithPackages
, postBuild ? ""
, ghcLibdir ? null # only used by ghcjs, when resolving plugins
@ -54,7 +56,11 @@ let
else "$out/lib/${ghc.targetPrefix}${ghc.haskellCompilerName}";
docDir = "$out/share/doc/ghc/html";
packageCfgDir = "${libDir}/package.conf.d";
paths = lib.filter (x: x ? isHaskellLibrary) (lib.closePropagation packages);
paths = lib.concatLists (
builtins.map
(pkg: [ pkg ] ++ lib.optionals installDocumentation [ (lib.getOutput "doc" pkg) ])
(lib.filter (x: x ? isHaskellLibrary) (lib.closePropagation packages))
);
hasLibraries = lib.any (x: x.isHaskellLibrary) paths;
# CLang is needed on Darwin for -fllvm to work:
# https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/codegens.html#llvm-code-generator-fllvm
@ -71,7 +77,9 @@ symlinkJoin {
# if such a feature is needed, the real compiler name should be saved
# as a dedicated drv attribute, like `compiler-name`
name = ghc.name + "-with-packages";
paths = paths ++ [ghc];
paths = paths
++ [ ghc ]
++ lib.optionals installDocumentation [ ghc.doc ];
nativeBuildInputs = [ makeWrapper ];
postBuild = ''
# wrap compiler executables with correct env variables