|
1 |
| -{ |
2 |
| - lib, |
3 |
| - config, |
4 |
| - pkgs, |
5 |
| - ... |
6 |
| -}: |
| 1 | +{ lib, ... }: |
7 | 2 | let
|
8 |
| - inherit (config.docs.menu) |
9 |
| - sections |
10 |
| - ; |
11 |
| - |
12 | 3 | transformOption =
|
13 | 4 | let
|
14 | 5 | root = builtins.toString ../../.;
|
|
28 | 19 | decl;
|
29 | 20 | in
|
30 | 21 | opt: opt // { declarations = builtins.map transformDeclaration opt.declarations; };
|
31 |
| - |
32 |
| - docsPageModule = |
33 |
| - { name, config, ... }: |
34 |
| - { |
35 |
| - options = { |
36 |
| - enable = lib.mkOption { |
37 |
| - type = lib.types.bool; |
38 |
| - description = "Whether to enable this page/menu item."; |
39 |
| - default = true; |
40 |
| - example = false; |
41 |
| - }; |
42 |
| - target = lib.mkOption { |
43 |
| - type = lib.types.str; |
44 |
| - description = '' |
45 |
| - The target filepath, relative to the root of the docs. |
46 |
| - ''; |
47 |
| - default = lib.optionalString (name != "") (name + "/") + "index.md"; |
48 |
| - defaultText = lib.literalMD '' |
49 |
| - `<name>` joined with `"index.md"`. Separated by `"/"` if `<name>` is non-empty. |
50 |
| - ''; |
51 |
| - }; |
52 |
| - source = lib.mkOption { |
53 |
| - type = with lib.types; nullOr path; |
54 |
| - description = '' |
55 |
| - Markdown page. Set to null to create a menu entry without a corresponding file. |
56 |
| - ''; |
57 |
| - }; |
58 |
| - menu.location = lib.mkOption { |
59 |
| - type = with lib.types; listOf str; |
60 |
| - description = '' |
61 |
| - A location path that represents the page's position in the menu tree. |
62 |
| -
|
63 |
| - The text displayed in the menu is derived from this value, |
64 |
| - after the location of any parent nodes in the tree is removed. |
65 |
| -
|
66 |
| - For example, if this page has the location `[ "foo" "bar" ]` |
67 |
| - and there is another page with the location `[ "foo" ]`, |
68 |
| - then the menu will render as: |
69 |
| - ```markdown |
70 |
| - - foo |
71 |
| - - bar |
72 |
| - ``` |
73 |
| -
|
74 |
| - However if there was no other page with the `[ "foo" ]` location, |
75 |
| - the menu would instead render as: |
76 |
| - ```markdown |
77 |
| - - foo.bar |
78 |
| - ``` |
79 |
| - ''; |
80 |
| - default = |
81 |
| - let |
82 |
| - list = lib.splitString "/" config.target; |
83 |
| - last = lib.last list; |
84 |
| - rest = lib.dropEnd 1 list; |
85 |
| - in |
86 |
| - if last == "index.md" then |
87 |
| - rest |
88 |
| - else if lib.hasSuffix ".md" last then |
89 |
| - rest ++ [ (lib.removeSuffix ".md" last) ] |
90 |
| - else |
91 |
| - list; |
92 |
| - defaultText = lib.literalMD '' |
93 |
| - `target`, split by `"/"`, with any trailing `"index.md` or `".md"` suffixes removed. |
94 |
| - ''; |
95 |
| - }; |
96 |
| - menu.section = lib.mkOption { |
97 |
| - type = lib.types.enum (builtins.attrNames sections); |
98 |
| - description = '' |
99 |
| - Determines the menu section. |
100 |
| -
|
101 |
| - Must be a section defined in `docs.menu.sections`. |
102 |
| - ''; |
103 |
| - }; |
104 |
| - }; |
105 |
| - }; |
106 | 22 | in
|
107 | 23 | {
|
108 | 24 | options.docs._utils = lib.mkOption {
|
|
114 | 30 | };
|
115 | 31 |
|
116 | 32 | config.docs._utils = {
|
117 |
| - # A liberal type that permits any superset of docsPageModule |
118 |
| - docsPageLiberalType = lib.types.submodule [ |
119 |
| - { _module.check = false; } |
120 |
| - docsPageModule |
121 |
| - ]; |
122 |
| - |
123 | 33 | /**
|
124 | 34 | Uses `lib.optionAttrSetToDocList` to produce a list of docs-options.
|
125 | 35 |
|
|
160 | 70 | # See https://github.com/NixOS/nixpkgs/blob/61235d44/lib/options.nix#L103-L104
|
161 | 71 | # and https://github.com/NixOS/nixpkgs/blob/61235d44/nixos/lib/make-options-doc/default.nix#L128-L165
|
162 | 72 | ];
|
163 |
| - |
164 |
| - inherit docsPageModule; |
165 | 73 | };
|
166 | 74 | }
|
0 commit comments