Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/treewide: Fix incorrectly rendered examples #84074

Merged
merged 1 commit into from Apr 3, 2020

Conversation

infinisil
Copy link
Member

Motivation for this change

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 #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 is using escapeNixIdentifier from #82461)

Closes #25516

Ping @davidak @ehmry

Things done
  • Verified that evaluating above expression now yields 0 results
  • Checked that the docs still build successfully

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 NixOS#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 NixOS#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.
@infinisil infinisil merged commit eb0148e into NixOS:master Apr 3, 2020
@infinisil infinisil deleted the fix-literal-option-examples branch April 3, 2020 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rebuild fails with whitespace in attribute
2 participants