query
On this page

mkOption

lib.options.mkOption

Docs pulled from | This Revision | 35 minutes ago


Creates an Option declaration for use with the module system.

Inputs

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, whether the option and/or sub-options show up in the manual. Use false to hide the option and any sub-options from submodules. Use "shallow" to hide only sub-options. Use "transparent" to hide this option, but not its sub-options. Default: true.
readOnly
Optional boolean indicating whether the option can be set only once.

Examples

lib.options.mkOption usage example

mkOption { }
# => Empty option; type = types.anything

mkOption { default = "foo"; }
# => Same as above, with a default value

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"; };