Commit Graph

263 Commits

Author SHA1 Message Date
Robert Hensing
c28dd7d921 lib/modules.nix: Rename defnsByName -> pushedDownDefinitionsByName 2023-07-11 12:22:58 +02:00
Robert Hensing
448b153f81 lib/modules.nix: Rename defnsByName' -> rawDefinitionsByName 2023-07-11 12:22:58 +02:00
Robert Hensing
fb988c6193 lib/modules.nix: Apply argument module of old f 2023-07-11 12:22:57 +02:00
Robert Hensing
eb410eab82 lib/modules.nix: Apply argument modules of old old old byName 2023-07-11 12:22:57 +02:00
Robert Hensing
65de18210d lib/modules.nix: Apply argument f of old old byName 2023-07-11 12:22:57 +02:00
Robert Hensing
c70a5e9223 lib/modules.nix: Apply argument attr of old byName 2023-07-11 12:22:08 +02:00
Robert Hensing
d1e18a369a lib/modules.nix: Inline byName
byName is not an abstraction. This is the first commit in a series
that refactors it away.
2023-07-11 11:37:56 +02:00
Robert Hensing
b1ad9cd27d
Merge pull request #238136 from hercules-ci/nixos-nixpkgs-dont-check-when-_module.args.pkgs-is-set
`nixos/nixpkgs`: Don't check when `_module.args.pkgs` is set
2023-06-23 19:17:36 +02:00
Robert Hensing
895ac17634
lib/modules.nix: Clean up mergeAttrDefinitionsWithPrio impl 2023-06-23 18:10:49 +02:00
figsoda
8a1a028694 lib/modules: remove unused let bindings 2023-06-23 09:41:04 +00:00
Robert Hensing
36ea2bbfe8 lib.modules: Add mergeAttrDefinitionsWithPrio
This will let us make assertions involving _module.args.pkgs, which
is not an option but a value attribute, and therefore doesn't have
its own highestPrio to inspect. The new function gives us that info.
2023-06-16 22:08:16 +02:00
pennae
b9756b4de1 lib: unhide _module.args
this was a temporary fix that should hopefully no longer be necessary.
2023-06-16 19:26:23 +02:00
pennae
d36f950d40 lib: turn *MD functions into aliases
with docbook gone and MD the default these aren't needed any more. we
can't remove them yet because there's thousands of uses, but maybe some
day we can.
2023-06-13 16:56:32 +02:00
Robert Hensing
eab660d91e lib.modules: configurationClass -> class
This simplifies the documentation. `configuration` is implied by `_type`.
2023-05-06 18:32:59 +02:00
Robert Hensing
89491bef8d lib.modules: in evalModules return move _module.class -> configurationClass 2023-05-06 18:32:59 +02:00
Robert Hensing
fd88c79418 lib.modules: Change class declaration in module to _class 2023-05-06 18:32:59 +02:00
Robert Hensing
8054785157 lib/modules: Move class out of specialArgs 2023-05-06 18:32:58 +02:00
Robert Hensing
73f584c3cc lib/modules.nix: Deduplicate documentation
`file://./..` looks redundant, but makes the url clickable in vscode.
2023-05-06 18:32:58 +02:00
Robert Hensing
84b1b01702 lib/modules: Only interpret class declaration in non-shorthand mode
This is to avoid stealing keys from submodules. `class` might be
common enough that reinterpreting existing `class` attributes in
configurations as a declaration leads to fairly widespread problems.
2023-05-06 18:29:04 +02:00
Robert Hensing
1f4a58ef03 lib/modules.nix: Refactor: extract applyModuleArgs 2023-05-06 18:29:04 +02:00
Robert Hensing
06ca78663c lib/modules.nix: Refactor: evaluate applyModuleArgsIfFunction in attrs case 2023-05-06 18:29:04 +02:00
Robert Hensing
439f6790bd lib/modules.nix: Restore old collectModules interface 2023-05-06 18:29:04 +02:00
Robert Hensing
9714487f74 lib/modules: Explain that a configuration can't be loaded as a module 2023-05-06 18:29:04 +02:00
Robert Hensing
2e689d58cb lib/modules: Improve error when a configuration is imported
This is appears to be a fairly common mistake for beginners who want
to build larger things from the system configurations, such as NixOps
networks, etc. Further explanation seems appropriate.
2023-05-06 18:29:03 +02:00
Robert Hensing
58f385f680 lib/modules: Check against importing things with a _type 2023-05-06 18:29:03 +02:00
Robert Hensing
b8ff2807a2 lib/modules: Add class concept to check imports
This improves the error message when an incompatible module is
imported.
2023-05-06 18:29:03 +02:00
Robert Hensing
3633bf98be lib/modules.nix: Make some functions private
The supposedly public nature of these functions has been holding
back module system maintenance, while usages of these functions
are expected to be rare. If used anywhere, presumably they're
emulating module system behavior because some use case isn't supported
properly. We should try to support such a use case directly, if it
even exists.
2023-05-06 18:29:03 +02:00
Robert Hensing
fe15279390 lib/modules.nix: Use explicit exports 2023-05-06 18:22:51 +02:00
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