diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2023-03-27 15:46:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-27 15:46:18 +0200 |
commit | 237587bc0af9259414d50ed18f137c2214d7abb1 (patch) | |
tree | 98110281567c0e5fb8623065e8172b8559feafb4 /doc/manual/utils.nix | |
parent | 1d539aa28711b4214867ebd8db85de1000bbbe59 (diff) | |
parent | 168b6021c558f317fc01b142c1610742e9b9096b (diff) |
Merge pull request #8084 from edolstra/store-docs
Auto-generate store documentation
Diffstat (limited to 'doc/manual/utils.nix')
-rw-r--r-- | doc/manual/utils.nix | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/doc/manual/utils.nix b/doc/manual/utils.nix index d0643ef46..5eacce0dd 100644 --- a/doc/manual/utils.nix +++ b/doc/manual/utils.nix @@ -38,4 +38,46 @@ rec { filterAttrs = pred: set: listToAttrs (concatMap (name: let v = set.${name}; in if pred name v then [(nameValuePair name v)] else []) (attrNames set)); + + showSetting = { useAnchors }: name: { description, documentDefault, defaultValue, aliases, value }: + let + result = squash '' + - ${if useAnchors + then ''<span id="conf-${name}">[`${name}`](#conf-${name})</span>'' + else ''`${name}`''} + + ${indent " " body} + ''; + + # separate body to cleanly handle indentation + body = '' + ${description} + + **Default:** ${showDefault documentDefault defaultValue} + + ${showAliases aliases} + ''; + + showDefault = documentDefault: defaultValue: + if documentDefault then + # a StringMap value type is specified as a string, but + # this shows the value type. The empty stringmap is `null` in + # JSON, but that converts to `{ }` here. + if defaultValue == "" || defaultValue == [] || isAttrs defaultValue + then "*empty*" + else if isBool defaultValue then + if defaultValue then "`true`" else "`false`" + else "`${toString defaultValue}`" + else "*machine-specific*"; + + showAliases = aliases: + if aliases == [] then "" else + "**Deprecated alias:** ${(concatStringsSep ", " (map (s: "`${s}`") aliases))}"; + + indent = prefix: s: + concatStringsSep "\n" (map (x: if x == "" then x else "${prefix}${x}") (splitLines s)); + + in result; + + showSettings = args: settingsInfo: concatStrings (attrValues (mapAttrs (showSetting args) settingsInfo)); } |