Commit Graph

191 Commits

Author SHA1 Message Date
Robert Hensing
49f0cbd7f8 lib.types: introduce a fileset type (#428293) 2025-11-04 13:44:33 +00: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
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
Jeremy Fleischman
6d7f6a92cc lib/types: add types.pathWith
This gives people some flexibility when they need a path type, and
prevents a "combinatorial explosion" of various path stops.

I've re-implemented our existing `path` and `pathInStore` types using
`pathWith`. Our existing `package` type is potentially a candidate for
similar treatment, but it's a little quirkier (there's some stuff with
`builtins.hasContext` and `toDerivation` that I don't completely
understand), and I didn't want to muddy this PR with that.

As a happy side effect of this work, we get a new feature: the ability
to create a type for paths *not* in the store. This is useful for when a
module needs a path to a file, and wants to protect people from
accidentally leaking that file into the nix store.
2025-02-15 16:14:06 +07:00
Johannes Kirschbauer
b3884c8b7d lib/modules: tests change expected error for class mismatch 2025-01-29 11:50:16 +01:00
Silvan Mosberger
33fe023937 lib/types: make pattern of strMatching accessible (#350467) 2024-12-09 17:53:38 +01:00
Silvan Mosberger
3fe041e8bf lib.types: Add test for merging strMatching 2024-12-09 17:40:32 +01:00
Johannes Kirschbauer
d504a1e680 lib.types.attrsWith: add placeholder parameter 2024-12-09 15:25:18 +01:00
Johannes Kirschbauer
ce8f304bb6 lib.types.attrsWith: remove failing test 2024-12-03 10:04:27 +01:00
Silvan Mosberger
e60e2e6916 lib/types: standardise attrsOf functor.wrapped warning and add a test 2024-12-03 10:03:13 +01:00
Silvan Mosberger
bd353d322c lib/types: Test attrsWith type merging
Co-Authored-By: @hsjobeki
2024-12-03 10:02:47 +01:00
Johannes Kirschbauer
5b7a21358d lib/types: init {types.attrsWith} 2024-12-03 10:02:40 +01:00
K900
907cb3d253 Revert "lib/types: init {types.attrsWith}" 2024-12-03 09:06:24 +03:00
Silvan Mosberger
d5eccbbbae lib/types: standardise attrsOf functor.wrapped warning and add a test 2024-12-02 16:18:03 +01:00
Silvan Mosberger
415d1932ea lib/types: Test attrsWith type merging
Co-Authored-By: @hsjobeki
2024-11-25 16:06:55 +01:00
Johannes Kirschbauer
c4a9529071 lib/types: init {types.attrsWith} 2024-11-25 15:11:45 +01:00
Johannes Kirschbauer
b978799f71 lib.types.defaultTypeMerge: refactor functor.{payload,wrapped} merging 2024-11-19 08:58:38 +01:00
Felix Stupp
f35a61d8a6 lib.modules: fix test line using empty "$@"
Probably a missed left over from somewhere in
the commit 58f385f680.
As can be seen in that commit where this line was introduced,
"$@" was also just emptied by the last `set` call in line 169.
This line is currently valid, but breaks suddenly when somewhere earlier
a `set --` instruction is used in the future.
Neither in commit 58f385f680
nor in PR https://github.com/NixOS/nixpkgs/pull/197547
have I found anything stating that this "defect" was intentional.
2024-10-05 14:14:01 +00: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
d572d95502 lib.types.anything: remove custom logic for lists (#340202) 2024-09-18 17:08:15 +02:00
HexoKnight
cf5a46368b lib/types: fix toCoerced's typeMerge 2024-09-10 22:45:27 +01:00
Alexis Destrez
e5e69b748f lib.types.anything: remove custom logic for lists (default to 'mergeEqualOption')
Previously, for values of type list, the merge function would only retain the value
if the number of option definitions was less than or equal to 1, and would throw an
error for conflicting definitions to avoid potentially unwanted list merges.

This change removes that logic, defaulting to the 'mergeEqualOption' function for
values of type list. This approach maintains the same safeguard against merging
different lists while allowing lists with identical values to be merged.
2024-09-07 01:15:32 +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