query
On this page

mkOption

lib.options.mkOption

Docs pulled from | This Revision | about 1 hour ago


Creates an Option attribute set. mkOption accepts an attribute set with the following keys:

Inputs

Structured attribute set
Attribute set containing none or some of the following attributes.
default
Optional default value used when no definition is given in the configuration.
defaultText
Substitute for documenting the default, if evaluating the default value during documentation rendering is not possible.
Can be any nix value that evaluates.
Usage with lib.literalMD or lib.literalExpression is supported
example
Optional example value used in the manual.
Can be any nix value that evaluates.
Usage with lib.literalMD or lib.literalExpression is supported
description
Optional string describing the option. This is required if option documentation is generated.
relatedPackages
Optional related packages used in the manual (see genRelatedPackages in ../nixos/lib/make-options-doc/default.nix).
type
Optional option type, providing type-checking and value merging.
apply
Optional function that converts the option value to something else.
internal
Optional boolean indicating whether the option is for NixOS developers only.
visible
Optional boolean indicating whether the option shows up in the manual. Default: true. Use false to hide the option and any sub-options from submodules. Use "shallow" to hide only sub-options.
readOnly
Optional boolean indicating whether the option can be set only once.
... (any other attribute)
Any other attribute is passed through to the resulting option attribute set.

Examples

lib.options.mkOption usage example

mkOption { }  // => { _type = "option"; }
mkOption { default = "foo"; } // => { _type = "option"; default = "foo"; }

Noogle detected

Aliases

Implementation

The following is the current implementation of this function.

mkOption =
    {
      default ? null,
      defaultText ? null,
      example ? null,
      description ? null,
      relatedPackages ? null,
      type ? null,
      apply ? null,
      internal ? null,
      visible ? null,
      readOnly ? null,
    }@attrs:
    attrs // { _type = "option"; };