mirror of
https://gitlab.com/TECHNOFAB/nixlets.git
synced 2025-12-11 17:40:07 +01:00
85 lines
1.6 KiB
Nix
85 lines
1.6 KiB
Nix
|
|
{
|
||
|
|
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
|