about summary refs log tree commit diff
path: root/lib/tests
AgeCommit message (Collapse)AuthorFilesLines
2023-12-19lib: `modules.sh` should check JSON output for predictabilityRebecca Turner4-17/+24
Currently, the `lib/tests/modules.sh` test checks the output of `nix-instantiate --eval` without `--json`, which outputs an unspecified human-readable format. This patch modifies `modules.sh` to use the `--json` output instead, to be robust against future changes to `nix-instantiate` output.
2023-12-15lib/tests/release.nix: temporary reference to pkgs/test/releaseAdam Joseph1-1/+13
This commit temporarily adds pkgs/test/release to the lib/tests/release.nix test suite, because ofborg already knows about that entry point. We should move the list of test entry points out of ofborg and into a central place in nixpkgs: https://github.com/NixOS/nixpkgs/issues/272591 Once we do that we won't need to have this ugly kludge in an inappropriate place.
2023-12-11Merge pull request #273004 from hercules-ci/attrset-path-longest-prefixRobert Hensing1-0/+45
lib.attrsets.longestValidPathPrefix: init
2023-12-10Merge pull request #272709 from hercules-ci/module-system-test-pr-131205Maximilian Bosch3-0/+34
lib/modules: Test optionless module errors from #131205
2023-12-10Merge pull request #272764 from tweag/anyBoolRobert Hensing2-0/+20
lib.types.anyBool: init
2023-12-09lib/modules: Clarify test assertionsRobert Hensing1-0/+3
2023-12-09lib/modules: Test optionless module errors from #131205Robert Hensing3-0/+31
2023-12-08lib.attrsets.hasAttrByPath: Document law and laziness, and test itRobert Hensing1-0/+5
2023-12-08lib.attrsets.longestValidPathPrefix: initRobert Hensing1-0/+40
Allows finding the most specific path that exists. This is useful for error messages relating to attribute paths.
2023-12-08lib.sortOn: initRobert Hensing1-0/+22
A more efficient sort in some cases, and often convenient. This exposes `lib.lists.sortOn` immediately on `lib`, because it is a sibling of `sort`, which is already present there. Omitting it would lead to more confusion, and worse outcomes. There's no confusion about the types `sort` or `sortOn` operate on. Haskell agrees about the type for `sortOn`, and it is in its `base`.
2023-12-08lib.types.boolByOr: initSilvan Mosberger2-0/+20
This type is necessary to have correct merging behavior for `allowUnfreePredicate` and `allowInsecurePredicate` Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2023-11-27Merge pull request #269552 from adisbladis/lib-matchattrs-list-allocsRobert Hensing1-0/+20
lib.attrsets.matchAttrs: Avoid some list allocations when walking structure
2023-11-27lib.attrsets.matchAttrs: Avoid some list allocations when walking structureadisbladis1-0/+20
Benchmarks (`nix-instantiate ./. -A python3`): - Before: ``` json { "cpuTime": 0.29049500823020935, "envs": { "bytes": 4484216, "elements": 221443, "number": 169542 }, "gc": { "heapSize": 402915328, "totalBytes": 53086800 }, "list": { "bytes": 749424, "concats": 4242, "elements": 93678 }, "nrAvoided": 253991, "nrFunctionCalls": 149848, "nrLookups": 49612, "nrOpUpdateValuesCopied": 1587837, "nrOpUpdates": 10104, "nrPrimOpCalls": 130356, "nrThunks": 358981, "sets": { "bytes": 30423600, "elements": 1859999, "number": 41476 }, "sizes": { "Attr": 16, "Bindings": 16, "Env": 16, "Value": 24 }, "symbols": { "bytes": 236145, "number": 24453 }, "values": { "bytes": 10502520, "number": 437605 } } ``` - After: ``` json { "cpuTime": 0.2946169972419739, "envs": { "bytes": 3315224, "elements": 172735, "number": 120834 }, "gc": { "heapSize": 402915328, "totalBytes": 48718432 }, "list": { "bytes": 347568, "concats": 4242, "elements": 43446 }, "nrAvoided": 173252, "nrFunctionCalls": 101140, "nrLookups": 73595, "nrOpUpdateValuesCopied": 1587837, "nrOpUpdates": 10104, "nrPrimOpCalls": 83067, "nrThunks": 304216, "sets": { "bytes": 29704096, "elements": 1831673, "number": 24833 }, "sizes": { "Attr": 16, "Bindings": 16, "Env": 16, "Value": 24 }, "symbols": { "bytes": 236145, "number": 24453 }, "values": { "bytes": 8961552, "number": 373398 } } ```
2023-11-25lib.meta: Avoid attrset allocation in platformMatchadisbladis1-0/+20
Benchmarks (`nix-instantiate ./. -A python3`) - Before ``` json { "cpuTime": 0.30625399947166443, "envs": { "bytes": 4484216, "elements": 221443, "number": 169542 }, "gc": { "heapSize": 402915328, "totalBytes": 53091024 }, "list": { "bytes": 749424, "concats": 4242, "elements": 93678 }, "nrAvoided": 253991, "nrFunctionCalls": 149848, "nrLookups": 49614, "nrOpUpdateValuesCopied": 1588326, "nrOpUpdates": 10106, "nrPrimOpCalls": 130356, "nrThunks": 359013, "sets": { "bytes": 30432320, "elements": 1860540, "number": 41480 }, "sizes": { "Attr": 16, "Bindings": 16, "Env": 16, "Value": 24 }, "symbols": { "bytes": 236218, "number": 24459 }, "values": { "bytes": 10504632, "number": 437693 } } ``` - After ``` { "cpuTime": 0.29695799946784973, "envs": { "bytes": 3296712, "elements": 169055, "number": 121517 }, "gc": { "heapSize": 402915328, "totalBytes": 49044992 }, "list": { "bytes": 504928, "concats": 4242, "elements": 63116 }, "nrAvoided": 175403, "nrFunctionCalls": 110554, "nrLookups": 44907, "nrOpUpdateValuesCopied": 1588326, "nrOpUpdates": 10106, "nrPrimOpCalls": 82330, "nrThunks": 306625, "sets": { "bytes": 29943328, "elements": 1843076, "number": 28382 }, "sizes": { "Attr": 16, "Bindings": 16, "Env": 16, "Value": 24 }, "symbols": { "bytes": 236218, "number": 24459 }, "values": { "bytes": 9037752, "number": 376573 } } ```
2023-11-19Merge pull request #266443 from amjoseph-nixpkgs/pr/lib-tests-no-aws-sdkSilvan Mosberger2-2/+20
2023-11-18lib.tests: build nix without flaky aws-sdk-cppAdam Joseph2-2/+20
The aws-sdk-cpp tests are flaky. Since pull requests to staging cause nix to be rebuilt, this means that staging PRs end up getting false CI failures due to whatever is flaky in the AWS SDK tests. Since none of our CI needs to (or should be able to) contact AWS S3, let's just omit it all. Bonus: the tests build way faster.
2023-11-16lib.fileset.gitTracked/gitTrackedWith: initSilvan Mosberger1-0/+2
A configuration parameter for gitTrackedWith will be introduced in the next commit
2023-11-14lib.lists.allUnique: initFelix Buehler1-0/+9
2023-11-07Merge pull request #261676 from h7x4/lib-add-replicatestringSilvan Mosberger1-0/+5
lib.strings: add `replicate`
2023-11-01lib.filesystem: Don't test Nix-specific error messagesSilvan Mosberger1-2/+8
In https://github.com/NixOS/nix/pull/9269 the error messages change which would've broken this test.
2023-10-31lib.strings: add `replicate`h7x41-0/+5
`strings.replicate` returns n copies of a string, concatenated into a new string Co-authored-by: Silvan Mosberger <github@infinisil.com>
2023-10-31Merge pull request #260971 from Gerg-L/getExeSilvan Mosberger1-0/+28
lib.getExe': check arguments
2023-10-16lib/tests: add tests for getExe' and getExeGerg-L1-0/+28
2023-10-16Merge pull request #258866 from schuelermine/mkPackageOptionV4Silvan Mosberger2-0/+42
lib/options: mkPackageOption: document better, add pkgsText and usePname options, refactor
2023-10-11lib.makeOverridable: fix functionArgs on returned functionRobert Hensing1-0/+12
2023-10-10Merge pull request #254452 from flyingcircusio/lib-attrsToListSilvan Mosberger1-0/+24
lib.attrsets.attrsToList: add function
2023-10-10lib.attrsets.attrsToList: add functionOliver Schmidt1-0/+24
For transforming back between lists and attrsets, it makes sense to have a quasi-inverse of `builtins.listToAttrs` available as a library function. Co-authored-by: Silvan Mosberger <github@infinisil.com> Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2023-10-10lib/tests: add test for pkgsText parameter and package set selection of ↵Anselm Schüler2-0/+10
mkPackageOption
2023-10-06lib/tests: add more tests for mkPackageOptionAnselm Schüler2-0/+32
2023-09-28lib.gvariant: make the tests really worklinsui2-87/+58
2023-09-27lib.attrsets.foldlAttrs: Make stricterSilvan Mosberger1-2/+2
See the parent commit for the same change to lib.lists.foldl'
2023-09-27lib.lists.foldl': Make strict in the initial accumulatorSilvan Mosberger1-2/+2
To maintain backwards compatibility, this can't be changed in the Nix language. We can however ensure that the version Nixpkgs has the more intuitive behavior.
2023-09-26lib.lists.foldl': Add testsSilvan Mosberger1-0/+32
2023-09-17Merge pull request #249243 from lf-/jade/declarationsWithLocationsRobert Hensing2-1/+68
nixos/modules: Add declarationPositions
2023-09-11Merge pull request #250220Robert Helgesson1-0/+45
lib.generators.toGitINI: escape string values in configuration
2023-09-08nixos/modules: Add declarationPositionsJade Lovelace2-1/+68
What it does: line and column level *declaration* position information: $ nix repl . nix-repl> :p nixosConfigurations.micro.options.environment.systemPackages.declarationPositions [ { column = 7; file = "/nix/store/24aj3k7fgqv3ly7qkbf98qvphasrw9nb-source/nixos/modules/config/system-path.nix"; line = 63; } ] Use cases: - ctags over NixOS options, as will be presented at NixCon 2023 ;) - improving the documentation pages to go to the exact line of the declarations. Related work: - https://github.com/NixOS/nixpkgs/pull/65024 This one does it for all *definitions* rather than declarations, and it was not followed through with due to performance worries. - https://github.com/NixOS/nixpkgs/pull/208173 The basis for this change. This change is just a rebase of that one. I split it out to add the capability before adding users of it, in order to simplify review. However, the ctags script in there is a sample user of this feature. Benchmarks: conducted by evaluating my own reasonably complex NixOS configuration with the command: `hyperfine -S none -w 1 -- "nix eval .#nixosConfigurations.snowflake.config.system.build.toplevel.outPath"` ``` Benchmark 1: nix eval .#nixosConfigurations.snowflake.config.system.build.toplevel.outPath Time (mean ± σ): 8.971 s ± 0.254 s [User: 5.872 s, System: 1.388 s] Range (min … max): 8.574 s … 9.327 s 10 runs Benchmark 1: nix eval .#nixosConfigurations.snowflake.config.system.build.toplevel.outPath Time (mean ± σ): 8.766 s ± 0.160 s [User: 5.873 s, System: 1.346 s] Range (min … max): 8.496 s … 9.033 s 10 runs ``` Summary of results: it seems to be in the noise, this does not cause any visible regression in times.
2023-09-02Merge pull request #245623 from tweag/fileset.toSourceSilvan Mosberger1-1/+5
File set combinators base: `lib.fileset.toSource`
2023-09-01lib.fileset.toSource: initSilvan Mosberger1-1/+5
2023-08-28Merge pull request #234615 from linsui/dconfJan Tojnar1-0/+93
nixos/dconf: support generating from attrs
2023-08-21lib.generators.toGitINI: added testVwCSXg1-0/+45
Added basic generators.toGitINI test. Mostly taken from https://github.com/nix-community/home-manager/blob/958c06303f43cf0625694326b7f7e5475b1a2d5c/tests/modules/programs/git/git.nix. The ${"\t} escape is used so that the lines aren't recognized as "Wrong indent style".
2023-08-18lib/modules: Report a better error when option tree has bare typeRobert Hensing1-3/+3
Improves on 0d472a62012364d064f0b75f1da491242c6ae9c6 - https://github.com/NixOS/nixpkgs/pull/242339 We actually do have the file name. Thanks Shawn8901 for the [feedback]! feedback: https://github.com/NixOS/nixpkgs/pull/242339#issuecomment-1683107055
2023-08-15lib/gvariant: initlinsui1-0/+93
2023-08-14lib.removePrefix: Add testsSilvan Mosberger1-0/+21
2023-08-14Merge pull request #243511 from tweag/lib.lists.hasPrefixSilvan Mosberger1-0/+38
`lib.lists.{hasPrefix,removePrefix}`: init
2023-08-14lib/modules: Report a good error when option tree has bare typeRobert Hensing4-0/+21
Note that this removes the possibility of declaring an option named `_type`.
2023-08-02Merge pull request #243139 from hercules-ci/modules-test-default-argumentRobert Hensing2-0/+31
lib/tests/modules: Test that _module.args works when a default argume…
2023-07-27Merge pull request #245271 from sternenseemann/module-system-merge-no-typeRobert Hensing2-0/+28
lib/modules: handle typeless options in mergeModules
2023-07-26lib/modules: handle typeless options in mergeModulessternenseemann2-0/+28
mkOption does not require a `type` argument and does not set the resulting attribute if it is not given. Consequently, we need to be prepared to merge options that have no type information.
2023-07-26Merge pull request #243520 from tweag/lib.lists.commonPrefixSilvan Mosberger1-20/+63
`lib.lists.{findFirstIndex,commonPrefix}`: init
2023-07-20lib.lists.commonPrefix: initSilvan Mosberger1-0/+33