Commit Graph

235 Commits

Author SHA1 Message Date
Naïm Favier
8751764236
lib/modules: better error for invalid option declarations
Make `byName` aware of whether it's processing options or config to give
slightly more accurate error messages.
2023-03-22 12:37:28 +01:00
Robert Hensing
118bdf25a6 lib/modules: Allow an "anonymous" module with key in disabledModules
This makes the following work

    disabledModules = [ foo.nixosModules.bar ];

even if `bar` is not a path, but rather a module such as

    { key = "/path/to/foo#nixosModules.bar"; config = ...; }

By supporting this, the user will often be able to use the same syntax
for both importing and disabling a module. This is becoming more relevant
because flakes promote the use of attributes to reference modules. Not
all of these modules in flake attributes will be identifiable, but with
the help of a framework such as flake-parts, these attributes can be
guaranteed to be identifiable (by outPath + attribute path).
2023-03-01 15:03:44 +01:00
Naïm Favier
fb1bc8de93
lib/modules: make mkAliasOptionModule emit DocBook
Follow-up to https://github.com/NixOS/nixpkgs/pull/208407

Removing `mdDoc` isn't enough, we need to emit actual DocBook.
2023-01-08 22:44:18 +01:00
pennae
e912c7bfe9 lib/modules: hide _module.args docs
unfortunately we can't unconditionally make this text markdown without
impacting downstream users of docs generation (as noted in #175586).
hide it entirely until the transition is complete.
2023-01-05 02:33:13 +01:00
pennae
4c1cfbdb84 modules: add mkAliasOptionModuleMD
mkAliasOptionModule should not default to mdDoc descriptions because
that can break out-of-tree users of documentation infrastructure. add an
explicitly-MD variant for now, to be removed some time after the MD
transition is complete.
2023-01-05 02:33:13 +01:00
figsoda
695d4bc76b lib: fix typos 2022-12-17 18:59:29 -05:00
Valentin Gagarin
260de5901e
Merge pull request #204103 from ncfavier/doc-mkOrder
nixos/doc: document `mkOrder` and friends
2022-12-02 17:19:40 +01:00
Naïm Favier
e8927c46b8
nixos/doc: document mkOrder and friends
Add a section on ordering option definitions.

Also mention `mkDefault` in the section on `mkOverride`.

Clarify the code a bit by renaming `defaultPriority` to
`defaultOverridePriority` and introducing `defaultOrderPriority`.
2022-12-02 14:15:24 +01:00
Robert Hensing
6110a6009f lib/modules: Add context to the "option does not exist" error
Add trace items that provide context for a failed definition that
can not be caught within the Nix language.

This also adds a test for the `tryEval` behavior of `showDefs`.
2022-12-02 11:06:53 +00:00
Shea Levy
ad10d4fdef lib.modules.doRename: Don't define warning, even as undefined, if not warning.
This fixes mkAliasOptionModule in systems with no warning option.
2022-11-03 13:12:58 +01:00
figsoda
a1d50eecab
Merge pull request #193132 from figsoda/clean-up
treewide: clean up
2022-10-01 17:03:11 -04:00
Robert Hensing
7f0d934f9a
Merge pull request #191540 from hercules-ci/nixosTest-modular
nixosTest: make modular
2022-09-28 10:27:45 +01:00
figsoda
05fc3747c9 lib/modules.nix: remove unused bindings 2022-09-26 22:18:55 -04:00
Robert Hensing
1ffa30b055 lib/modules: Fix meta duplication in shorthand syntax 2022-09-21 10:55:11 +01:00
Erik Arvstedt
9f22df9a7f
lib/modules: add definitionsWithLocations to evaluated options
This attr provides the location of each definition.

This is particularly useful for introspecting options of type
`attrsOf`. E.g., it allows finding the location of a systemd
service definition by parsing
`options.systemd.services.definitionsWithLocations`.
2022-09-05 12:11:43 +02:00
pennae
3bddcf5f90
Merge branch 'master' into option-docs-md 2022-09-01 16:10:09 +02:00
pennae
e04a09082e lib/modules: convert option description to MD 2022-08-31 17:27:37 +02:00
Erik Arvstedt
e2cc361970
lib.modules: support strings with absolute paths in disabledModules
This is particularly useful for disabling modules defined in a flake.
Example:
disabledModules = [ "${flake}/modules/mymodule.nix" ];

Previously, absolute string paths were internally prepended with `modulesPath`,
which caused the module filtering to fail.
2022-08-31 14:23:28 +02:00
Robert Hensing
bf5b75864d lib/modules: Add _module.specialArgs 2022-07-21 15:31:34 +02:00
Robert Hensing
3c4a49f506 lib/modules: Throw earlier when module function does not return attrs
`m` must always be an attrset at this point. It is basically always
evaluated. This will make it throw when any of the attrs is accessed,
rather than just `config`. We assume that this will improve the error
message in more scenarios.
2022-06-14 23:23:41 +02:00
Robert Hensing
19a069ab8b lib.types: Add deferredModuleWith 2022-06-14 23:01:27 +02:00
Robert Hensing
9dead5565a lib/types, lib/modules: Remove unused extensionOffset 2022-06-14 17:25:06 +02:00
Robert Hensing
d9e71531a0 lib/modules: Fix missing prefix in extendModules when unset in both eval- and extend- 2022-06-10 12:21:23 +02:00
Robert Hensing
c2451ed1a2
Merge pull request #167776 from hercules-ci/lib-modules-allow-disable-_modules.args-docs-internal
lib.modules: Allow making _module.args internal
2022-04-30 13:43:08 +02:00
Robert Hensing
224426ba6d lib.types.submoduleWith: Avoid _key collisions after extendModules 2022-04-24 00:07:59 +02:00
Robert Hensing
14aa201b65 lib.modules: Allow making _module.args internal
This allows other module system consumers to
disable these docs via option merging.

For instance arion uses asciidoc instead of
docbook so that would look awful.
2022-04-11 11:17:34 +02:00
Robert Hensing
c705953267
Merge pull request #165540 from Infinisil/module-args-docs
lib/modules: Document `_module.args`
2022-04-05 21:51:46 +02:00
Silvan Mosberger
25de2935ef lib/modules: Document _module.args
Documents the _module.args option, motivated by many usages in Flakes,
especially with the deprecation of extraArgs
(78ada83361)

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>
2022-04-05 18:26:40 +02:00
Silvan Mosberger
99d9d45630
Merge pull request #164651 from Infinisil/remove-optionSet
lib/modules: Finally remove deprecated types.optionSet
2022-03-25 17:41:57 +01:00
Robert Hensing
6c469679f6 Merge remote-tracking branch 'upstream/master' into tests-restrict-arguments 2022-03-21 23:17:17 +01:00
Robert Hensing
6a0b24b276 lib: applyIfFunction -> applyModuleArgsIfFunction 2022-03-21 23:14:10 +01:00
Kevin Cox
8ce16fcf62
Merge pull request #163451 from hercules-ci/stop-premature-warnings
Stop premature warnings, including `nix.settings` migration
2022-03-21 10:10:40 -04:00
Robert Hensing
1eb627c4cf lib.mkRenamedOptionModuleWith: Remove warnWhenRead
Let's keep things simple and not poke holes in the
improved migration process.
2022-03-21 14:41:22 +01:00
Silvan Mosberger
96698efe0c lib/modules: Finally remove deprecated types.optionSet
types.optionSet has been deprecated for almost 10 years now
(0e333688ce)! A removal
was already attempted in 2019
(27982b408e), but it was promptly
reinstantiated since some third-party uses were discovered
(f531ce75e4178c6867cc1d0f7fec96b2d5c3f1cb).

It's finally time to remove it for good :)
2022-03-18 04:51:27 +01:00
Silvan Mosberger
b97742c66c
Merge pull request #156533 from hercules-ci/issue-146882-transparent-submodule-options
lib.modules: Let module declare options directly in bare submodule
2022-03-16 21:44:35 +01:00
Robert Hensing
7377ea57ff lib: Add mkRenamedOptionModuleWith
Adds support for sinceRelease
2022-03-09 14:50:51 +01:00
Robert Hensing
c4b38702e5 lib/modules.nix: Add comment about internal shorthand null value 2022-03-07 11:23:24 +01:00
Robert Hensing
e162ed8a14 lib/modules.nix: Move comment to the actual legacy code 2022-03-07 11:21:19 +01:00
Robert Hensing
02de37ca07 lib/modules.nix: Optimize optionSet legacy compat code
It's still in the hot path.
2022-03-07 11:07:50 +01:00
Robert Hensing
db08290453 Revert "lib.modules: Remove redundant fixupOptionType in option injection"
This reverts commit 6b077c47ff.

Thanks Infinisil for discovering this problem:

> After a lot of trial and error, trying to prove why fixupOptionType should
> be used here or not, I figured it out: It's needed for the sake of file
> locations in error messages.
2022-03-07 10:59:03 +01:00
Robert Hensing
6b077c47ff lib.modules: Remove redundant fixupOptionType in option injection 2022-03-03 00:29:14 +01:00
Robert Hensing
8baea8b82c lib.modules: Make option injection work when shorthandOnlyDefinesConfig 2022-03-03 00:29:14 +01:00
Robert Hensing
11537c9c02 lib.modules: Improve option-is-prefix error message 2022-03-03 00:29:11 +01:00
Robert Hensing
81f342d1f3 lib.modules: Explain why options can only be merged into submodules 2022-03-03 00:28:35 +01:00
Robert Hensing
0c09eb343d lib.modules: Refactor option scanning slightly
This scans the options with fewer function calls, improving performance.

It also removes a let Env from the happy flow of the new logic.
2022-03-03 00:28:35 +01:00
Robert Hensing
58a8a48e9d lib.types.submodule: Remove redundant isSubmodule attr 2022-03-03 00:28:35 +01:00
Robert Hensing
d030e2109f lib.modules: Let module declare options directly in bare submodule
... where a bare submodule is an option that has a type like
`submoduleWith x`, as opposed to `attrsOf (submoduleWith x)`.

This makes migration unnecessary when introducing a freeform type
in an existing option tree.

Closes #146882
2022-03-03 00:28:35 +01:00
Silvan Mosberger
023fa7b923 lib.modules: Use types.optionType for _module.freeformType
This ensures that the module file locations are propagated to the
freeform type, which makes it so that submodules in freeform types now
have their declaration location shown in the manual, fixing
https://github.com/NixOS/nixpkgs/issues/132085.

In addition, this also newly allows freeformTypes to be declared
multiple times and all declarations being merged together according to
normal option merging.

This also removes some awkwardness regarding the type of `freeformType`
2022-03-01 19:31:02 +01:00
Silvan Mosberger
ff13cd5d3e lib/modules: Use types.raw for _module.args
Fixes https://github.com/NixOS/nixpkgs/issues/53458, as types.raw
doesn't allow setting multiple values
2022-02-22 15:54:45 +01:00
Naïm Favier
5a07097772
lib/modules: introduce setDefaultModuleLocation
Wraps a module with a default location for reporting errors.
2022-01-27 22:12:53 +01:00