mirror of
https://gitlab.com/TECHNOFAB/nixlets.git
synced 2025-12-12 01:50:05 +01:00
feat: add function to generate docs for nixlet values
add docs for nixlets in this repo to the mkdocs site
This commit is contained in:
parent
2cb8c69aaa
commit
48e8cf48b0
3 changed files with 214 additions and 74 deletions
84
lib/valuesDocs.nix
Normal file
84
lib/valuesDocs.nix
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
{
|
||||
lib,
|
||||
nixlet,
|
||||
transformOptions ? opt: opt,
|
||||
filter ? _: true,
|
||||
headingDepth ? 3,
|
||||
...
|
||||
}: let
|
||||
inherit
|
||||
(lib)
|
||||
removeSuffix
|
||||
concatStringsSep
|
||||
mapAttrsToList
|
||||
concatStrings
|
||||
replicate
|
||||
;
|
||||
|
||||
_transformOptions = opt:
|
||||
transformOptions (opt
|
||||
// {
|
||||
visible = let
|
||||
filtered = !builtins.elem (builtins.head opt.loc) ["_module"];
|
||||
in
|
||||
filtered && opt.visible && (filter opt);
|
||||
name = lib.removePrefix "config." opt.name;
|
||||
});
|
||||
|
||||
rawOpts = lib.optionAttrSetToDocList nixlet.values.options;
|
||||
transformedOpts = map _transformOptions rawOpts;
|
||||
filteredOpts = lib.filter (opt: opt.visible && !opt.internal) transformedOpts;
|
||||
|
||||
optionsNix = builtins.listToAttrs (
|
||||
map (o: {
|
||||
name = o.name;
|
||||
value = removeAttrs o [
|
||||
"visible"
|
||||
"internal"
|
||||
];
|
||||
})
|
||||
filteredOpts
|
||||
);
|
||||
|
||||
optToMd = opt: let
|
||||
headingDecl = concatStrings (replicate headingDepth "#");
|
||||
in
|
||||
''
|
||||
${headingDecl} `${opt.name}`
|
||||
|
||||
${
|
||||
if opt.description != null
|
||||
then opt.description
|
||||
else "(no description)"
|
||||
}
|
||||
|
||||
**Type**:
|
||||
|
||||
```console
|
||||
${opt.type}
|
||||
```
|
||||
''
|
||||
+ (lib.optionalString (opt ? default && opt.default != null) ''
|
||||
|
||||
**Default value**:
|
||||
|
||||
```nix
|
||||
${removeSuffix "\n" opt.default.text}
|
||||
```
|
||||
'')
|
||||
+ (lib.optionalString (opt ? example) ''
|
||||
|
||||
**Example value**:
|
||||
|
||||
```nix
|
||||
${removeSuffix "\n" opt.example.text}
|
||||
```
|
||||
'')
|
||||
+ "\n";
|
||||
|
||||
opts = mapAttrsToList (name: opt:
|
||||
optToMd opt)
|
||||
optionsNix;
|
||||
markdown = concatStringsSep "\n" opts;
|
||||
in
|
||||
builtins.toFile "values-doc.md" markdown
|
||||
Loading…
Add table
Add a link
Reference in a new issue