aboutsummaryrefslogtreecommitdiff
path: root/doc/manual/utils.nix
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2023-03-21 12:58:14 +0100
committerEelco Dolstra <edolstra@gmail.com>2023-03-21 14:03:40 +0100
commit8d6d59cb1ba0a2cfe12f9f444a27833dc531c191 (patch)
treeeb164db30d593d53b7caff644e4c3f522fc5c400 /doc/manual/utils.nix
parentcdfa59daa17d647308d8ac48a6b3e1a7328c3640 (diff)
nix store --help: Include store type documentation
Diffstat (limited to 'doc/manual/utils.nix')
-rw-r--r--doc/manual/utils.nix37
1 files changed, 37 insertions, 0 deletions
diff --git a/doc/manual/utils.nix b/doc/manual/utils.nix
index d0643ef46..ce0c21c98 100644
--- a/doc/manual/utils.nix
+++ b/doc/manual/utils.nix
@@ -38,4 +38,41 @@ rec {
filterAttrs = pred: set:
listToAttrs (concatMap (name: let v = set.${name}; in if pred name v then [(nameValuePair name v)] else []) (attrNames set));
+
+ showSetting = useSpans: name: { description, documentDefault, defaultValue, aliases, ... }:
+ let
+ result = squash ''
+ - ${if useSpans
+ then ''<span id="conf-${name}">[`${name}`](#conf-${name})</span>''
+ else ''[`${name}`](#conf-${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 = useSpans: settingsInfo: concatStrings (attrValues (mapAttrs (showSetting useSpans) settingsInfo));
}