about summary refs log tree commit diff
path: root/lib/tests
AgeCommit message (Collapse)AuthorFilesLines
2021-11-26lib/tests: Use standard test syntaxVictor Engmark1-1/+1
For consistency.
2021-11-26lib/tests: Anchor config output regexesVictor Engmark1-98/+98
Strengthens the tests by making sure the whole line is matched.
2021-11-26lib/tests: Set hardening pragmasVictor Engmark2-4/+8
Makes any programming errors more likely to show up early. Non-obvious changes because of this: - Ignore the `evalConfig` result in `reportFailure`; we're not checking it at that point. - Pre-increment `$fail` and `$pass` to make sure the arithmetic doesn't result in a zero, which would result in a non-zero exit code for the expression.
2021-11-26lib/tests: Don't return non-zero values from checksVictor Engmark1-5/+0
The exit codes aren't used for anything.
2021-11-26lib/tests: Avoid assigning an array to a stringVictor Engmark1-2/+2
As per <https://github.com/koalaman/shellcheck/wiki/SC2124>.
2021-11-26lib/tests: Remove redundant semicolonsVictor Engmark1-6/+6
2021-11-26lib/tests: Clarify assignmentVictor Engmark1-1/+1
The extra equal sign was confusing, and doesn't seem to be relevant.
2021-11-26lib/tests: Use correct shebang lineVictor Engmark1-1/+1
The script uses plenty of non-POSIX features, such as referencing `$BASH_SOURCE`.
2021-11-26lib/tests: Quote variable referencesVictor Engmark1-5/+5
2021-11-26lib/tests: `export` separately from assignmentVictor Engmark1-2/+3
Avoids hiding the exit code from the assignment. See <https://github.com/koalaman/shellcheck/wiki/SC2155>.
2021-11-22modules: Add moduleType to module argumentsRobert Hensing3-0/+36
2021-11-09lib/tests/sources: update to Nix 2.4 cli syntaxBernardo Meurer2-3/+7
2021-11-09lib/tests/modules.sh: update to Nix 2.4 syntaxBernardo Meurer1-12/+12
2021-11-01lib.evalModules: Add extendModules and type to resultRobert Hensing2-0/+35
Allows the simultaneous construction of top-level invocations and submodule types. This helps structure configuration systems integration code.
2021-10-05Merge pull request #140284 from Infinisil/types-anything-lambdasSilvan Mosberger2-4/+12
lib/types: Make types.anything merge functions
2021-10-03Merge pull request #140136 from rnhmjoj/matrix-idsMichele Guerini Rocco1-0/+4
maintainers/maintainers-list: add Matrix IDs
2021-10-03lib: add function escapeXMLRobert Helgesson1-0/+5
Given a string, this function returns a string that can be inserted verbatim in an XML document.
2021-10-02lib/types: Make types.anything merge functionsSilvan Mosberger2-4/+12
Previously it would give an error if there were multiple function definitions.
2021-10-01lib/tests/maintainers: add matrix optionrnhmjoj1-0/+4
2021-09-29Merge pull request #131205 from Ma27/showdefs-overflowLinus Heckemann1-0/+19
lib/modules: improve errors for `options`/`config`-mixups
2021-09-09lib/systems: add minimal s390x-linux cross-compile supportSergei Trofimovich1-1/+1
Tested basic functionality as: $ nix-build --arg crossSystem '{ config = "s390x-unknown-linux-gnu"; }' -A re2c $ file ./result/bin/re2c $ ./result/bin/re2c: ELF 64-bit MSB executable, IBM S/390, version 1 (SYSV), dynamically linked, interpreter ...-gnu-2.33-50/lib/ld64.so.1, for GNU/Linux 2.6.32, not stripped $ qemu-s390x ./result/bin/re2c --version re2c 2.2
2021-08-26lib/generators: move limit detection into `withRecursion`Maximilian Bosch1-3/+4
As suggested in #131205. Now it's possible to pretty-print a value with `lib.generators` like this: with lib.generators; toPretty { } (withRecursion { depthLimit = 10; } /* arbitrarily complex value */) Also, this can be used for any other pretty-printer now if needed.
2021-08-25lib/generators/toPretty: add evaluation-limitMaximilian Bosch1-0/+18
When having e.g. recursive attr-set, it cannot be printed which is solved by Nix itself like this: $ nix-instantiate --eval -E 'let a.b = 1; a.c = a; in builtins.trace a 1' trace: { b = 1; c = <CYCLE>; } 1 However, `generators.toPretty` tries to evaluate something until it's done which can result in a spurious `stack-overflow`-error: $ nix-instantiate --eval -E 'with import <nixpkgs/lib>; generators.toPretty { } (mkOption { type = types.str; })' error: stack overflow (possible infinite recursion) Those attr-sets are in fact rather common, one example is shown above, a `types.<type>`-declaration is such an example. By adding an optional `depthLimit`-argument, `toPretty` will stop evaluating as soon as the limit is reached: $ nix-instantiate --eval -E 'with import ./Projects/nixpkgs-update-int/lib; generators.toPretty { depthLimit = 2; } (mkOption { type = types.str; })' |xargs -0 echo -e "{ _type = \"option\"; type = { _type = \"option-type\"; check = <function>; deprecationMessage = null; description = \"string\"; emptyValue = { }; functor = { binOp = <unevaluated>; name = <unevaluated>; payload = <unevaluated>; type = <unevaluated>; wrapped = <unevaluated>; }; getSubModules = null; getSubOptions = <function>; merge = <function>; name = \"str\"; nestedTypes = { }; substSubModules = <function>; typeMerge = <function>; }; }" Optionally, it's also possible to let `toPretty` throw an error if the limit is exceeded.
2021-08-15treewide: runCommandNoCC -> runCommandRobert Hensing2-3/+3
This has been synonymous for ~5y.
2021-08-04Merge pull request #131267 from blaggacao/fix-functionArgsSilvan Mosberger1-0/+10
lib: fix functionArgs for functors
2021-08-03lib: fix functionArgs for functorsDavid Arnold1-0/+10
`functionArgs` should give valid results on functions that have been identified with `lib.isFunction` instead of erroring out.
2021-08-01lib.systems: add m68k-netbsd supportAlyssa Ross1-1/+1
m68k was recently added for Linux and none, but NetBSD also supports m68k. Nothing will build yet, but I want to make sure we at least encode the existence of NetBSD support for every applicable architecture we support for other operating systems.
2021-07-25Initial implementation of s390 cross-compileBen Siraphob1-1/+1
2021-07-24Initial implementation of m68k cross-compileBen Siraphob1-1/+1
2021-05-29lib/tests/sources.sh: initRobert Hensing2-0/+63
2021-05-05Revert "lib/tests: Add type deprecation tests"Robert Hensing2-45/+0
This reverts commit 8b957e3b301d748e6fbbed806d82bd9d4b9d4ac4.
2021-05-03lib/tests: Add type deprecation testsSilvan Mosberger2-0/+45
2021-05-03lib/tests: Make sure the submodule type description can be evaluatedSilvan Mosberger2-3/+4
In 2d45a62899d47c109a0b8ce4ca9d33265b8a1a37, the submodule type description was amended with the freeformType description. This causes all the modules passed to the submodule to be evaluated once on their own, without any extra definitions from the config section. This means that the specified modules need to be valid on their own, without any undeclared options. This commit adds a test that evaluates a submodules option description, which would trigger the above problem for one of the tests, if it were not fixed by this commit as well. This is done because the next commit makes option evaluation a bit more strict, which would also trigger this test failure, even though it's not related to the change at all.
2021-04-23lib.systems.doubles.netbsd: expandAlyssa Ross1-3/+3
These are all the architectures supported by Nixpkgs on other platforms, that are also supported by NetBSD. (So I haven't added any architectures that are new to Nixpkgs here, even though NetBSD supports some that we don't have.)
2021-03-11lib/modules: better error message if an attr-set of options is expectedMaximilian Bosch1-1/+1
I recently wrote some Nix code where I wrongly set a value to an option which wasn't an actual option, but an attr-set of options. The mistake I made can be demonstrated with an expression like this: { foo = { lib, pkgs, config, ... }: with lib; { options.foo.bar.baz = mkOption { type = types.str; }; config.foo.bar = 23; }; } While it wasn't too hard to find the cause of the mistake for me, it was necessary to have some practice in reading stack traces from the module system since the eval-error I got was not very helpful: error: --- TypeError --------------------------------------------------------- nix-build at: (323:25) in file: /nix/store/3nm31brdz95pj8gch5gms6xwqh0xx55c-source/lib/modules.nix 322| foldl' (acc: module: 323| acc // (mapAttrs (n: v: | ^ 324| (acc.${n} or []) ++ f module v value is an integer while a set was expected (use '--show-trace' to show detailed location information) I figured that such an error can be fairly confusing for someone who's new to NixOS, so I decided to catch this case in th `byName` function in `lib/modules.nix` by checking if the value to map through is an actual attr-set. If not, a different error will be thrown.
2021-01-30Merge pull request #111345 from r-burns/ppc64-big-endianJohn Ericson1-1/+1
Enable PPC64 (big-endian)
2021-01-30lib.systems: add powerpc64-linuxRyan Burns1-1/+1
PPC64 supports two ABIs: ELF v1 and v2. ELFv1 is historically what GCC and most packages expect, but this is changing because musl outright does not work with ELFv1. So any distro which uses musl must use ELFv2. Many other platforms are moving to ELFv2 too, such as FreeBSD (as of v13) and Gentoo (as of late 2020). Since we use musl extensively, let's default to ELFv2. Nix gives us the power to specify this declaratively for the entire system, so ELFv1 is not dropped entirely. It can be specified explicitly in the target config, e.g. "powerpc64-unknown-linux-elfv1". Otherwise the default is "powerpc64-unknown-linux-elfv2". For musl, "powerpc64-unknown-linux-musl" must use elfv2 internally to function.
2021-01-28lib/attrsets: add cartesianProductOfSets functionJacek Galowicz1-0/+67
2021-01-27lib/tests: More functionTo testsSilvan Mosberger7-31/+117
2021-01-24lib/tests/modules: add a test for the functionTo typeBas van Dijk2-0/+32
(cherry picked from commit 478af112e83df806bd8a51174834d2a130fbdeb9)
2020-12-18Revert "Module-builtin assertions, disabling assertions and submodule ↵Silvan Mosberger11-160/+22
assertions"
2020-12-17lib/modules: Introduce _module.checks.*.checkSilvan Mosberger10-11/+21
Previously the .enable option was used to encode the condition as well, which lead to some oddness: - In order to encode an assertion, one had to invert it - To disable a check, one had to mkForce it By introducing a separate .check option this is solved because: - It can be used to encode assertions - Disabling is done separately with .enable option, whose default can be overridden without a mkForce
2020-11-30lib/modules: Remove _module.checks.*.triggerPath as it's not necessarySilvan Mosberger5-82/+0
Previously this option was thought to be necessary to avoid infinite recursion, but it actually isn't, since the check evaluation isn't fed back into the module fixed-point.
2020-11-30lib/modules: Rename _module.assertions to _module.checksSilvan Mosberger13-20/+20
2020-11-30lib/tests: Add tests for module-builtin assertionsSilvan Mosberger13-0/+197
2020-11-30lib/tests: Implement generalized checkConfigCodeOutErr for module testsSilvan Mosberger1-21/+34
2020-11-30nixos/modules: Expose the internal module in the top-level documentationSilvan Mosberger1-1/+1
2020-11-14Merge pull request #102766 from siraben/mmixJohn Ericson1-2/+4
Initial implementation of cross-compilation to Knuth's MMIX
2020-11-13lib: Add composeManyExtensionsJoe Hermaszewski1-0/+20
2020-11-09Initial implementation of mmix cross-compileBen Siraphob1-2/+4