680 Commits
Author SHA1 Message Date
Tom Hubrecht ba6b3a4f6c lib/tests: Use --option to enable abort-on-warn 2025-12-08 08:44:53 +01:00
Robert Hensing 649a766e35 lib/tests: move throwTestFailures tests to standalone script
The throwTestFailures tests in misc.nix produce confusing trace output
that looks like test failures even when tests pass.

This commit moves these tests to a new lib/tests/debug.sh script,
following the pattern from modules.sh, sources.sh, and filesystem.sh.

The confusing trace output does not appear in any logs anymore.

Example of the confusing log:

trace: FAIL "testDerivation":
Expected:
<derivation a>

Result:
<derivation b>

evaluation warning: Using `lib.generators.toPlist` without `escape = true` is deprecated
[ ]
2025-11-26 23:51:59 +01:00
Robert HensingandGitHub 75c025c613 lib/types: make attrTag's description field list valid choices (#464627) 2025-11-25 18:28:32 +00:00
Johannes KirschbauerandGitHub 3ae8192162 lib: deprecate fold (#456532) 2025-11-25 14:15:41 +00: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
Yueh-Shun Li 21021adbe9 lib.makeOverrdable: preserve constructor override and metadata attributes 2025-11-13 18:01:44 +08:00
Rebecca Turner dc4cf16993 lib.debug.throwTestFailures: init
`lib.debug.runTests` provides a unit test evaluator for Nix, but its
results are returned in a raw and difficult-to-read form.

Currently, different callers output the results in various ways:
`builtins.throw (builtins.toJSON failures)` and `builtins.throw ("Tests
failed: " + lib.generators.toPretty { } failures)` are both used.

This change adds a new `lib.debug.throwTestFailures` function which
displays the results nicely before throwing an exception (or returns
`null` if no failures are given), unifying these disparate call-sites.

First, each failing test is pretty-printed in a `trace` message:

```
trace: FAIL testDerivation:
  Expected: <derivation a>
    Result: <derivation b>
```

Then, an exception is thrown containing the number of tests that failed
(and their names), followed by the raw JSON of the results (for parity
with previous usage, and because `lib.generators.toPretty` sometimes
omits information that `builins.toJSON` includes):

```
error:
       … while evaluating the file '...':

       … caused by explicit throw
         at /nix/store/.../lib/debug.nix:528:7:
          527|       in
          528|       throw (
             |       ^
          529|         builtins.seq traceFailures (

       error: 1 tests failed:
       - testDerivation

       [{"expected":"/nix/store/xh7kyqp69mxkwspmi81a94m9xx74r8dr-a","name":"testDerivation","result":"/nix/store/503l84nir4zw57d1shfhai25bxxn16c6-b"}]
```
2025-11-10 10:41:31 -08:00
Felix Buehler 3106949fd7 lib/types: add externalPath 2025-11-04 22:57:16 +01:00
Robert HensingandGitHub 49f0cbd7f8 lib.types: introduce a fileset type (#428293) 2025-11-04 13:44:33 +00:00
Robert HensingandGitHub acb6191c6e lib: Add splicing utilities (#426889) 2025-10-30 21:22:54 +00:00
Aliaksandr f4d36941eb lib: deprecate fold 2025-10-30 16:56:49 +02:00
Robert HensingandGitHub 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
Silvan Mosberger 7636389851 lib.teams: Add githubId from associated github teams
This will allow the code for https://github.com/NixOS/nixpkgs/issues/447514
to make sure that the right team is requested for review,
even if it has been renamed in the meantime.

While the matching is currently based on the teams slug/name and not the
id, renames won't cause problems with `lib.teams`, because CI would
error if there's no match. Changing this can be future work.
2025-10-28 00:01:51 +01:00
Silvan Mosberger ddf8b5da4a lib.teams: Add githubMaintainers field
This is so you can figure out who to ask to get added to the team

Also avoid an unecessary `{ inherit lib; }` argument
2025-10-27 19:36:58 +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
Lukas Wurzinger 73e8a483e6 lib/cli: add toCommandLine 2025-10-21 21:01:32 +02:00
Silvan Mosberger 1ea51e1f1a lib.teams: Remove .githubTeams in favor of singular .github
No team was using the feature of having multiple GitHub teams, and this
would make it tricky to try to sync maintainer teams with GitHub teams.
2025-10-08 21:44:39 +02:00
Wolfgang Walther 91a8fee3aa treewide: remove redundant parentheses
Auto-fixed by nixf-diagnose.
2025-10-05 10:52:03 +02:00
Robert HensingandGitHub 6a5f6f1a4e lib: init strings.join (#446278) 2025-10-02 15:34:34 +00:00
Philip TaronandGitHub 44998896c6 lib: remove optional builtins prefixes from prelude functions (#447402) 2025-09-30 16:28:04 +00:00
John EricsonandGitHub 941a243895 cygwin: add as a cross-compilation target, and get hello to build (#444470) 2025-09-30 14:16:25 +00:00
NAHO e8f998c3bc lib: add builtins prefixes for prelude functions to improve clarity 2025-09-30 09:38:12 +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
David McFarlandandBrian McKenna 39fd8e4adf cygwin: init as a target toolchain
The old cygwin support used -pc-windows-cygnus as the config.  This is
supported by LLVM, but not by GNU. This will change it to -pc-cygwin,
which is more generally supported.

Because the kernel is now 'cygwin' rather than 'windows', isWindows will
return false. There are lots of different reasons isWindows is used in
nixpkgs, but in my experience they often have to do with posix
compatibility and don't apply to cygwin.

Co-authored-by: Brian McKenna <brian@brianmckenna.org>
2025-09-27 13:29:44 -03:00
Johannes Kirschbauer b37ac6a920 lib: init strings.join 2025-09-27 09:18:37 +02:00
Johannes KirschbauerandGitHub 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 KirschbauerandGitHub 348e5028e7 lib/types: minimal fix for the regression of either when used in freeformType (#440459) 2025-09-14 04:38:10 +00: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
Robert HensingandGitHub 0bdb5c1be2 lib.options.optionAttrSetToDocList: add visible = "transparent" (#441782) 2025-09-11 18:24:13 +00:00
Matt Sturgeon 6c20442479 lib.options.optionAttrSetToDocList: add visible = "transparent"
Allows marking an option as invisible, without excluding its sub-options.

In practice, this is similar to `visible = true; internal = true;`,
however it is more explicit and less reliant on implementation details.
2025-09-11 17:00:17 +01:00
misuzuandGitHub 8d45e68ff1 lib.mkEUI64Suffix: init (#416086) 2025-09-11 15:26:02 +00:00
nukdokplex d24f103572 lib.mkEUI64Suffix: fix syntax errors and tests 2025-09-11 00:01:53 +05:00
nukdokplex 68253aae9b lib.mkEUI64Suffix: bring @hsjobeki suggestions
renamed `mac` to `octets` in hextets combining step for better var
naming; rephrased error message to provide a hint of expected format;
replaced `Arguments` with `Inputs` in docstring; added more test cases
for invalid hex digits; added comments in hextets combining step;
2025-09-10 23:41:18 +05:00
Matt Sturgeon 1efdbe8f2f lib/tests/misc: add option visibility test 2025-09-10 14:34:59 +01:00
Marie RamlowandAlyssa Ross b6d48619ed lib.systems: add ppc32 target 2025-09-10 08:15:07 +02:00
nukdokplex 7abe9e95ec lib.network: add lib.mkEUI64Suffix tests to network.sh 2025-09-09 12:23:41 +05:00
Robert Hensing 7ba464154f lib: Introduce Cross Index concept
A Cross Index, short for Cross Platform Pair Index, is the essential
shape of a splice, without the invoking the more mind bending concept
of adding variations of for these 6 pairings to an existing thing so
that it can be switched out for something else.

So the purpose of a Cross Index is to contain the result of `f`\
(which may be reified in code, or just an abstract concept):
 - f "build" "build"
 - f "build" "host"
 - ...

Splicing on the other hand refers not just to these six variants, but
to the idea of tacking them onto one of the variants. (hostTarget,
I believe)

Cross Indexes are a necessity for making cross compilation work, but
splicing is more than necessary.
2025-09-09 04:42:37 +02:00
Robert Hensing ca4beaaf1c lib: Add splice structure utilities 2025-09-09 04:42:36 +02:00
Wolfgang WaltherandGitHub 399136b3d7 lib/attrsets: add mapAttrsToListRecursive(Cond) function (#395160) 2025-09-08 19:12:59 +00:00
Johannes Kirschbauer b3cf9ce0f9 lib/types.either: add tests for warning in legacy case 2025-09-06 12:29:16 +02:00
Wolfgang Walther 568b19f656 maintainers: require GitHub handle
At the scale of Nixpkgs, actively maintaining a package is only possible
with integration into CI. To be able to be pinged for review requests,
the maintainer must have a GitHub handle, which:
- Leads to an invitation to the NixOS org, which comes with additional
privileges.
- Allows to request the maintainer for review as a member of this org.
- Automatically requests the maintainer for review in CI.

Currently, the GitHub handle is not strictly enforced. This leads to
some new maintainers accidentally forgetting to set these. We can avoid
these mistakes and enforce them via CI.
2025-09-02 09:57:25 +02:00
0477b30ab6 lib.attrsets.genAttrs': init (#436434)
* lib.attrsets.genAttrs': init

* lib.attrsets.genAttrs: rewrite with lib.attrsets.genAttrs'

* lib.attrsets.{genAttrs,genAttrs'}: add tests

* Update lib/attrsets.nix

Co-authored-by: Johannes Kirschbauer <hsjobeki+github@gmail.com>

* Update lib/attrsets.nix

Co-authored-by: Johannes Kirschbauer <hsjobeki+github@gmail.com>

* lib.attrsets.genAttrs': document and test attrName collision

---------

Co-authored-by: Johannes Kirschbauer <hsjobeki+github@gmail.com>
2025-09-01 11:58:28 +02:00
Mikael Voss e5ac84e29c lib/attrsets: add mapAttrsToListRecursive(Cond) function 2025-08-31 12:11:43 +02:00
Niols ad1e615f48 lib.types: add module tests for fileset 2025-08-29 13:07:55 +02:00
Robert HensingandGitHub 83fed2e6ff lib.modules: init types checkAndMerge to allow adding 'valueMeta' (#391544) 2025-08-28 14:34:31 +02:00
Jörg Thalheim 1b7637ff08 nix_2_24: remove 2025-08-27 22:18:31 +02:00