lib/modules: Document _module.args#165540
Conversation
_module.args
pennae
left a comment
There was a problem hiding this comment.
nice! would clarify how args works for submodules a little bit though and mention the name argument since it's really useful but apparently not documented anywhere either.
lib/modules.nix
Outdated
There was a problem hiding this comment.
These are NixOS-specific and don't belong in the generated documentation of other configuration systems.
They are better documented as freeform options.
| <literal>pkgs</literal>, <literal>modulesPath</literal> for |
There was a problem hiding this comment.
These arguments are not evaluated by the module system.
What does this mean?
Technically the module system doesn't evaluate anything, as it is a library or embedded dsl.
Maybe "they aren't processed by the module system", but that's still vague. Probably best to remove this sentence.
There was a problem hiding this comment.
These are NixOS-specific and don't belong in the generated documentation of other configuration systems. They are better documented as freeform options.
I should reword this sentence (there's a for nixpkgs afterwards, but it's very ambiguous). I think it's valid to mention pkgs and modulesPath in this documentation because there's no other place where these are documented currently, and NixOS modules are by far the most common use case. With a freeform type we should be able to make this documentation NixOS-specific in the future though.
There was a problem hiding this comment.
I just dropped the for nixpkgs. This sentence specifically says "ones like ...", which indicates that it's just an example of some arguments the reader might be familiar with. I think this should be fine
lib/modules.nix
Outdated
There was a problem hiding this comment.
This is actually an antipattern. It works for "split configuration" but is a bad idea for reusable modules.
It's better than lib.extend by virtue of being slightly more composable, but still vulnerable to name collisions.
The most robust method of using "libraries" is to import them directly into the lexical scope: let myLib = import ./myLlib; in ...... The root values in file imports are cached, so there's no loss of performance. Function invocations are not, so we need an alternative place to memoize those and internal options fit that purpose, without the risk of name collisions or organic accumulation of "utils" junk libraries.
There was a problem hiding this comment.
Do you have suggestions for better examples? Or should we drop examples completely?
There was a problem hiding this comment.
I honestly don't know of a good example. The ones in nixpkgs itself aren't actually good either. They're highly specific and/or workarounds.
unstable is the best example I know of, only slightly better than myLib. I'd call it pkgsUnstable though.
I think we need to clarify what are the "acceptable" use cases:
- end user configurations that are not intended to be included into anything that isn't defined "locally". Here convenience wins over reusability, but it does mean turning configs into modules will be harder.
- specific features of configuration systems, maybe?
- for example NixOS defines
noUserModulesto solve quite a NixOS-specific problem (maybe I should have used an internalspecialisationsoption instead? I guess that namespace was taken by anattrsOf. Is that sufficient reason? - is
baseModulesany better?
- for example NixOS defines
I'm really trying to like it, but not succeeding.
There was a problem hiding this comment.
I removed the example altogether for now. We can still add one later if we have a good one.
ecdf336 to
2f218ed
Compare
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/tweag-nix-dev-update-27/18433/1 |
Documents the _module.args option, motivated by many usages in Flakes, especially with the deprecation of extraArgs (NixOS@78ada83) The documentation rendering for this option had to be handled a bit specially, since it's not declared in nixos/modules like all the other NixOS options. Co-Authored-By: pennae <github@quasiparticle.net> Co-Authored-By: Robert Hensing <robert@roberthensing.nl>
2f218ed to
25de293
Compare
|
@roberth Good to merge? |
roberth
left a comment
There was a problem hiding this comment.
One final thing it seems.
Otherwise lgtm.
| </listitem> | ||
| <listitem> | ||
| <para> | ||
| <varname>config</varname>: The results of all options after merging the values from all modules together. |
There was a problem hiding this comment.
Subtle but important.
| <varname>config</varname>: The results of all options after merging the values from all modules together. | |
| <varname>config</varname>: The results of all options after merging the values from all modules together. In the context of a submodule, "all modules" does not include the parent module that contains the submodule. | |
| </para> | |
| <para> | |
| The module arguments of the parent can be accessed through the lexical scope instead. |
There was a problem hiding this comment.
It seems that something is missing from my terminology here. I can't find a word for what's like a level of modules, corresponding to an evalModules invocation, whether through lib or types.submodule. "Modules" is too vague "configuration" is a little more accurate but deemphasizes the options. "Configuration fixpoint" will send our readers studying for a day ;). Not sure what to do.
There was a problem hiding this comment.
"modules are merged according to the longest common option path prefix"? that covers both configurations (prefix 𝜀) and submodules (nested or not)
There was a problem hiding this comment.
While that is true, it does not indicate where config starts or equivalently: what is the result of "all options" and which options are "all".
There was a problem hiding this comment.
I don't think this clarification is needed because it's fairly obvious, submodules have a completely separate option set. This would fit better into the full NixOS documentation, this here should only be a very short explanation, only in relation to _module.args.
| </listitem> | ||
| <listitem> | ||
| <para> | ||
| <varname>options</varname>: The options declared in all modules. |
There was a problem hiding this comment.
| <varname>options</varname>: The options declared in all modules. | |
| <varname>options</varname>: The options declared in all modules, where "all modules" is defined the same as in <varname>config</varname>. |
|
Making this opt-out in #167776 so arion doesn't have to deal with docbook in its asciidoc. |
Description of changes
Documents the
_module.argsoption, motivated by many usages in Flakes, especially with the deprecation of extraArgsClick for screenshot of the documentation
Ping @roberth
Things done
nix-build nixos/release.nix -A manualHTML.x86_64-linuxand checked the resultingresult/share/doc/nixos/options.html