Home Explore Blog CI



nixpkgs

2nd chunk of `nixos/doc/manual/development/option-types.section.md`
f38d14367e71991c1d7d77668b2b646d72213872292234840000000100000fe1
      str = "bar";
      pkg.gcc = pkgs.gcc;
      pkg.hello = pkgs.hello;
      fun.fun = x: x + 2;
    }
    ```
    :::

`types.raw`

:   A type which doesn't do any checking, merging or nested evaluation. It
    accepts a single arbitrary value that is not recursed into, making it
    useful for values coming from outside the module system, such as package
    sets or arbitrary data. Options of this type are still evaluated according
    to priorities and conditionals, so `mkForce`, `mkIf` and co. still work on
    the option value itself, but not for any value nested within it. This type
    should only be used when checking, merging and nested evaluation are not
    desirable.

`types.optionType`

:   The type of an option's type. Its merging operation ensures that nested
    options have the correct file location annotated, and that if possible,
    multiple option definitions are correctly merged together. The main use
    case is as the type of the `_module.freeformType` option.

`types.attrs`

:   A free-form attribute set.

    ::: {.warning}
    This type will be deprecated in the future because it doesn't
    recurse into attribute sets, silently drops earlier attribute
    definitions, and doesn't discharge `lib.mkDefault`, `lib.mkIf`
    and co. For allowing arbitrary attribute sets, prefer
    `types.attrsOf types.anything` instead which doesn't have these
    problems.
    :::

`types.pkgs`

:   A type for the top level Nixpkgs package set.

### Numeric types {#sec-option-types-numeric}

`types.int`

:   A signed integer.

`types.ints.{s8, s16, s32}`

:   Signed integers with a fixed length (8, 16 or 32 bits). They go from
    −2^n/2 to
    2^n/2−1 respectively (e.g. `−128` to
    `127` for 8 bits).

`types.ints.unsigned`

:   An unsigned integer (that is >= 0).

`types.ints.{u8, u16, u32}`

:   Unsigned integers with a fixed length (8, 16 or 32 bits). They go
    from 0 to 2^n−1 respectively (e.g. `0`
    to `255` for 8 bits).

`types.ints.between` *`lowest highest`*

:   An integer between *`lowest`* and *`highest`* (both inclusive).

`types.ints.positive`

:   A positive integer (that is > 0).

`types.port`

:   A port number. This type is an alias to
    `types.ints.u16`.

`types.float`

:   A floating point number.

    ::: {.warning}
    Converting a floating point number to a string with `toString` or `toJSON`
    may result in [precision loss](https://github.com/NixOS/nix/issues/5733).
    :::

`types.number`

:   Either a signed integer or a floating point number. No implicit conversion
    is done between the two types, and multiple equal definitions will only be
    merged if they have the same type.

`types.numbers.between` *`lowest highest`*

:   An integer or floating point number between *`lowest`* and *`highest`* (both inclusive).

`types.numbers.nonnegative`

:   A nonnegative integer or floating point number (that is >= 0).

`types.numbers.positive`

:   A positive integer or floating point number (that is > 0).

### String types {#sec-option-types-string}

`types.str`

:   A string. Multiple definitions cannot be merged.

`types.separatedString` *`sep`*

:   A string. Multiple definitions are concatenated with *`sep`*, e.g.
    `types.separatedString "|"`.

`types.lines`

:   A string. Multiple definitions are concatenated with a new line
    `"\n"`.

`types.commas`

:   A string. Multiple definitions are concatenated with a comma `","`.

`types.envVar`

:   A string. Multiple definitions are concatenated with a colon `":"`.

`types.strMatching`

:   A string matching a specific regular expression. Multiple
    definitions cannot be merged. The regular expression is processed
    using `builtins.match`.

### Specialised types {#sec-option-types-specialised}

`types.luaInline`

:   A string wrapped using `lib.mkLuaInline`. Allows embedding lua expressions
    inline within generated lua. Multiple definitions cannot be merged.

## Submodule types {#sec-option-types-submodule}

Submodules are detailed in [Submodule](#section-option-types-submodule).

Title: Option Types: More Basic Types, Numeric Types, String Types, and Specialised Types
Summary
This section continues the description of option types, covering `types.attrs`, `types.pkgs`, numeric types (`types.int`, `types.ints`, `types.port`, `types.float`, `types.number`), string types (`types.str`, `types.separatedString`, `types.lines`, `types.commas`, `types.envVar`, `types.strMatching`), and specialized types (`types.luaInline`). It explains their behaviors, constraints, and how multiple definitions are handled, including warnings about potential issues like precision loss with floating-point numbers and the deprecation of `types.attrs`.