summaryrefslogtreecommitdiffstats
path: root/lib/tests/modules/docs.nix
blob: 66d705da9609dc4006fc00c9669d90bcc34a2e0c (plain)
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
/*
  A basic documentation generating module.
  Declares and defines a `docs` option, suitable for making assertions about
  the extraction "phase" of documentation generation.
*/
{ lib, options, ... }:

let
  inherit (lib)
    head
    length
    mkOption
    types
    ;

  traceListSeq = l: v: lib.foldl' (a: b: lib.traceSeq b a) v l;

in

{
  options.docs = mkOption {
    type = types.lazyAttrsOf types.raw;
    description = ''
      All options to be rendered, without any visibility filtering applied.
    '';
  };
  config.docs = lib.zipAttrsWith (
    name: values:
    if length values > 1 then
      traceListSeq values abort "Multiple options with the same name: ${name}"
    else
      assert length values == 1;
      head values
  ) (map (opt: { ${opt.name} = opt; }) (lib.optionAttrSetToDocList options));
}