Commit graph

616 commits

Author SHA1 Message Date
Emily 6673e05ad0 lib: add fromHexString tests for distressing behaviour
This was cherry‐picked from
<https://github.com/NixOS/nixpkgs/pull/266705> and merged as part of
<https://github.com/NixOS/nixpkgs/pull/318712>, despite there being
a blocking review on the former pointing out these kinds of issues.

This documents some of the dodgy behaviour. It also can’t handle
negative literals. It might be worth considering deprecating and
dropping this, by inlining it into `lib.network.ipv6.fromString`,
its only in‐tree user.
2025-08-14 21:02:11 +01:00
Sergei Zimmerman 67ef2657ff
lib/tests/test-with-nix: run misc.nix tests in the derivation
This would have allowed us to catch to fromTOML regression in
[1] without waiting for the dogfooding on master, since previously
these tests [2] were not run for the Nix/Lix under test - only the host
nix.

[1]: https://github.com/NixOS/nix/pull/13741
[2]: https://github.com/NixOS/nixpkgs/pull/433710
2025-08-14 19:22:35 +03:00
Sergei Zimmerman 76a7b54083
lib/tests/misc: don't hardcode store directory 2025-08-14 19:18:08 +03:00
Sergei Zimmerman 74799dd97c
lib/tests/misc: don't import nixpkgs 2025-08-14 19:10:08 +03: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
Wolfgang Walther fa0cba1c39
nix_2_3: drop
This has been marked insecure a while ago, as some CVEs have not been
backported. Even if *some* CVEs are fixed, we'd need **all** of them to
be, to get it back into the cache.

Not having it in the cache means, we can not test it in CI. This means
we can't make sure to actually support this version to evaluate Nixpkgs.
2025-08-12 11:28:40 +02:00
Wolfgang Walther cc3d2295b6
nixVersions.minimum: drop
The concept of this alias becomes questionable once we move past 2.18,
where Lix was forked. We should probably move to a feature-detection
based approach for lib/minver.nix eventually, too.
2025-08-12 11:28:38 +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
Wolfgang Walther 5a0711127c
treewide: run nixfmt 1.0.0 2025-07-24 13:55:40 +02:00
Rebecca Turner 4a81a5e556
lib.packagesFromDirectoryRecursive: Allow non-"path" directory
As initially designed, `lib.packagesFromDirectoryRecursive` allowed
passing a string for the `directory` argument. This is necessary for
several reasons:

- `outPath` on derivations and Flake inputs is not a path.
- Derivations can be coerced to their `outPath` in string interpolation,
  but that produces strings, not paths.
- `builtins.path`, bizarrely, returns a string instead of a path (not
  that the documentation makes this clear).

If a path is used instead of a string here, then Nix will dutifully copy
the entire directory into a new path in the Nix store (ignored as
WONTFIX by Eelco in https://github.com/NixOS/nix/issues/9428). For
industrial use cases, this can result in an extra 10-15 seconds on every
single eval just to copy files from one spot in the Nix store to another
spot in the Nix store.

In #361424, this was changed so that `directory` must be a path,
breaking these use-cases.

I'm not really sure what happened here -- #361424 has very little
justification for why it exists, only a reference to a previous version
of the PR (#359941), which itself had very little justification given.
The description on #359941 explained that it would "Shrink the
function's code by ~2/3rd 🎉", but 60% of the reduction in size was just
deleting comments (!) and bindings like `directoryEntryIsPackage` that
helped clarify the intent of the implementation. As a result, the new
implementation is (to my eyes) more challenging to read and understand.
I think the whole thing was in service of #392800, which adds a
`newScope` argument in order "to create nested scopes for each
(sub)directory (not just the top-level one) when `newScope` is given."

Nobody noticed this regression until after the commit was merged. After
@phanirithvij pointed out the regression, @nbraud said they would
"shortly prepare a PR to fix this" [1] but did not. Later, they would
explain that they were "quite ill the last month(s)" [2], which explains
why this got forgotten about. @nbraud also requested a review from
@Gabriella439 [3], as she had reviewed the original PR adding
`lib.packagesFromDirectoryRecursive`, but not from me, the original
author of that PR. @Gabriella439 did not review the "refactor" PR, and
no attempt to contact her or myself was made after that initial request.
This behavior is admittedly rather subtle, so I'm not sure either
Gabriella or myself would have noticed the change (especially since the
relevant PR restructures the entire implementation).

While I find this a bit frustrating, I should have added a test for this
use-case in my original PR; if there was a test that relied on passing
paths in as a string, perhaps the authors modifying this code would have
noticed that the implementation was not an accident.

[1]: https://github.com/NixOS/nixpkgs/pull/361424#discussion_r1912407693
[2]: https://github.com/NixOS/nixpkgs/pull/359984#issuecomment-2775768808
[3]: https://github.com/NixOS/nixpkgs/pull/361424#issuecomment-2521308983
2025-07-10 16:13:38 -07:00
Johannes Kirschbauer 86603255c3
lib.filesystem.resolveDefaultNix: init (#418824) 2025-07-03 12:54:47 +02:00
Alyssa Ross a61841a597 nixVersions.nix_2_3: add knownVulnerabilities 2025-06-30 10:26:29 +02:00
sodiboo b3c9916455 lib.types.attrTag: expose suboptions at correct level 2025-06-22 21:23:18 +02:00
Robert Hensing ecc039f327 lib.filesystem.resolveDefaultNix: init 2025-06-21 21:43:37 +02:00
Johannes Kirschbauer 1849ee507e
modules: Add _prefix module argument, improve error, add docs (#398839) 2025-06-19 16:09:07 +02:00
Jade Lovelace 332bc64369 ci/eval: accept nix directly
Previously we were taking nixVersions and this made external use from
the Lix repo's CI annoying.

We should probably also test other nix versions than stable (i.e. also
latest and Lix), but this involves writing GitHub Actions about it and
maybe not running it on every single PR. Future work.
2025-06-10 16:04:38 -07:00
Wolfgang Walther a7f4e0f9ae
lib/tests: avoid full rebuild when only maintainers change
The vast majority of CI jobs to build the lib tests are caused by
changes in the maintainer list. In this case, we currently run the full
test-suite which takes 3-4 minutes. By moving the maintainers and teams
tests out of the test-with-nix file, we save almost all of that.
Building only those two tests on a change is almost instant. This only
works, because we previously enabled cachix for the workflow.

Note, that these tests are not actually run with both nix versions, even
though they were listed in the "test with specific nix version" file.
That's because we only differ in the nix version run *inside* the
sandbox, but not doing the outer build.

Since this file seems to be re-used by NixOS/nix' CI, this is
technically a small loss in coverage for that repo, but nixpkgs CI
considerations outweigh that. But because of this, I left the other
non-nix-version-specific tests in that file.
2025-06-02 09:12:19 +02:00
Gutyina Gergő b5720e2b3f
lib/strings: init replaceString 2025-05-28 00:20:56 +02:00
Simon Hollingshead 6b6e23bfda
treewide: maintainers-list.nix -> maintainer-list.nix (#409585) 2025-05-22 15:42:16 +05:30
Johannes Kirschbauer b7d438b87c
lib.strings: init toCamelCase (#402372) 2025-05-18 22:18:39 +02:00
Heitor Augusto 24e8a790b7
lib.strings: init toCamelCase 2025-05-11 20:24:56 -03:00
Wolfgang Walther c8d2eca963
.editorconfig: move subfolder config into separate .editorconfig files
This avoids paths in the top-level file getting out-of-sync, because the
.editorconfig files would be moved together with the files they target.
2025-05-07 20:01:35 +02:00
Johannes Kirschbauer be393db73e
lib.takeEnd: init (#398222) 2025-04-23 14:20:47 +02:00
Pol Dellaiera a9320986b3
lib.strings: init splitStringBy (#385643) 2025-04-23 04:51:38 +00:00
Norbert Melzer b2f1b6b8f0
lib/strings: Zero‐pad hex digits in escapeC (#399722) 2025-04-21 17:12:55 +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
Mikael Voss 487a002c63
lib/strings: Zero‐pad hex digits in escapeC
lib.strings.escapeC produces single‐digit hexadecimal strings for
character values ≤ 15, which results in an ambiguity. If the following
character is a hex digit, it will be interpreted as being part of the
escape sequence.

systemd, which also relies on C‐style escape sequences, does not
decode single‐digit sequences at all, even if unambiguous.

Padding the hexadecimal string with "0" avoids this problem.
2025-04-18 13:41:53 +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
azahi 9fee9e7371
lib.takeEnd: init 2025-04-13 17:37:35 +03:00
K900 aece6a0c1f Merge remote-tracking branch 'origin/master' into staging-next 2025-04-11 21:17:42 +03:00
Robert Hensing 3e5af839c2
lib.types.submodule: Disable check during docs generation (#396907) 2025-04-11 19:12:32 +02:00
nixpkgs-ci[bot] c55a1a7779
Merge master into staging-next 2025-04-11 00:15:47 +00:00
Robert Hensing e09cf9f066 lib.types.submodule: Disable check during docs generation
Put simply docs generation is a weird eval, and we should avoid
generating any unnecessary errors.
2025-04-11 00:32:01 +02:00
Robert Hensing d84b0024f6
lib/modules: export class inside specialArgs (#395141) 2025-04-10 20:58:41 +02: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
nixpkgs-ci[bot] 6c98e107c7
Merge master into staging-next 2025-04-09 00:15:45 +00:00
Jörg Thalheim abd52dd872 nixVersions.{nix_2_28,nix_2_26}: switch simplified meson build
So we are adding a simplified version that builds a monolithic nix binary to get finished
in time for the release. Afterwards we will switch to the modular build again.
2025-04-08 12:29:11 -04:00
Heitor Augusto bb4be9a474
lib.strings: init splitStringBy 2025-04-07 15:51:18 -03:00
K900 b3146d4446 Merge remote-tracking branch 'origin/master' into staging-next 2025-04-07 21:21:10 +03:00
Johannes Kirschbauer 33daa3f4b9
lib.modules: init test for lib.mkDefinition 2025-04-03 15:03:00 +02:00
Emily 1e6ab3434f treewide: drop support for 32‐bit Darwin
It’s dead, Jim.
2025-04-02 21:20:44 +01: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
Robert Hensing bb984408d5 lib/tests/release.nix: Use nix.overrideScope for >=2.26 2025-03-31 00:47:37 +02:00
Robert Hensing 90c1822309 nixVersions.nix_2_26: Fix cross and static 2025-03-26 18:33:43 -04:00
nicoo 32235deeb8 lib.packagesFromDirectoryRecursive: default to creating new scopes when newScope is provided
Co-authored-by: Rebecca Turner <rbt@sent.as>
2025-03-26 12:11:44 +01:00
nicoo 41f219d1d9 lib.packagesFromDirectoryRecursive: add tests for nested scopes 2025-03-26 12:11:43 +01:00
nicoo fdd2c6f80f lib/tests: move packages-from-directory/* into a subdir
in preparation for adding more tests for `lib.packagesFromDirectoryRecursive`
2025-03-24 18:35:26 +01: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
Mikael Voss 7a07cc0da9
lib/strings: allow CA paths in isStorePath 2025-03-05 13:08:41 +01:00
Wroclaw 0de1d18795 lib.types.functionTo: preserve functionArgs
Previously if function in defs had set pattern in argument,
this information would be lost.

This keeps functionArgs in set pattern,
by using functor and `__functionArgs`
that is later used by `lib.functionArgs`.
2025-03-02 00:04:19 +01:00
Johannes Kirschbauer 0e46672592
lib.types: Make functor.wrapped deprecation work in unprocessed types (#382848) 2025-02-21 15:57:20 +07:00
Johannes Kirschbauer 0d52202380
lib.strings: init toSentenceCase (#381802) 2025-02-20 07:58:44 +07:00
isabel b109863c25 lib.strings: init toSentenceCase 2025-02-19 12:10:39 +00: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 9d3e649939
lib.types: init mergeTypes (#364620) 2025-02-10 22:10:30 +07:00
Johannes Kirschbauer 3c911b2aca
lib.types: init mergeTypes 2025-02-10 21:23:12 +07:00
Johannes Kirschbauer b3884c8b7d
lib/modules: tests change expected error for class mismatch 2025-01-29 11:50:16 +01:00
Silvan Mosberger 0f880eb305
lib.dropEnd (#370558) 2025-01-13 21:30:30 +01:00
piegames 603733851b treewide: Fix incorrect string escapes 2025-01-07 19:49:28 +01:00
Robert Hensing 782a0e6581 lib.dropEnd: init
Naming borrowed from Haskell
- `base`: [`dropWhileEnd`]
- `extra`, `mono-traversable`, ...: [`dropEnd`]

[`dropEnd`]: https://hackage.haskell.org/package/mono-traversable-1.0.21.0/docs/Data-Sequences.html#v:dropEnd
[`dropWhileEnd`]: https://hackage.haskell.org/package/base-4.21.0.0/docs/Data-List.html#v:dropWhileEnd
2025-01-03 12:04:06 +01:00
Robert Hensing c96e907825 lib/tests/misc: Test lib.drop 2025-01-03 12:03:33 +01:00
Silvan Mosberger d510f60a4d
lib.generators.toPlist: escape XML syntax in strings & keys (#356502) 2024-12-23 13:47:44 +01:00
Linnnus d1cb670ee6 lib.generators.toPlist: escape XML syntax in strings & keys
Before this patch, code like this would break generate invalid XML:

    lib.generators.toPlist {} "ab<cd"

That's obviously bad, since the call to toPlist often happens through
indirection, as is the case in e.g. the nix-darwin project. A user might
not realize that they have to escape the strings.

This patch adds the argument 'escape' to lib.generators.plist and emits
a warning if it is not set to true. In a future release, this behavior
should become the default.

I have also added a note for future maintainers, in case I forget to
actually remove the deprecated functionality in a future release.
2024-12-23 12:29:20 +01:00
Robert Hensing efd4a649fe lib/tests/release.nix: Expose system parameter 2024-12-16 23:49:08 +01:00
sternenseemann a0a35b6c24
Fix cross eval issues (#362546) 2024-12-14 22:14:52 +01:00
Artturin 764c99481a lib/tests/release.nix: Fix build if impure.nix returns a cross pkgs
In https://www.github.com/NixOS/nixpkgs/pull/341067 `ofborg-eval-lib-tests`
fails because it uses `pkgsHostTarget` of the cross pkgs

```diff
diff --git a/pkgs/top-level/impure.nix b/pkgs/top-level/impure.nix
index 4d847e280f4b..7f0099b254f0 100644
--- a/pkgs/top-level/impure.nix
+++ b/pkgs/top-level/impure.nix
@@ -86,4 +86,6 @@ assert args ? system -> !(args ? localSystem);

 import ./. (builtins.removeAttrs args [ "system" ] // {
   inherit config overlays localSystem;
-})
+} // (if ((localSystem.system or localSystem) == "x86_64-linux" || (localSystem.system or localSystem) == "aarch64-linux") then {
+  crossSystem = { config = "aarch64-unknown-linux-gnu"; };
+  } else {}) )
```
2024-12-12 21:09:56 +02: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 2936a2ab9b
lib.strings.concatMapAttrsStringSep: init (#330010) 2024-12-06 09:53:50 +01:00
Yueh-Shun Li b1371135b5 lib.strings.concatMapAttrsStringSep: init 2024-12-06 11:02:26 +08: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 23a7a7d8b4
lib/types: init {types.attrsWith} (#354738) 2024-12-02 16:47:32 +01:00
Silvan Mosberger d5eccbbbae lib/types: standardise attrsOf functor.wrapped warning and add a test 2024-12-02 16:18:03 +01:00
Philip Taron 9396352fba
lib/systems: elaborate properly with non-matching system / config / parsed args (#351608) 2024-11-29 15:48:15 -08:00
John Ericson 07f8638828
freebsd: Add support for aarch64 (#358053) 2024-11-26 20:39:38 -05: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