Home Explore Blog Models CI



nixpkgs

3rd chunk of `nixos/doc/manual/development/option-declarations.section.md`
c9ae4d3325a392fd0f7e53738bb5940080343cd1af4ac9e3000000010000081a
    default = pkgs.ghc;
    defaultText = lib.literalExpression "pkgs.ghc";
    example = lib.literalExpression "pkgs.haskellPackages.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: `mkPackageOption` Examples and Introduction to Extensible Option Types
Summary
This chunk concludes the examples for `mkPackageOption`, demonstrating its use with an explicit default package path and how to add extra descriptive text. It then introduces 'Extensible Option Types,' a feature allowing `enum` and `submodules` type declarations to be extended across multiple module files. The text explains that this feature is useful for `enum` options that affect multiple modules or as an alternative to `enable` options, illustrating its purpose with the example of managing display managers. It highlights the difficulty of enforcing mutually exclusive choices (like a single display manager) when using independent `enable` options across modules.