nixos/treewide: Fix incorrectly rendered examples

Many options define their example to be a Nix value without using
literalExample. This sometimes gets rendered incorrectly in the manual,
causing confusion like in https://github.com/NixOS/nixpkgs/issues/25516

This fixes it by using literalExample for such options. The list of
option to fix was determined with this expression:

  let
    nixos = import ./nixos { configuration = {}; };
    lib = import ./lib;
    valid = d: {
      # escapeNixIdentifier from https://github.com/NixOS/nixpkgs/pull/82461
      set = lib.all (n: lib.strings.escapeNixIdentifier n == n) (lib.attrNames d) && lib.all (v: valid v) (lib.attrValues d);
      list = lib.all (v: valid v) d;
    }.${builtins.typeOf d} or true;

    optionList = lib.optionAttrSetToDocList nixos.options;

  in map (opt: {
    file = lib.elemAt opt.declarations 0;
    loc = lib.options.showOption opt.loc;
  }) (lib.filter (opt: if opt ? example then ! valid opt.example else false) optionList)

which when evaluated will output all options that use a Nix identifier
that would need escaping as an attribute name.
This commit is contained in:
Silvan Mosberger
2020-04-02 07:49:25 +02:00
parent f75c11cfdf
commit 1d0fc9729d
13 changed files with 92 additions and 59 deletions
+7 -3
View File
@@ -43,7 +43,7 @@ let
timeout = mkOption {
type = types.int;
description = ''
Controls how long to wait for a Neighbor Advertisment Message before
Controls how long to wait for a Neighbor Advertisment Message before
invalidating the entry, in milliseconds.
'';
default = 500;
@@ -51,7 +51,7 @@ let
ttl = mkOption {
type = types.int;
description = ''
Controls how long a valid or invalid entry remains in the cache, in
Controls how long a valid or invalid entry remains in the cache, in
milliseconds.
'';
default = 30000;
@@ -142,7 +142,11 @@ in {
messages, and respond to them according to a set of rules.
'';
default = {};
example = { eth0.rules."1111::/64" = {}; };
example = literalExample ''
{
eth0.rules."1111::/64" = {};
}
'';
};
};