Commit Graph

333 Commits

Author SHA1 Message Date
Robert Hensing
a01aeeb9b1 lib/modules: Add false positive info to check coherence assertion
Unfortunately, we don't have a good enough way to discern this
possibility. Technically we could add yet another attribute, but
that does not seem to be worth the cost at this point, in terms
of complexity and possibly even performance.

I take the blame for this one. I identified the need for the second
merge commit in review but didn't require it in the first merge.
These changes really should have been done in a single merge.
That would have prevented this situation.
2025-11-09 19:30:17 +01:00
Robert Hensing
586961172a lib/modules: Report error for unsupported t // { check = ...; } (#454964) 2025-10-28 16:40:39 +00:00
Aliaksandr
dc7095a86e treewide: remove deprecated lib functions that had warning for more than 2 years 2025-10-24 06:30:16 +03:00
Robert Hensing
93ea59f66d lib/modules: Report error for unsupported // { check }
`check` can have a new place since the introduction of
merge.v2. This makes the // { check = ... } idiom unreliable.

In this PR we add checks to detect and report this.

merge.v2 introduced in:
https://github.com/NixOS/nixpkgs/pull/391544

Real world case:
https://hercules-ci.com/github/hercules-ci/hercules-ci-effects/jobs/875
2025-10-23 19:06:05 +02:00
Aliaksandr
def801fb09 lib: deprecate mkAliasOptionModuleMD 2025-10-21 16:00:52 +03:00
Johannes Kirschbauer
bb9da33c62 lib/*: fix docs to use "returns" instead of "return" (#442388) 2025-10-06 08:09:54 +00:00
Johannes Kirschbauer
1c960d4bcf lib/modules: rename defs''' into human friendly names 2025-09-24 09:22:29 +02:00
Felix Buehler
06ac3fbebd lib/*: fix docs to use "returns" instead of "return" 2025-09-12 16:16:41 +02:00
Johannes Kirschbauer
bb0bd3d413 lib/modules: add _internal to valueMeta of checkedAndMerged 2025-08-20 21:55:19 +02:00
Johannes Kirschbauer
4f802d935c lib/modules: fix typo 2025-08-18 08:01:24 +02:00
Johannes Kirschbauer
50bef19448 lib/modules: add nested 'headError.message'
This should make headError extensible other information needs to be passed
This seems to improve performance slightly
2025-08-13 15:09:20 +02:00
Johannes Kirschbauer
ebafc3eb74 lib/modules: optimize performance by inlining bindings 2025-08-13 15:09:20 +02:00
Johannes Kirschbauer
70ab11c2f2 lib/modules: add new merge.v2 for 'types.{either,coercedTo}' 2025-08-13 15:09:20 +02:00
Robert Hensing
644527dd57 lib.modules: init types checkAndMerge to allow adding 'valueMeta' attributes
This allows individual types to add attributes that would be discarded during normal evaluation.
Some examples:

types.submodule performs a submodule evluation which yields an 'evalModules' result.
It returns '.config' but makes the original result accessible via 'valueMeta' allowing introspection of '.options' and all other kinds of module evaluation results

types.attrsOf returns an attribute set of the nestedType.
It makes each valueMeta available under the corresponding attribute name.
2025-08-13 15:09:20 +02:00
Shahar "Dawn" Or
5186921ded lib.evalModules: add graph attribute
Co-authored-by: Ali Jamadi <jamadi1377@gmail.com>
2025-08-07 11:38:16 +07:00
Ali Jamadi
2c1ec14d12 lib/modules: extract isDisabled from filterModules
Co-authored-by: Shahar "Dawn" Or <mightyiampresence@gmail.com>
2025-08-07 11:27:10 +07:00
Robert Hensing
5620fc678e lib.modules: Improve infinite recursion hint
hsjobeki: Using config in imports is possible in general. But its not possible to do conditional imports where the condition depends on config. Thats two different statements.

Co-authored-by: Johannes Kirschbauer <hsjobeki+github@gmail.com>
2025-08-04 10:05:26 +02:00
Robert Hensing
c34e08489e lib.modules: Adjust error message
- Lower case error trace for consistency
- Be more explicit about the condition under which the hint applies,
  and the resolution.
2025-08-02 11:17:26 +02:00
Robert Hensing
3d15b12d8f lib.modules: Make _module.args evaluation explicit in trace 2025-08-02 11:17:26 +02:00
Robert Hensing
9dad048f21 lib.modules: Generalize the import hint to _module.args 2025-08-02 10:51:09 +02:00
49016
7a787e122b lib.modules: Add hint when using config in imports 2025-08-01 22:09:02 +02:00
Wolfgang Walther
5a0711127c treewide: run nixfmt 1.0.0 2025-07-24 13:55:40 +02:00
Johannes Kirschbauer
1849ee507e modules: Add _prefix module argument, improve error, add docs (#398839) 2025-06-19 16:09:07 +02:00
Matt Sturgeon
1fb1446380 lib.modules.importApply: Fix doc typo; _keykey
The `importApply` docs reference using the `_key` attr along with
`importApply` or `_file`, however the actual attr name used by the
module system is `key`.
2025-05-08 17:48:50 +01:00
Robert Hensing
38bb05d169 lib.modules: Add prefix to imports type check error 2025-04-15 13:42:29 +02:00
Robert Hensing
ce0c6e269d lib.modules: Typos 2025-04-15 12:42:47 +02:00
Robert Hensing
4752577dd6 lib.modules: Add _prefix module argument 2025-04-15 12:42:47 +02:00
Michael Hoang
6de9039315 lib/modules: add class to specialArgs
Co-Authored-By: Johannes Kirschbauer <hsjobeki@gmail.com>
2025-04-10 17:58:40 +02:00
Johannes Kirschbauer
33daa3f4b9 lib.modules: init test for lib.mkDefinition 2025-04-03 15:03:00 +02:00
Robert Hensing
b42b9e061b lib.modules: init lib.mkDefinition
Free-floating definitions including file location.
2025-04-03 14:12:07 +02:00
Silvan Mosberger
374e6bcc40 treewide: Format all Nix files
Format all Nix files using the officially approved formatter,
making the CI check introduced in the previous commit succeed:

  nix-build ci -A fmt.check

This is the next step of the of the [implementation](https://github.com/NixOS/nixfmt/issues/153)
of the accepted [RFC 166](https://github.com/NixOS/rfcs/pull/166).

This commit will lead to merge conflicts for a number of PRs,
up to an estimated ~1100 (~33%) among the PRs with activity in the past 2
months, but that should be lower than what it would be without the previous
[partial treewide format](https://github.com/NixOS/nixpkgs/pull/322537).

Merge conflicts caused by this commit can now automatically be resolved while rebasing using the
[auto-rebase script](8616af08d9/maintainers/scripts/auto-rebase).

If you run into any problems regarding any of this, please reach out to the
[formatting team](https://nixos.org/community/teams/formatting/) by
pinging @NixOS/nix-formatting.
2025-04-01 20:10:43 +02:00
toborwinner
ff9b3598e6 lib.modules: simplified logic in zipAttrsWith and minor cleanup 2025-03-10 17:05:22 +01:00
Johannes Kirschbauer
88f912da48 Docs: migrate format of comments to doc-comments 2025-02-12 15:01:43 +07:00
Johannes Kirschbauer
5c35166b71 lib/modules: improve mismatching class error mesage 2025-01-29 11:49:20 +01:00
K900
7c251e2b5f Revert "pkgs/top-level: make package sets composable" 2025-01-26 09:43:44 +03:00
Wolfgang Walther
eec21001b0 nixos/nixpkgs: pass original system args instead of elaborated
Passing the elaborated system defeats what pkgs/top-level/default.nix
tries to do: Pass only the original args and let defaults be inferred.

The underlying problem is that lib.systems.elaborate can not deal with
arbitrary overrides, but will often return an inconsistent system
description when partially overriding some values. This becomes most
prominent if trying to override an already elaborated system.
2025-01-25 18:55:03 +01:00
Johannes Kirschbauer
e51cc8a2a6 lib.collectModules: improve readability by replacing implication 2024-12-31 22:47:20 +01:00
Silvan Mosberger
dbb085549e lib/modules: Minor performance optimisation
Co-Authored-By: Johannes Kirschbauer <hsjobeki@gmail.com>
2024-12-03 10:03:02 +01:00
Silvan Mosberger
e438d6b08d lib/types: Add deprecation to attrsWith
Co-Authored-By: @infinisil
2024-12-03 10:02:55 +01:00
K900
907cb3d253 Revert "lib/types: init {types.attrsWith}" 2024-12-03 09:06:24 +03:00
Silvan Mosberger
14f4431d12 lib/modules: Minor performance optimisation
Co-Authored-By: Johannes Kirschbauer <hsjobeki@gmail.com>
2024-12-02 15:54:52 +01:00
Silvan Mosberger
45f0035a83 lib/types: Add deprecation to attrsWith
Co-Authored-By: @infinisil
2024-11-26 10:27:01 +01:00
Robert Hensing
729225e355 treewide: lib.isInOldestRelease -> lib.oldestSupportedReleaseIsAtLeast 2024-10-08 11:14:24 +02:00
Robert Hensing
65eea03839 lib/modules: Improve error when loading a flake as a module 2024-09-26 18:31:39 +02:00
Robert Hensing
92f4ef78de lib/modules: improve error message when option is being accessed that isn't defined (#338362) 2024-09-02 10:08:49 +02:00
Sandro Jäckel
ab8bf8c35b lib/modules: improve error message when option is being accessed that isn't defined 2024-09-01 23:29:21 +02:00
Robert Hensing
0abfc619bc lib.importApply: init (#230588)
* lib.modules.importApply: init

Brings variables from rich scopes to modules defined in separate files.

A helper for functions in files that return a module.

* lib.modules.importApply: Edit doc

Generally improve the quality. Notes:

- Not rendered to the manual yet, so probably the syntax could be
  improved, but I have no way to test this now.

- The docs use `arg` vs `staticArg` in the code. This is intentional,
  because the doc is pretty clear about the role of `arg` whereas
  the code exists in a context where ambiguities are more harmful.

* Format
2024-08-31 01:12:43 +02:00
Robert Hensing
4eb6883b86 lib/modules: Memoize remaining lookups into builtins
Similar to the previous commit about lookups into lib
Main benefits
- consistent
- faster
- shorter
2024-07-03 11:16:31 +02:00
Robert Hensing
d0438fb00f lib/modules: Memoize remaining lookups into lib
Benefits:
 - some lookups happened in the hot path, and will now be slightly faster,
   with only a variable lookup and no attribute selection
 - it's now harder to accidentally use args.lib aka specialArgs.lib, which
   has happened
 - shorter
2024-07-03 11:16:31 +02:00
Robert Hensing
88a9a933c4 lib/modules: Memoize functionArgs lookup
This would also make specialArgs-lib.nix pass.
2024-07-03 11:16:31 +02:00