191 Commits

Author SHA1 Message Date
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 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
Michael Daniels 18e82c4591 lib: remove unused let bindings and args@{} uses 2026-04-30 18:43:56 -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
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
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
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
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
Wolfgang Walther 91a8fee3aa treewide: remove redundant parentheses
Auto-fixed by nixf-diagnose.
2025-10-05 10:52:03 +02: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
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 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
Wolfgang Walther 5a0711127c treewide: run nixfmt 1.0.0 2025-07-24 13:55:40 +02:00
sodiboo b3c9916455 lib.types.attrTag: expose suboptions at correct level 2025-06-22 21:23:18 +02:00
Johannes Kirschbauer 1849ee507e modules: Add _prefix module argument, improve error, add docs (#398839) 2025-06-19 16:09:07 +02:00
Johannes Kirschbauer 843af863e6 lib.options.mkPackageOption: use lib.showAttrPath (#398066) 2025-04-21 10:51:01 +02:00
Johannes Kirschbauer 013beed1db lib/types: check paths in pathWith with hasStorePathPrefix (#387304) 2025-04-21 10:45:23 +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
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
Mikael Voss 931f464581 lib/types: check paths in pathWith with hasStorePathPrefix
This permits usage of content‐addressed derivations and has the added
benefit of checking normalised paths.
2025-04-02 13:28:52 +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](https://github.com/NixOS/nixpkgs/tree/8616af08d915377bd930395f3b700a0e93d08728/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
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