Skip to content

Commit

Permalink
doc: minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hsjobeki committed Oct 28, 2024
1 parent 645a3c6 commit 8a8fe93
Showing 1 changed file with 62 additions and 6 deletions.
68 changes: 62 additions & 6 deletions lib/options.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ in
rec {

/**
Returns true when the given argument is an option
Returns true when the given argument `a` is an option
# Inputs
`value`
`a`
: Any value to check whether it is an option
# Examples
Expand Down Expand Up @@ -375,20 +375,35 @@ rec {

/**
A merge function that merges multiple definitions of an option into a single value
by checking that they are all equal.
Merge functions are typically used for constructing option types.
:::{.caution}
This function is used as the default merge operation in `lib.types.mkOptionType`. In most cases, explicit usage of this function is unnecessary.
:::
# Inputs
`loc`
: location of the option in the configuration as a list of strings.
e.g. ["boot" "loader "grub" "enable"]
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 } ]
e.g. `[ { file = "/foo.nix"; value = 1; } { file = "/bar.nix"; value = 2 } ]`
# Example
:::{.example}
## `lib.options.mergeDefaultOption` usage example
```nix
myType = mkOptionType {
name = "myType";
merge = mergeDefaultOption; # <- This line is redundant. It is the default aready.
};
```
:::
# Merge behavior
Expand Down Expand Up @@ -623,6 +638,47 @@ rec {
in "\n- In `${def.file}'${result}"
) defs;

/**
Pretty prints all option definition locations
# Inputs
`option`
: The option to pretty print
# Examples
:::{.example}
## `lib.options.showOptionWithDefLocs` usage example
```nix
showOptionWithDefLocs { loc = ["x" "y" ]; files = [ "foo.nix" "bar.nix" ]; }
"x.y, with values defined in:\n - foo.nix\n - bar.nix\n"
```
```nix
nix-repl> eval = lib.evalModules {
modules = [
{
options = {
foo = lib.mkEnableOption "foo";
};
}
];
}
nix-repl> lib.options.showOptionWithDefLocs eval.options.foo
"foo, with values defined in:\n - <unknown-file>\n"
```
:::
# Type
```
showDefsSep :: { files :: [ String ]; loc :: [ String ]; ... } -> string
```
*/
showOptionWithDefLocs = opt: ''
${showOption opt.loc}, with values defined in:
${concatMapStringsSep "\n" (defFile: " - ${defFile}") opt.files}
Expand Down

0 comments on commit 8a8fe93

Please sign in to comment.