diff options
author | Robert Hensing <roberth@users.noreply.github.com> | 2021-10-04 20:37:42 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-04 20:37:42 +0200 |
commit | 0699530f08290f34c532beedd66046825d9756fa (patch) | |
tree | 39cdee36907d66f698eebe8a377b3e1a4984eeee /lib | |
parent | 63df91f789fd973ece46ad9547f6a72ea7dfb231 (diff) | |
parent | 2ddc335e6f32b875e14ad9610101325b306a0add (diff) |
Merge pull request #136909 from ncfavier/cleanup-defaults-examples
nixos/doc: clean up defaults and examples
Diffstat (limited to 'lib')
-rw-r--r-- | lib/default.nix | 4 | ||||
-rw-r--r-- | lib/options.nix | 24 |
2 files changed, 21 insertions, 7 deletions
diff --git a/lib/default.nix b/lib/default.nix index cabc1549c07b..5a85c5421172 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -123,8 +123,8 @@ let inherit (self.options) isOption mkEnableOption mkSinkUndeclaredOptions mergeDefaultOption mergeOneOption mergeEqualOption getValues getFiles optionAttrSetToDocList optionAttrSetToDocList' - scrubOptionValue literalExample showOption showFiles - unknownModule mkOption; + scrubOptionValue literalExpression literalExample literalDocBook + showOption showFiles unknownModule mkOption; inherit (self.types) isType setType defaultTypeMerge defaultFunctor isOptionType mkOptionType; inherit (self.asserts) diff --git a/lib/options.nix b/lib/options.nix index 119a67fb7d82..b3164181312e 100644 --- a/lib/options.nix +++ b/lib/options.nix @@ -54,7 +54,7 @@ rec { Example: mkOption { } // => { _type = "option"; } - mkOption { defaultText = "foo"; } // => { _type = "option"; defaultText = "foo"; } + mkOption { default = "foo"; } // => { _type = "option"; default = "foo"; } */ mkOption = { @@ -212,11 +212,25 @@ rec { else x; - /* For use in the `example` option attribute. It causes the given - text to be included verbatim in documentation. This is necessary - for example values that are not simple values, e.g., functions. + /* For use in the `defaultText` and `example` option attributes. Causes the + given string to be rendered verbatim in the documentation as Nix code. This + is necessary for complex values, e.g. functions, or values that depend on + other values or packages. */ - literalExample = text: { _type = "literalExample"; inherit text; }; + literalExpression = text: + if ! isString text then throw "literalExpression expects a string." + else { _type = "literalExpression"; inherit text; }; + + literalExample = lib.warn "literalExample is deprecated, use literalExpression instead, or use literalDocBook for a non-Nix description." literalExpression; + + + /* For use in the `defaultText` and `example` option attributes. Causes the + given DocBook text to be inserted verbatim in the documentation, for when + a `literalExpression` would be too hard to read. + */ + literalDocBook = text: + if ! isString text then throw "literalDocBook expects a string." + else { _type = "literalDocBook"; inherit text; }; # Helper functions. |