From c7026a993c4b837dcee39f669e1cc4123f4eb53d Mon Sep 17 00:00:00 2001 From: Minijackson Date: Mon, 8 Nov 2021 16:26:42 +0100 Subject: initial commit --- doc-options-md.nix | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 doc-options-md.nix (limited to 'doc-options-md.nix') diff --git a/doc-options-md.nix b/doc-options-md.nix new file mode 100644 index 0000000..ea21746 --- /dev/null +++ b/doc-options-md.nix @@ -0,0 +1,52 @@ +{ outputAttrPath, optionsAttrPath, optionsInternal ? true, }: + +{ lib, options, pkgs, ... }: + +with lib; + +let + visibleOptionDocs = filter (opt: opt.visible && !opt.internal) (optionAttrSetToDocList options); + + toValue = value: + if value ? _type && value._type == "literalExpression" then value.text + else generators.toPretty { } value; + + toMarkdown = option: + '' + ## `${option.name}` + + ${option.description} + + ${optionalString (option ? default) '' + **Default value**: + + ```nix + ${toValue option.default} + ``` + ''} + + **Type**: ${option.type}${optionalString option.readOnly " (read only)"} + + ${optionalString (option ? example) '' + **Example**: + + ```nix + ${toValue option.example} + ``` + ''} + + Declared in: + + ${concatStringsSep "\n" (map (decl: "- ${decl}") option.declarations)} + + ''; + + # TODO: rewrite "Declared in" so that it points to GitHub repository + + options-md = concatStringsSep "\n" (map toMarkdown visibleOptionDocs); +in +{ + config = setAttrByPath outputAttrPath { + doc-options-md = pkgs.writeText "options.md" options-md; + }; +} -- cgit v1.2.3