Home Explore Blog CI



nixpkgs

3rd chunk of `nixos/doc/manual/development/option-declarations.section.md`
e7f5705c8f140de409ca7ab397f22f16c0ba093756fc1e22000000010000081d
  type = lib.types.package;
  default = pkgs.ghc;
  defaultText = lib.literalExpression "pkgs.ghc";
  example = lib.literalExpression "pkgs.haskell.packages.ghc92.ghc.withPackages (hkgs: [ hkgs.primes ])";
  description = "The GHC package to use.";
}
```
:::

::: {#ex-options-declarations-util-mkPackageOption-extraDescription .example}
### `mkPackageOption` with additional description text
```nix
mkPackageOption pkgs [ "python312Packages" "torch" ] {
  extraDescription = "This is an example and doesn't actually do anything.";
}
# is like
lib.mkOption {
  type = lib.types.package;
  default = pkgs.python312Packages.torch;
  defaultText = lib.literalExpression "pkgs.python312Packages.torch";
  description = "The pytorch package to use. This is an example and doesn't actually do anything.";
}
```
:::

## Extensible Option Types {#sec-option-declarations-eot}

Extensible option types is a feature that allows to extend certain types
declaration through multiple module files. This feature only work with a
restricted set of types, namely `enum` and `submodules` and any composed
forms of them.

Extensible option types can be used for `enum` options that affects
multiple modules, or as an alternative to related `enable` options.

As an example, we will take the case of display managers. There is a
central display manager module for generic display manager options and a
module file per display manager backend (sddm, gdm ...).

There are two approaches we could take with this module structure:

-   Configuring the display managers independently by adding an enable
    option to every display manager module backend. (NixOS)

-   Configuring the display managers in the central module by adding
    an option to select which display manager backend to use.

Both approaches have problems.

Making backends independent can quickly become hard to manage. For
display managers, there can only be one enabled at a time, but the
type system cannot enforce this restriction as there is no relation
between each backend's `enable` option. As a result, this restriction

Title: Extensible Option Types Explained with Display Manager Example
Summary
This section introduces extensible option types, a feature that allows extending type declarations across multiple module files, specifically for `enum` and `submodules` types. It presents a detailed example using display managers to illustrate the benefits of this approach over independent backend configurations, highlighting the issue of enforcing mutual exclusivity when multiple backends cannot be enabled simultaneously.