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

doc: improve lib.options reference documentation #316862

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

hsjobeki
Copy link
Contributor

@hsjobeki hsjobeki commented Jun 3, 2024

Description of changes

  • Migrate documentation of lib.options to rfc145
  • Init documentation for many undocumented option functions

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@github-actions github-actions bot added 6.topic: module system About "NixOS" module system internals 6.topic: lib The Nixpkgs function library labels Jun 3, 2024
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild 10.rebuild-linux: 1-10 labels Jun 3, 2024
Copy link
Member

@roberth roberth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the first part. Ok overall, but noticed some quirks.

lib/options.nix Outdated Show resolved Hide resolved
lib/options.nix Outdated
Type: isOption :: a -> bool
# Inputs

`value`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value is not part of the interface and isn't referenced anywhere in this documentation.

lib/options.nix Outdated Show resolved Hide resolved
lib/options.nix Outdated Show resolved Hide resolved
lib/options.nix Outdated Show resolved Hide resolved
lib/options.nix Outdated Show resolved Hide resolved
lib/options.nix Outdated Show resolved Hide resolved
lib/options.nix Outdated Show resolved Hide resolved
lib/options.nix Outdated
Comment on lines 368 to 378
# Inputs

`loc`
: location of the option in the configuration as a list of strings.

e.g. ["boot" "loader "grub" "enable"]

`defs`
: list of definition values and locations.

e.g. [ { file = "/foo.nix"; value = 1; } { file = "/bar.nix"; value = 2 } ]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should simply refer to mkOptionType. That's where all the merge functions are passed to, so it's the best place to describe the type of those functions.
Implementations don't have to repeat that, because they aren't actually called by users.

Copy link
Contributor Author

@hsjobeki hsjobeki Jun 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd not move the documentation that is for this function into another place can we view it as a low level documentation? Maybe some Disclaimer:

This function is used as the default merge behavior in mkOptionType you should usually not need to use it yourself.

Currently most people see the following and i've not touched anything there.

# lib/types.nix
  /**
  
  */
  mkOptionType =
    {
    ...
    , # Merge a list of definitions together into a single value.
      # This function is called with two arguments: the location of
      # the option in the configuration as a list of strings
      # (e.g. ["boot" "loader "grub" "enable"]), and a list of
      # definition values and locations (e.g. [ { file = "/foo.nix";
      # value = 1; } { file = "/bar.nix"; value = 2 } ]).
      merge ? mergeDefaultOption

Since mergeDefaultOption is the default merge function we should describe its behavior here.
And we should describe the interface at the mkOptionType level. (Also place a link pointing here that explains the default merge behavior)

I'll also refactor the /lib/types.nix at a later point, so this comes together nicely.

Maybe I should add a concrete usage example:

    myType = mkOptionType {
      name = "myType";
      merge = mergeDefaultOption;
    };

Copy link
Contributor Author

@hsjobeki hsjobeki Jun 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just took a look into the nixpkgs manual. It seems we don't explain the concept of option types. At all.... (there)

lib/options.nix Outdated
@@ -254,18 +401,49 @@ rec {
else if all isInt list && all (x: x == head list) list then head list
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: resume review here.

@hsjobeki
Copy link
Contributor Author

hsjobeki commented Jun 3, 2024

@roberth big thanks for the review so far. The overall scope of this PR was to migrate the format to commonmark/markdown documentation.
But it somewhow evolved into cleaning up the entire documentation as i started to fix minor things 😀

Copy link
Member

@infinisil infinisil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a small review, but note that this is a bit of a duplicate with https://nixos.org/manual/nixos/stable/#sec-option-declarations

We should really move those docs to the Nixpkgs manual, they don't belong into the NixOS one.

lib/options.nix Outdated Show resolved Hide resolved
lib/options.nix Outdated Show resolved Hide resolved
lib/options.nix Outdated Show resolved Hide resolved
lib/options.nix Show resolved Hide resolved
lib/options.nix Outdated Show resolved Hide resolved
@hsjobeki
Copy link
Contributor Author

hsjobeki commented Jun 27, 2024

We should really move those docs to the Nixpkgs manual, they don't belong into the NixOS one.

I could do a follow up PR, that moves them from the nixos manual into the nixpkgs manual and revise them with what we have here.

@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Jul 4, 2024
lib/options.nix Outdated Show resolved Hide resolved
lib/options.nix Outdated Show resolved Hide resolved
Thanks @infinisil

Co-authored-by: Silvan Mosberger <[email protected]>
@hsjobeki
Copy link
Contributor Author

hsjobeki commented Oct 28, 2024

@roberth @infinisil I've split and rebased the PR.

Everything you didn't came to review will be in a follow up PR. Feel free to merge this one if all issues are adressed.

@Aleksanaa Aleksanaa removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: lib The Nixpkgs function library 6.topic: module system About "NixOS" module system internals 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild 10.rebuild-linux: 1-10
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants