From fa8b46adf467eec196da8808d62c9e03d69caa37 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Sun, 4 Feb 2024 17:17:47 +0100 Subject: [PATCH] doc/option-types: Make attrTag example self-contained ... well, except for the ellipses, which hide unnecessary descriptions, which you should write! --- .../development/option-types.section.md | 46 +++++++++++++------ 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/nixos/doc/manual/development/option-types.section.md b/nixos/doc/manual/development/option-types.section.md index 6bf579ff7802..0b348094bfcf 100644 --- a/nixos/doc/manual/development/option-types.section.md +++ b/nixos/doc/manual/development/option-types.section.md @@ -323,22 +323,40 @@ If the built-in Nix value types provide enough distinction, you simplify your sy Example: ```nix - types.attrTag { - bounce = mkOption { - description = "Send back a packet explaining why it wasn't forwarded."; - type = submodule { - options.errorMessage = mkOption { … }; - }; + { lib, ... }: + let inherit (lib) type mkOption; + in { + options.toyRouter.rules = mkOption { + description = '' + Rules for a fictional packet routing service. + ''; + type = types.attrsOf ( + types.attrTag { + bounce = mkOption { + description = "Send back a packet explaining why it wasn't forwarded."; + type = types.submodule { + options.errorMessage = mkOption { … }; + }; + }; + forward = mkOption { + description = "Forward the packet."; + type = types.submodule { + options.destination = mkOption { … }; + }; + }; + ignore = types.mkOption { + description = "Drop the packet without sending anything back."; + type = types.submodule {}; + }; + }); }; - forward = mkOption { - description = "Forward the packet."; - type = submodule { - options.destination = mkOption { … }; + config.toyRouter.rules = { + http = { + bounce = { + errorMessage = "Unencrypted HTTP is banned. You must always use https://."; + }; }; - }; - ignore = mkOption { - description = "Drop the packet without sending anything back."; - type = submodule {}; + ssh = { drop = {}; }; }; } ```