Commit Graph

213 Commits

Author SHA1 Message Date
Johannes Kirschbauer
0cb9aa055c lib/types: remove functor.wrapped after deprecation phase of 2 full releases 2026-06-10 21:24:53 +02:00
Johannes Kirschbauer
ae142b5738 types.attrListWith: review fixes
- Improve extractItem error messages: distinguish non-attrset elements
  from multi-key attrsets, and include the faulty definition via showDefs.
- Use isType instead of raw _type access for order detection.
- Disable type merging (typeMerge = t: null) instead of providing a
  functor-based merge. Add test confirming duplicate declarations fail.
2026-05-24 15:32:04 +02:00
Robert Hensing
8aa6e3dbb9 types.attrListWith: add valueMeta.definitions 2026-05-24 15:32:04 +02:00
Robert Hensing
43d998e6c0 types.attrListOf: init
This adds a type for name-value mappings that preserve ordering.

Motivating use case: command line flags for package modules /
wrappers / modular services.
The option value can be transformed into a command line in the
correct order.
Additionally, a convenience readOnly option could be provided
to give easy introspection access to the values in an ad hoc
manner.
2026-05-24 15:07:02 +02:00
Robert Hensing
77b5864637 lib.modules: submodule emptyValue must evaluate sub-option defaults
`emptyValue` for `types.submodule` was `{ value = { }; }`, i.e. none
of the type-declared options or their defaults.

Previously submodules without defs would simply fail for lack of a default,
but since PR #500104 repurposed `emptyValue` as the fallback when no
definitions exist, submodule options without an explicit `default = { }`
(new additions) silently lost their sub-option defaults
(e.g. `requiredFeatures.devnet` in the nixos-test-driver, #511413).

Main change: `emptyValue`: `{ }` -> `{ value = base.config; }`

Additionally, skip `emptyValue`-based default rendering in docs for
types with submodules, because their sub-options are already documented
individually, and forcing evaluation here can break on modules with
invalid or incomplete definitions.
2026-04-19 20:52:33 +01:00
Johannes Kirschbauer
dbe18bc16d lib.types.defaultTypeMerge: Fix for functors with no wrapped attr (#476219) 2026-04-14 07:15:44 +00:00
Robert Hensing
8d4e372952 lib.types: add types.option (#499945) 2026-04-08 13:41:10 +00:00
Robert Hensing
17c056fa24 lib.types.optionDeclaration: test error 2026-04-03 10:53:47 +02:00
cinereal
7334dd9096 lib.types: add types.option
Signed-off-by: cinereal <cinereal@riseup.net>
2026-04-02 12:10:29 +02:00
Robert Hensing
ff011b00be lib/modules: Improve errors involving pushDownProperties (#502117) 2026-04-01 16:00:01 +00:00
Timothy Gallion
f32c37b88c lib.types.defaultTypeMerge: Fix for functors with no wrapped attr
Downstream types that want to use `lib.types.defaultTypeMerge` must include
`wrapped` even though it is deprecated or the internal
`wrappedDeprecationMessage`. This is caused by accessing the
`wrapped` attr in `lib.types.defaultTypeMerge`. The logic should first check
if the attr exists and then if it does check if it is null.
2026-03-29 15:14:00 -04:00
cinereal
ac0ef82504 lib.modules: default to emptyValue
Signed-off-by: cinereal <cinereal@riseup.net>
2026-03-23 16:04:32 +01:00
dramforever
d48a370de1 lib/modules: Add error message test for pushing down non-attrsets 2026-03-22 14:11:01 +08:00
Silvan Mosberger
58b187378d lib/modules: add suggestions to invalid option name errors (#442263) 2026-02-03 19:10:35 +00:00
Johannes Kirschbauer
f4d45cdced lib/types: add tests for types.mkStructuredType 2026-01-20 21:26:05 +01:00
Johannes Kirschbauer
53b47eb93d lib/tests: add strict option to checkConfigOutput 2026-01-20 21:26:05 +01:00
Tom Hubrecht
ba6b3a4f6c lib/tests: Use --option to enable abort-on-warn 2025-12-08 08:44:53 +01:00
cinereal
cf4da9fd69 lib/types: make attrTag's description field list valid choices
Lists the valid choices in `attrTag` type's `description` field.
Given this description is used in error messages, this serves to make
for somewhat more descriptive errors in the event an option involving
this type turns out not to match.

Signed-off-by: cinereal <cinereal@riseup.net>
2025-11-24 18:45:48 +01:00
Felix Buehler
3106949fd7 lib/types: add externalPath 2025-11-04 22:57:16 +01:00
Robert Hensing
49f0cbd7f8 lib.types: introduce a fileset type (#428293) 2025-11-04 13:44:33 +00:00
Robert Hensing
143ca6688b lib/modules: Fix suggestions in submodules 2025-10-28 15:22:17 +01:00
Robert Hensing
cdefdba743 lib/modules: Support multiple suggestions, optimize 2025-10-28 15:17:08 +01: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
Johannes Kirschbauer
2b2df96038 lib/types: submodule fix description with freeformType (#443134) 2025-09-25 14:57:10 +00:00
Robert Hensing
35cb0d92d8 lib/tests/modules: Test description composition 2025-09-17 14:00:10 +02:00
Winter
0f54833b4a lib/modules: add suggestions to invalid option name errors
This change introduces the suggesting of possible valid option names for
a given invalid option, based on the keys of said invalid option's
parent attrset. That is, `foo.bar.baz` will only be suggested keys from
`foo.bar`, while `(config).baz` will only be suggested keys from the
toplevel.
2025-09-11 23:12:45 -04:00
Johannes Kirschbauer
b3cf9ce0f9 lib/types.either: add tests for warning in legacy case 2025-09-06 12:29:16 +02:00
Niols
ad1e615f48 lib.types: add module tests for fileset 2025-08-29 13:07:55 +02:00
Johannes Kirschbauer
45ed757e10 types/addCheck: add tests for merge v1 and v2 2025-08-13 15:09:21 +02:00
Johannes Kirschbauer
cd2e5bd46c types/merge: move 'configuration' of submodules into nested attribute set 2025-08-13 15:09:21 +02:00
Johannes Kirschbauer
1765370051 lib/modules: test revert unentional regression in check 2025-08-13 15:09:20 +02:00
Johannes Kirschbauer
9f787b30e5 lib/modules: fix test by matching error message more generically 2025-08-13 15:09:20 +02:00
Johannes Kirschbauer
8fa33000a3 lib.modules: add tests for option valueMeta 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
Robert Hensing
9dad048f21 lib.modules: Generalize the import hint to _module.args 2025-08-02 10:51:09 +02:00
Robert Hensing
e28f3f0cd0 lib.modules: Test infinite recursion hint
We don't want it to occur in the trace of any unrelated errors.
2025-08-02 10:40:00 +02:00
Johannes Kirschbauer
1849ee507e modules: Add _prefix module argument, improve error, add docs (#398839) 2025-06-19 16:09:07 +02:00
Robert Hensing
38bb05d169 lib.modules: Add prefix to imports type check error 2025-04-15 13:42:29 +02:00
Robert Hensing
4752577dd6 lib.modules: Add _prefix module argument 2025-04-15 12:42:47 +02:00
Matt Sturgeon
6107d48bcb lib.options.mkPackageOption: use lib.showAttrPath
Make use of `lib.showAttrPath` instead of manually doing `concatStringsSep "."`.

This means edge-cases such as the attr-path including names that are not
valid nix identifiers will be handled better.

See:
- https://nix.dev/manual/nix/2.26/language/identifiers
- https://nixos.org/manual/nixpkgs/unstable/#function-library-lib.attrsets.showAttrPath
2025-04-13 20:54:13 +01:00
Matt Sturgeon
4c26f96059 lib/tests/modules: test all mkPackageOption cases
There were several test case options declared in `declare-mkPackageOption.nix`
that were not actually tested in `modules.sh`.
2025-04-13 20:54:12 +01: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
Johannes Kirschbauer
484a0477d8 lib/types: types.either deprecate functor.wrapped in favor of functor.payload.elemType 2025-03-20 14:11:34 +00:00
Johannes Kirschbauer
4f123107b4 lib/types: types.coercedTo deprecate functor.wrapped in favor of functor.payload.elemType 2025-03-15 00:46:02 +09:00
Johannes Kirschbauer
f6214eb786 lib/types: types.functionTo deprecate functor.wrapped in favor of functor.payload.elemType 2025-03-15 00:45:39 +09:00
Johannes Kirschbauer
4fe25460e1 lib/types: types.nullOr deprecate functor.wrapped in favor of functor.payload.elemType 2025-03-15 00:45:30 +09:00
Johannes Kirschbauer
05958f27e2 lib/types: types.{unique,uniq} deprecate functor.wrapped in favor of functor.payload.elemType 2025-03-15 00:05:55 +09:00
Johannes Kirschbauer
fb79705bca lib.types: improve tests for deprecation warning on all migrated types 2025-02-19 16:54:55 +07:00
Silvan Mosberger
bdddb0c517 Revert "lib.types.attrsWith: remove failing test"
This reverts commit ce8f304bb6.

The problem was simply a typo (nestedTypes.elemType ->
type.nestedTypes.elemType) ! And CI didn't run for lib in the orginal
PR which is why it didn't get caught.
2025-02-17 16:19:40 +01:00