-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault.nix
37 lines (32 loc) · 1.21 KB
/
default.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
{ pkgs, lib ? pkgs.lib }:
let
inherit (lib) isAttrs optionalAttrs isDerivation mapAttrs;
# Recursively replace each derivation in the given attribute set
# with the same derivation but with the `outPath` attribute set to
# the string `"\${pkgs.attribute.path}"`. This allows the
# documentation to refer to derivations through their values without
# establishing an actual dependency on the derivation output.
#
# This is not perfect, but it seems to cover a vast majority of use
# cases.
#
# Caveat: even if the package is reached by a different means, the
# path above will be shown and not e.g.
# `${config.services.foo.package}`.
scrubDerivations = prefixPath: attrs:
let
scrubDerivation = name: value:
let pkgAttrName = prefixPath + "." + name;
in if isAttrs value then
scrubDerivations pkgAttrName value
// optionalAttrs (isDerivation value) {
outPath = "\${${pkgAttrName}}";
}
else
value;
in mapAttrs scrubDerivation attrs;
in {
inherit scrubDerivations;
buildModulesDocs = import ./lib/modules-doc.nix { inherit lib pkgs; };
buildDocBookDocs = import ./lib/manual-docbook.nix { inherit lib pkgs; };
}