-
-
Notifications
You must be signed in to change notification settings - Fork 14.1k
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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
Type: isOption :: a -> bool | ||
# Inputs | ||
|
||
`value` |
There was a problem hiding this comment.
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
# 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 } ] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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;
};
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
@roberth big thanks for the review so far. The overall scope of this PR was to migrate the format to commonmark/markdown documentation. |
There was a problem hiding this 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.
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. |
Co-authored-by: Robert Hensing <[email protected]>
9c954a8
to
4f2d2c9
Compare
Thanks @infinisil Co-authored-by: Silvan Mosberger <[email protected]>
4f2d2c9
to
2b22275
Compare
@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. |
Description of changes
Things done
nix.conf
? (See Nix manual)sandbox = relaxed
sandbox = true
nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)Add a 👍 reaction to pull requests you find important.