Commit graph

323 commits

Author SHA1 Message Date
Matt Sturgeon
c00644f728
Module system types.attrTag implement declaration info in options (#531031) 2026-07-02 12:38:20 +00:00
Eman Resu
44eafb2953 lib.types: remove throwIf usage
throwIf sends our error message through a function call, even if the
error condition doesn't trigger. This requires a lot of thunk allocation
that can be easily avoided.
2026-06-30 21:38:25 -04:00
Eman Resu
ce99cfa103 lib.types: remove assertMsg usage
assertMsg sends our error message through a function call, even if the
error condition doesn't trigger. This requires a lot of thunk allocation
that can be easily avoided.
2026-06-30 21:38:25 -04:00
d18g
495906d50a lib.types: types.attrTag declaration info
Closes #303082
2026-06-18 15:23:42 +03:00
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
f1b62fdc4e
types.attrListWith: add asAttrs
This allows the type's return value to be accessed more easily.

Motivating use case:
- Built-in module provides CLI functionality by declaring
  an `attrListWith { asAttrs = true; }`, extracting the ordered list
  from `valueMeta` for the purpose of creating the `argv`.
- User modules can read the command line's flags directly without
  having to parse the list of attrs.
2026-05-24 15:07:05 +02:00
Robert Hensing
17fdb6f68a
types.attrListWith: init
Trivial extraction from attrListOf.
2026-05-24 15:07:05 +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
toonn
1aa1947487
lib.types: Fix biggest/smallest supported int comment 2026-05-13 18:44:05 +02:00
Eman Resu
db9c713393 lib.types: move variable to its usage, don't check condition twice
The only place `merged` is used already checks if `coercedType.merge ?
v2`, so we don't need to check it again. We can also avoid creating the
variable if coercedTypes.merge doesn't have a v2 attribute.
2026-05-12 11:23:18 -04:00
Eman Resu
9b693534b4 lib.types: inline tail binding 2026-05-12 11:23:16 -04:00
Eman Resu
51a39dc768 lib.types: use head foo instead of elemAt foo 0 2026-05-12 11:23:14 -04:00
Eman Resu
89effed623 lib.types: reuse args in v2 merge functions 2026-05-12 11:23:05 -04:00
Eman Resu
1f94af932c lib.types: add variables to global scope 2026-05-12 11:23:04 -04:00
Eman Resu
5616d07fe0 lib/types: filter for nulls instead of counting them 2026-05-12 11:22:36 -04:00
Eman Resu
ea872088f3 lib/types: only filter if we're actually getting an error 2026-05-12 11:22:33 -04:00
Eman Resu
cc86a8faa0 lib.types: inherit builtins into scope 2026-05-12 11:22:25 -04:00
Eman Resu
6c84f96a96 lib.types: inherit builtins to global scope 2026-05-12 11:22:24 -04: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
cinereal
7334dd9096
lib.types: add types.option
Signed-off-by: cinereal <cinereal@riseup.net>
2026-04-02 12:10:29 +02: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
fe13778496
lib.types: use isType for optionType
Signed-off-by: cinereal <cinereal@riseup.net>
2026-03-14 16:18:56 -07:00
Dyego Aurélio
28096cc5e3 treewide: apply nixfmt 1.2.0 2026-01-22 18:37:56 -03:00
Johannes Kirschbauer
c988f82f7a
lib/types: add types.{json,toml} from pkgs.formats 2026-01-20 21:26:05 +01:00
Johannes Kirschbauer
38cab2baa2
lib/types: unify public attribute set and ast 2026-01-19 13:24:05 +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
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
bb56489b2f
lib/types: small typo fix 2025-10-22 00:20:17 +03:00
Johannes Kirschbauer
bb9da33c62
lib/*: fix docs to use "returns" instead of "return" (#442388) 2025-10-06 08:09:54 +00:00
NAHO
6177c4ad72
lib: remove optional builtins prefixes from prelude functions
Remove optional builtins prefixes from prelude functions by running:

    builtins=(
      abort
      baseNameOf
      break
      derivation
      derivationStrict
      dirOf
      false
      fetchGit
      fetchMercurial
      fetchTarball
      fetchTree
      fromTOML
      import
      isNull
      map
      null
      placeholder
      removeAttrs
      scopedImport
      throw
      toString
      true
    )

    fd --type file . lib --exec-batch sed --in-place --regexp-extended "
      s/\<builtins\.($(
        printf '%s\n' "${builtins[@]}" |
          paste --delimiter '|' --serial -
      ))\>/\1/g
    "

    nix fmt
2025-09-30 09:02:59 +02:00
Johannes Kirschbauer
2b2df96038
lib/types: submodule fix description with freeformType (#443134) 2025-09-25 14:57:10 +00:00
Johannes Kirschbauer
717bb9db24
lib/types: submodule fix description with freeformType 2025-09-16 16:27:32 +02:00
Felix Buehler
06ac3fbebd lib/*: fix docs to use "returns" instead of "return" 2025-09-12 16:16:41 +02:00
Johannes Kirschbauer
8a5c4598d8
lib/types: either allow unchecked values again
This fixes a slight regression of the either type
Where it allowed access to any value when used in freeformType
2025-09-06 11:49:31 +02:00
Niols
9c00c9af71
lib.types: add a fileset type 2025-08-29 13:07:55 +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
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
5d72133a22
lib/addCheck: add support for new merge 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
Johannes Kirschbauer
648dbed1d6
lib/types: add 'checkDefsForError' utility for checking defs with a given check 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