doc/option-types: Add attrTag example

This commit is contained in:
Robert Hensing 2024-01-29 09:14:18 +01:00
parent 475a55b2f0
commit c0f54d3dea
1 changed files with 24 additions and 0 deletions

View File

@ -318,6 +318,30 @@ If the built-in Nix value types provide enough distinction, you simplify your sy
the attribute set (`attr1`, etc) and whose value must be of the accompanying
type.
This type appears in the documentation as _attribute-tagged union_.
Example:
```nix
types.attrTag {
bounce = mkOption {
description = "Send back a packet explaining why it wasn't forwarded.";
type = submodule {
options.errorMessage = mkOption { … };
};
};
forward = mkOption {
description = "Forward the packet.";
type = submodule {
options.destination = mkOption { … };
};
};
ignore = mkOption {
description = "Drop the packet without sending anything back.";
type = submodule {};
};
}
```
## Composed types {#sec-option-types-composed}