Commit graph

164 commits

Author SHA1 Message Date
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
Johannes Kirschbauer b3cf9ce0f9
lib/types.either: add tests for warning in legacy case 2025-09-06 12:29:16 +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](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
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
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
piegames 603733851b treewide: Fix incorrect string escapes 2025-01-07 19:49:28 +01:00
Silvan Mosberger 4f0dadbf38 treewide: format all inactive Nix files
After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build a08b3a4d19.tar.gz \
      --argstr baseRev b32a094368
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:26:33 +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
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 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
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 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
Silvan Mosberger 8f425c25ad lib/tests: Format a file with nixfmt
And fix locations to not break the test.
This is a rare case where another change is required after formatting.
We do this in a separate commit so that we don't need to do it in the
treewide reformatting PR.
2024-08-25 05:07:51 +02:00
Sigmanificient 6dd44107ac treewide: remove unused lib (and other) arguments 2024-07-26 11:18:09 +02:00
Robert Hensing 4a014ed92e lib/modules: Use fixed lib instead of args.lib
The practical use for this should be very limited because I don't
think anyone should change `lib`, let alone change `lib.functionArgs`,
but, but it would be even stranger to rely on `args.lib` (or really
`specialArgs.lib` for what's clearly a behavior of the current
`evalModules`, which uses its own ambient lib for basically everything.

The shadowing of `lib` by `args.lib` here seems to be a small mistake,
which is easy to make.
2024-07-03 11:16:31 +02:00
Silvan Mosberger 4f1d724b82
Merge pull request #284551 from hercules-ci/types-attrTag
Add `types.attrTag`
2024-04-09 20:48:44 +02:00
Johannes Kirschbauer c0f5f271d1
doc: migrate trivial files to doc-comment format (#299986)
* doc: migrate trivial files to doc-comment format

* fix: revert some comments

* Apply suggestions from code review

Thanks @danielSidhion

Co-authored-by: Daniel Sidhion <DanielSidhion@users.noreply.github.com>

* Update lib/types.nix

---------

Co-authored-by: Daniel Sidhion <DanielSidhion@users.noreply.github.com>
Co-authored-by: Silvan Mosberger <github@infinisil.com>
2024-04-04 16:36:07 +02:00
Robert Hensing 22d7f146a4 lib.types.attrTag: Fix declarationPositions after merge 2024-04-04 12:56:56 +02:00
Robert Hensing cf4968a904 lib/tests/modules/types-attrTag.nix: Test other option doc attrs 2024-04-04 12:22:08 +02:00