Commit Graph

418 Commits

Author SHA1 Message Date
Silvan Mosberger
50e4dbf35b
Merge pull request #205557 from ncfavier/concatLines
lib/strings: add `concatLines`
2023-01-31 18:05:53 +01:00
Naïm Favier
0288ee587f
maintainers: clarify what fields are required 2023-01-27 18:05:28 +01:00
Naïm Favier
93dc2de29a
maintainers: disallow noreply.github.com emails 2023-01-27 18:05:28 +01:00
Naïm Favier
4e39849611
maintainers: make email optional
Not giving an email address is fine as long as the maintainer is
reachable through other means, such as GitHub or Matrix.
2023-01-27 18:04:20 +01:00
John Ericson
c1071e7804
Merge pull request #211622 from alyssais/valgrind-platforms
valgrind: make meta.platforms more accurate
2023-01-19 15:43:22 -05:00
Alyssa Ross
6d165a9474
lib.platforms.s390x: init 2023-01-19 17:43:50 +00:00
Alyssa Ross
541a2a5e91
lib.platforms.power: init 2023-01-19 17:43:49 +00:00
Alyssa Ross
48f3fd2d49
lib.platforms.armv7: init 2023-01-19 17:43:41 +00:00
Robert Hensing
415504e867 lib/tests/release.nix: Make nix a parameter + strictDeps
This makes bisecting nix a bit easier.

Example reproducer, invoked from nix directory:

```bash
nix-build ../nixpkgs/lib/tests/release.nix --arg nix '(builtins.getFlake "git+file://${toString ./.}").packages.x86_64-linux.default'
```
2023-01-18 01:39:38 +01:00
Robert Hensing
f61d4d346b
Merge pull request #205190 from NixOS/lib.path.relativeNormalise
lib.path.subpath.{isValid,normalise}: init
2023-01-03 13:46:11 +01:00
Silvan Mosberger
98fbcf1788 lib.path.subpath.isValid: init
The first path library function
2023-01-03 13:20:36 +01:00
Naïm Favier
0355479715
lib/versions: add pad
Pad a version string with zeros to match a given number of components.
2022-12-21 12:58:21 +01:00
figsoda
695d4bc76b lib: fix typos 2022-12-17 18:59:29 -05:00
Robert Hensing
efa1140e83
Merge pull request #205457 from h7x4/lib-strings-toInt-broken-for-negative-numbers
lib.strings: fix negative number handling for `toInt` and `toIntBase10`
2022-12-11 02:26:42 +01:00
Naïm Favier
ed0b8c26f1
lib/strings: add concatLines
Like `unlines` from Haskell.

The aim is to replace the `concatStringsSep "\n"` pattern for generated
files, which doesn't add a final newline.
2022-12-10 15:56:30 +01:00
h7x4
62e863e98c
lib.strings: fix negative number handling for toInt and toIntBase10
The previous version would be unstable due to an input validation regex
not expecting a '-' in front of the number.
2022-12-10 13:16:45 +01:00
Naïm Favier
6a117e2759 nixos/doc: render option values using lib.generators.toPretty
Render un`_type`d defaults and examples as `literalExpression`s using
`lib.generators.toPretty` so that consumers don't have to reinvent Nix
pretty-printing. `renderOptionValue` is kept internal for now intentionally.

Make `toPretty` print floats as valid Nix values (without a tilde).

Get rid of the now-obsolete `substSpecial` function.

Move towards disallowing evaluation of packages in the manual by
raising a warning on `pkgs.foo.{outPath,drvPath}`; later, this should
throw an error. Instead, module authors should use `literalExpression`
and `mkPackageOption`.
2022-12-08 17:52:52 +01:00
Naïm Favier
0b661ce32a lib/generators.toPretty: escape strings properly 2022-12-08 17:52:52 +01:00
Naïm Favier
0fa7b1b004 lib/generators.toPretty: don't evaluate derivations
With the goal of making `toPretty` suitable for rendering option
values, render derivations as `<derivation foo-1.0>` instead of
`<derivation /nix/store/…-foo-1.0.drv>`.

This is to avoid causing sudden evaluation errors for out-of-tree
projects that have options with `default = pkgs.someUnfreePackage;` and
no `defaultText`.
2022-12-08 17:52:52 +01:00
Robert Hensing
6110a6009f lib/modules: Add context to the "option does not exist" error
Add trace items that provide context for a failed definition that
can not be caught within the Nix language.

This also adds a test for the `tryEval` behavior of `showDefs`.
2022-12-02 11:06:53 +00:00
figsoda
f993f8a186 lib/attrsets: add concatMapAttrs 2022-11-17 10:41:53 -05:00
John Ericson
66aa02f190 lib/systems: Support FreeBSD
A tricky thing about FreeBSD is that there is no stable ABI across
versions. That means that putting in the version as part of the config
string is paramount.

We have a parsed represenation that separates name versus version to
accomplish this. We include FreeBSD versions 12 and 13 to demonstrate
how it works.
2022-11-04 16:49:28 -04:00
Robert Hensing
1b6e5ac952 lib/tests/modules: Test doRename 2022-11-03 13:12:58 +01:00
Jacob Abel
ed71173841
lib/strings: Update docs and restructured code to improve readability of toInt and toIntBase10. 2022-10-23 17:50:24 -04:00
Jacob Abel
39a4ab78a1
lib/strings: Refactor toInt into toInt and toIntBase10 2022-10-23 17:50:24 -04:00
Jacob Abel
3d196a5f2a
lib/strings: Update toInt to handle intermixed ws and zeros. Added tests 2022-10-23 17:50:23 -04:00
Jacob Abel
febff1dccd
lib/strings: allow toInt to parse zero-padded strings 2022-10-23 17:50:20 -04:00
Daniel Olsen
23c1754fff lib/tests/misc: Add tests for charToInt, escapeC, and normalizePath 2022-10-20 20:12:15 +02:00
Maximilian Bosch
ac48f07282
lib/types: always use <function body> instead of [function body] to indicate a function inside an option structure
The motivation is to have a single identifier for that. Useful for the
next commit where I'll try to escape option-parts correctly (options can
be any kind of strings, but unless these are Nix identifiers, they must
be quoted).

Since `<function body>` (or `<name>`/`*`) are special identifiers in
error messages and the manual, we need a unique way to mark an option
part as function call because these are not to be quoted.
2022-10-07 10:01:44 +02:00
figsoda
a1d50eecab
Merge pull request #193132 from figsoda/clean-up
treewide: clean up
2022-10-01 17:03:11 -04:00
figsoda
f9f6872960 lib/tests/maintainers.nix: remove unused binding 2022-09-26 22:18:55 -04:00
Robert Hensing
1ffa30b055 lib/modules: Fix meta duplication in shorthand syntax 2022-09-21 10:55:11 +01:00
Robert Hensing
fce8b018f0 lib: Add lazyDerivation 2022-09-21 10:55:07 +01:00
Robert Hensing
1cbe950384 lib.types: Add parentheses where description is ambiguous 2022-09-17 22:16:39 +01:00
Robert Hensing
3ebb588ab3
Merge pull request #188289 from erikarvstedt/fix-disabled-modules-abs-paths
lib.modules: support strings with absolute paths in `disabledModules`
2022-08-31 15:27:03 +02:00
Erik Arvstedt
e2cc361970
lib.modules: support strings with absolute paths in disabledModules
This is particularly useful for disabling modules defined in a flake.
Example:
disabledModules = [ "${flake}/modules/mymodule.nix" ];

Previously, absolute string paths were internally prepended with `modulesPath`,
which caused the module filtering to fail.
2022-08-31 14:23:28 +02:00
Minijackson
4db467f7e9
lib/systems: add MicroBlaze architectures 2022-08-25 16:00:42 +02:00
Graham Christensen
9ed793229c teams/maintainers list: show instructions for validating the contents 2022-06-20 22:20:26 +02:00
Graham Christensen
ff38ee15c2 maintainer teams: check them in lib tests 2022-06-20 22:20:26 +02:00
Graham Christensen
3ac995a568 maintainer lib test: extract maintainer module 2022-06-20 22:20:26 +02:00
Graham Christensen
c8cebff38b maintainers: remove longkeyid
see https://dkg.fifthhorseman.net/blog/openpgp-key-ids-are-not-useful.html
2022-06-20 22:20:26 +02:00
Robert Hensing
3c4a49f506 lib/modules: Throw earlier when module function does not return attrs
`m` must always be an attrset at this point. It is basically always
evaluated. This will make it throw when any of the attrs is accessed,
rather than just `config`. We assume that this will improve the error
message in more scenarios.
2022-06-14 23:23:41 +02:00
Robert Hensing
dfd98a5da2 lib.deferredModule: Make it properly singular 2022-06-14 23:01:27 +02:00
Robert Hensing
781c2e0789 lib.types.deferredModule: Allow path-typed module references 2022-06-14 23:01:26 +02:00
Robert Hensing
a2c29561e7 lib.types.deferredModule: Improve reported location 2022-06-14 23:01:26 +02:00
Robert Hensing
38b7709a6f lib/test/modules.sh: Test deferredModule error location file 2022-06-14 23:01:26 +02:00
Robert Hensing
4746f6d03e lib.types: Add deferredModule 2022-06-14 23:01:23 +02:00
Silvan Mosberger
79441600c2 lib/tests: Add submodule file propagation test 2022-06-14 17:01:58 +02:00
Silvan Mosberger
4b2827e6a1
Merge pull request #168374 from Ma27/special-attrs-in-with-recursion
lib/generators: withRecursion: don't break attr-sets with special attrs
2022-05-23 17:55:18 +02:00
Robert Hensing
2d1a34b8cc
Merge pull request #172813 from hercules-ci/functionTo-properly
`lib.types.functionTo` type merging and docs
2022-05-17 22:22:21 +02:00
Silvan Mosberger
e06f66e73c
Merge pull request #170561 from klemensn/types-description
lib/types: Drop misleading plural from type descriptions
2022-05-16 17:03:37 +02:00
adisbladis
161776ec1e Revert "lib: init flakes.nix"
This reverts commit PR #167947.

Flakes aren't standardised and the `lib` namespace shouldn't be
polluted with utilities that serve only experimental uses.
2022-05-15 22:39:46 +12:00
Robert Hensing
81a0a8be29 lib/tests/modules: Test functionTo submodule merging too 2022-05-13 09:09:16 +02:00
Robert Hensing
06da97fc3a lib.types.functionTo: Support type merging 2022-05-13 09:01:05 +02:00
Naïm Favier
4d2ea62d82
lib/strings/toShellVars: handle derivations as strings 2022-05-07 17:01:51 +02:00
Robert Hensing
9252a7daa8 lib/tests/modules.sh: Fix for singular type descriptions 2022-05-02 10:41:47 +02:00
Robert Hensing
761c21a16a
Merge pull request #170090 from danth/has-infix-toString
lib/strings: call toString within hasInfix
2022-05-02 09:47:15 +02:00
Daniel Thwaites
7b5be1a0f8 lib/tests: add tests for hasInfix
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2022-05-02 09:05:56 +02:00
Artturi
a5357d06e4
Merge pull request #167947 from MatthewCroughan/mc/callLocklessFlake
lib: add callLocklessFlake
2022-05-01 23:06:17 +03:00
Alyssa Ross
2a6288d9b9 lib.systems: add riscv{32,64} sets and filters
For other platforms like Intel and ARM, we can do
e.g. lib.platforms.aarch64 to get only the 64-bit ARM platorms, but
until now there were no equivalents for RISC-V.
2022-04-28 08:17:02 +00:00
Alyssa Ross
ed24c902d0 lib/tests: add RISC-V test 2022-04-28 08:17:02 +00:00
Naïm Favier
226bc99659
lib/strings: add toShellVars
A straightforward piece of plumbing to safely inject Nix variables into
shell scripts:

''
  ${lib.toShellVars { inherit foo bar; }}
  cmd "$foo" --bar "$bar"
''
2022-04-27 16:04:17 +02:00
Robert Hensing
224426ba6d lib.types.submoduleWith: Avoid _key collisions after extendModules 2022-04-24 00:07:59 +02:00
matthewcroughan
3f128cc024 lib/tests: evaluate value from subflake with callLocklessFlake 2022-04-12 21:22:36 +01:00
matthewcroughan
ec59145c3b lib/tests: use subflake to test callLocklessFlake 2022-04-12 20:38:55 +01:00
matthewcroughan
cc052779fb lib/tests: add test for callLocklessFlake 2022-04-12 19:47:48 +01:00
Maximilian Bosch
7203788068
lib/generators: withRecursion: don't break attr-sets with special attrs
Closes #168327

The issue reported there can be demonstrated with the following
expression:

    → nix-instantiate --eval -E "with import ./. {}; pkgs.lib.options.showDefs [ { file = \"foo\"; value = pkgs.rust.packages.stable.buildRustPackages; } ]"
    error: attempt to call something which is not a function but a string

           at /home/ma27/Projects/nixpkgs/lib/trivial.nix:442:35:

              441|   isFunction = f: builtins.isFunction f ||
              442|     (f ? __functor && isFunction (f.__functor f));
                 |                                   ^
              443|

Basically, if a `__functor` is in an attribute-set at depth-limit,
`__functor` will be set to `"<unevaluated>"`. This however breaks
`lib.isFunction` which checks for a `__functor` by invoking `__functor`
with `f` itself.

The same issue - "magic" attributes being shadowed by `withRecursion` -
also applies to others such as
`__pretty`/`__functionArgs`/`__toString`.

Since these attributes have a low-risk of causing a stack overflow
(because these are flat attr-sets or even functions), ignoring them in
`withRecursion` seems like a valid solution.
2022-04-12 12:34:23 +02:00
Silvan Mosberger
180173a1c4
Merge pull request #164088 from Profpatsch/lib.generators-add-toINIWithGlobalSection
lib.generators: add toINIWithGlobalSection
2022-04-06 19:02:36 +02:00
Robert Hensing
c705953267
Merge pull request #165540 from Infinisil/module-args-docs
lib/modules: Document `_module.args`
2022-04-05 21:51:46 +02:00
Robert Hensing
559ac3c9e7
Merge pull request #166383 from hercules-ci/always-sanitize-derivation-name
Always sanitize derivation name
2022-04-05 20:05:33 +02:00
Silvan Mosberger
25de2935ef lib/modules: Document _module.args
Documents the _module.args option, motivated by many usages in Flakes,
especially with the deprecation of extraArgs
(78ada83361)

The documentation rendering for this option had to be handled a bit
specially, since it's not declared in nixos/modules like all the other
NixOS options.

Co-Authored-By: pennae <github@quasiparticle.net>
Co-Authored-By: Robert Hensing <robert@roberthensing.nl>
2022-04-05 18:26:40 +02:00
Silvan Mosberger
f8c1aee5da lib/tests: Add tests for levenshtein functions 2022-04-01 22:03:05 +02:00
Robert Hensing
2999ab114e lib.sanitizeDerivationName: Test with unicode 2022-03-31 18:31:11 +02:00
Robert Hensing
5ff918bf55
Merge pull request #147077 from Infinisil/updateAttrPaths
Introduce `lib.updateManyAttrsByPath`
2022-03-19 19:00:03 +01:00
Silvan Mosberger
85003ecdbb lib.attrsets: Introduce updateManyAttrsByPath 2022-03-18 00:08:29 +01:00
Silvan Mosberger
1ad7812c4a lib.lists: Use builtins.groupBy for lib.groupBy
builtins.groupBy is much more performant. It was introduced in
https://github.com/NixOS/nix/pull/5715
2022-03-18 00:05:10 +01:00
Silvan Mosberger
71b130c581 lib.attrsets: Introduce showAttrPath 2022-03-18 00:05:08 +01:00
John Ericson
111839dcf6
Merge pull request #161158 from a-m-joseph/mips64el-support-first-steps
mips64el support
2022-03-17 17:43:24 -04:00
Silvan Mosberger
b97742c66c
Merge pull request #156533 from hercules-ci/issue-146882-transparent-submodule-options
lib.modules: Let module declare options directly in bare submodule
2022-03-16 21:44:35 +01:00
Profpatsch
ab03ddc8f4 lib.generators: add toINIWithGlobalSection
As discussed in
https://github.com/NixOS/nixpkgs/pull/118925#issuecomment-821112723,
this is the best way of adding global sections to `toINI` without
employing heuristics (i.e. checking whether something is an attrset).
2022-03-14 10:21:15 +01:00
Adam Joseph
12371a51e6 lib/systems: add mips64el definitions
MIPS has a large space of {architecture,abi,endianness}; this commit
adds all of them to lib/systems/platforms.nix so we can be done with
it.

Currently lib/systems/inspect.nix has a single "isMips" predicate,
which is a bit ambiguous now that we will have both mips32 and mips64
support, with the latter having two ABIs.  Let's add four new
predicates (isMips32, isMips64, isMips64n32, and isMips64n64) and
treat the now-ambiguous isMips as deprecated in favor of the
more-specific predicates.  These predicates are used mainly for
enabling/disabling target-specific workarounds, and it is extremely
rare that a platform-specific workaround is needed, and both mips32
and mips64 need exactly the same workaround.

The separate predicates (isMips64n32 and isMips64n64) for ABI
distinctions are, unfortunately, useful.  Boost's user-scheduled
threading (used by nix) does does not currently supports mips64n32,
which is a very desirable ABI on routers since they rarely have
more than 2**32 bytes of DRAM.
2022-03-10 20:30:16 -08:00
Robert Hensing
55ee7ab4a6 lib.types.optionType: Only merge when necessary 2022-03-10 20:25:49 +01:00
Robert Hensing
c90844aeb9 lib/tests/modules: Add test case for duplicate option error file location 2022-03-07 11:21:23 +01:00
Robert Hensing
8baea8b82c lib.modules: Make option injection work when shorthandOnlyDefinesConfig 2022-03-03 00:29:14 +01:00
Robert Hensing
11537c9c02 lib.modules: Improve option-is-prefix error message 2022-03-03 00:29:11 +01:00
Robert Hensing
d030e2109f lib.modules: Let module declare options directly in bare submodule
... where a bare submodule is an option that has a type like
`submoduleWith x`, as opposed to `attrsOf (submoduleWith x)`.

This makes migration unnecessary when introducing a freeform type
in an existing option tree.

Closes #146882
2022-03-03 00:28:35 +01:00
Silvan Mosberger
023fa7b923 lib.modules: Use types.optionType for _module.freeformType
This ensures that the module file locations are propagated to the
freeform type, which makes it so that submodules in freeform types now
have their declaration location shown in the manual, fixing
https://github.com/NixOS/nixpkgs/issues/132085.

In addition, this also newly allows freeformTypes to be declared
multiple times and all declarations being merged together according to
normal option merging.

This also removes some awkwardness regarding the type of `freeformType`
2022-03-01 19:31:02 +01:00
Silvan Mosberger
5cbeddfde4 lib.types: Introduce types.optionType
This type correctly merges multiple option types together while also
annotating them with file information. In a future commit this will be
used for `_module.freeformType`
2022-03-01 19:31:00 +01:00
Silvan Mosberger
665344f148 lib/types: Introduce types.raw for unprocessed values 2022-02-22 15:54:44 +01:00
Silvan Mosberger
b333395be5 lib/tests: Add tests for emptyValue 2022-02-17 18:48:30 +01:00
zimbatm
22991521eb
lib: fix flake check
`builtins.currentSystem` is not available in pure eval. For this
particular test, we don't really care since it's all about generating
.drv files.

Fixes the following error:

    $ nix flake check
    warning: unknown flake output 'lib'
    error: attribute 'currentSystem' missing

           at /nix/store/8wvnlbjxlr90kq2qa6d9zjpj8rqkilr5-source/lib/tests/misc.nix:499:73:

              498|     let
              499|       deriv = derivation { name = "test"; builder = "/bin/sh"; system = builtins.currentSystem; };
                 |                                                                         ^
              500|     in {
    (use '--show-trace' to show detailed location informat
2021-12-13 12:03:40 +01:00
Silvan Mosberger
ae0b7d6db0
Merge pull request #144022 from hercules-ci/lib-modules-optimize-unmatchedDefns
lib/modules: Short-circuit unmatchedDefns when configs is empty
2021-12-07 19:38:43 +01:00
Victor Engmark
44a15ab801 lib/tests: Use standard test syntax
For consistency.
2021-11-26 11:03:40 +13:00
Victor Engmark
b8f8589e9a lib/tests: Anchor config output regexes
Strengthens the tests by making sure the whole line is matched.
2021-11-26 11:02:41 +13:00
Victor Engmark
989f034ff1 lib/tests: Set hardening pragmas
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-26 10:55:14 +13:00
Victor Engmark
bfc580f54f lib/tests: Don't return non-zero values from checks
The exit codes aren't used for anything.
2021-11-26 10:52:28 +13:00
Victor Engmark
40ae711f73 lib/tests: Avoid assigning an array to a string
As per <https://github.com/koalaman/shellcheck/wiki/SC2124>.
2021-11-26 10:52:27 +13:00
Victor Engmark
04223a0d43 lib/tests: Remove redundant semicolons 2021-11-26 10:51:56 +13:00
Victor Engmark
41fd1d8626 lib/tests: Clarify assignment
The extra equal sign was confusing, and doesn't seem to be relevant.
2021-11-26 10:51:12 +13:00
Victor Engmark
5e85cd86af lib/tests: Use correct shebang line
The script uses plenty of non-POSIX features, such as referencing
`$BASH_SOURCE`.
2021-11-26 10:51:12 +13:00
Victor Engmark
40d1c87bea lib/tests: Quote variable references 2021-11-26 10:51:12 +13:00
Victor Engmark
6d53055cb7 lib/tests: export separately from assignment
Avoids hiding the exit code from the assignment. See
<https://github.com/koalaman/shellcheck/wiki/SC2155>.
2021-11-26 09:30:10 +13:00
Robert Hensing
d464ccfdd9 modules: Add moduleType to module arguments 2021-11-22 16:50:50 +01:00
Bernardo Meurer
90c1cdd93f
lib/tests/sources: update to Nix 2.4 cli syntax 2021-11-09 10:47:20 -08:00
Bernardo Meurer
fd4390146e
lib/tests/modules.sh: update to Nix 2.4 syntax 2021-11-09 10:47:19 -08:00
Robert Hensing
e8d61a25fc lib/tests/modules: Test non-strictness some more
Doesn't seem to have been a problem actually, but now it won't
regress.
2021-11-03 19:19:41 +01:00
Robert Hensing
dece37b83a lib.evalModules: Add extendModules and type to result
Allows the simultaneous construction of top-level invocations and
submodule types.

This helps structure configuration systems integration code.
2021-11-01 09:34:07 +01:00
Silvan Mosberger
d193e632bc
Merge pull request #140284 from Infinisil/types-anything-lambdas
lib/types: Make types.anything merge functions
2021-10-05 13:50:42 +02:00
Michele Guerini Rocco
dd7cbf0c59
Merge pull request #140136 from rnhmjoj/matrix-ids
maintainers/maintainers-list: add Matrix IDs
2021-10-03 23:40:49 +02:00
Robert Helgesson
e75f346aa3
lib: add function escapeXML
Given a string, this function returns a string that can be inserted
verbatim in an XML document.
2021-10-03 11:28:03 +02:00
Silvan Mosberger
48293bd6b6 lib/types: Make types.anything merge functions
Previously it would give an error if there were multiple function
definitions.
2021-10-02 16:37:22 +02:00
rnhmjoj
35841653e1
lib/tests/maintainers: add matrix option 2021-10-01 21:27:00 +02:00
Linus Heckemann
a3df3d05e5
Merge pull request #131205 from Ma27/showdefs-overflow
lib/modules: improve errors for `options`/`config`-mixups
2021-09-29 11:03:31 +02:00
Sergei Trofimovich
34e468dc42 lib/systems: add minimal s390x-linux cross-compile support
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-09-09 10:58:47 +00:00
Maximilian Bosch
5773ae93f7
lib/generators: move limit detection into withRecursion
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-26 00:28:49 +02:00
Maximilian Bosch
55ea29fd8c
lib/generators/toPretty: add evaluation-limit
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-25 23:18:26 +02:00
Robert Hensing
fbafeb7ad5 treewide: runCommandNoCC -> runCommand
This has been synonymous for ~5y.
2021-08-15 17:36:41 +02:00
Silvan Mosberger
f0fda3bf55
Merge pull request #131267 from blaggacao/fix-functionArgs
lib: fix functionArgs for functors
2021-08-04 00:02:57 +02:00
David Arnold
cf8e219b7e
lib: fix functionArgs for functors
`functionArgs` should give valid results on
functions that have been identified with `lib.isFunction`
instead of erroring out.
2021-08-03 16:40:58 -05:00
Alyssa Ross
3669b12f35 lib.systems: add m68k-netbsd support
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-08-01 15:27:12 +00:00
Ben Siraphob
0f1204bd2b Initial implementation of s390 cross-compile 2021-07-25 10:12:18 +07:00
Ben Siraphob
407953e9df Initial implementation of m68k cross-compile 2021-07-24 14:37:35 +07:00
Robert Hensing
d14be76615 lib/tests/sources.sh: init 2021-05-29 14:32:56 +02:00
Robert Hensing
e7412dde1f Revert "lib/tests: Add type deprecation tests"
This reverts commit 8b957e3b30.
2021-05-05 18:53:28 +02:00
Silvan Mosberger
8b957e3b30 lib/tests: Add type deprecation tests 2021-05-03 22:16:06 +02:00
Silvan Mosberger
ce5e3113c3 lib/tests: Make sure the submodule type description can be evaluated
In 2d45a62899, 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-05-03 22:15:33 +02:00
Alyssa Ross
532493b508
lib.systems.doubles.netbsd: expand
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-04-23 22:23:25 +00:00
Maximilian Bosch
e878fc4aac
lib/modules: better error message if an attr-set of options is expected
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-03-11 14:55:56 +01:00
John Ericson
5fc5e83808
Merge pull request #111345 from r-burns/ppc64-big-endian
Enable PPC64 (big-endian)
2021-01-30 16:26:06 -05:00
Ryan Burns
72b3badb61 lib.systems: add powerpc64-linux
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-30 12:34:24 -08:00
Jacek Galowicz
123045a570 lib/attrsets: add cartesianProductOfSets function 2021-01-28 23:08:59 +01:00
Silvan Mosberger
c2f3556dc7
lib/tests: More functionTo tests 2021-01-27 00:17:56 +01:00
Bas van Dijk
43243539b3
lib/tests/modules: add a test for the functionTo type
(cherry picked from commit 478af112e83df806bd8a51174834d2a130fbdeb9)
2021-01-24 16:56:45 +01:00
Silvan Mosberger
9e6737710c Revert "Module-builtin assertions, disabling assertions and submodule assertions" 2020-12-18 16:44:37 +01:00
Silvan Mosberger
767d80099c
lib/modules: Introduce _module.checks.*.check
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-12-17 21:52:24 +01:00
Silvan Mosberger
8dea4df903
lib/modules: Remove _module.checks.*.triggerPath as it's not necessary
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-30 23:51:42 +01:00
Silvan Mosberger
c9cc8969b4
lib/modules: Rename _module.assertions to _module.checks 2020-11-30 23:51:41 +01:00
Silvan Mosberger
3e39d6efdf
lib/tests: Add tests for module-builtin assertions 2020-11-30 23:51:23 +01:00
Silvan Mosberger
900c4a5abd
lib/tests: Implement generalized checkConfigCodeOutErr for module tests 2020-11-30 23:51:23 +01:00
Silvan Mosberger
3759a77fcd
nixos/modules: Expose the internal module in the top-level documentation 2020-11-30 23:51:23 +01:00
John Ericson
86fedc3a92
Merge pull request #102766 from siraben/mmix
Initial implementation of cross-compilation to Knuth's MMIX
2020-11-14 12:46:24 -05:00
Joe Hermaszewski
c3b35f21f7 lib: Add composeManyExtensions 2020-11-13 21:37:57 +01:00
Ben Siraphob
445dde6304 Initial implementation of mmix cross-compile 2020-11-09 19:49:55 +07:00
Etienne Laurin
d7464ab4bb lib.splitString: use builtin.split 2020-10-18 13:19:50 +00:00
Silvan Mosberger
8908766165
lib/tests: Update for error message changes 2020-09-21 18:24:55 +02:00
Silvan Mosberger
4f0982b223
lib/tests: Allow grepping for newlines in error messages 2020-09-21 18:24:54 +02:00
Silvan Mosberger
366a677dbb
Merge pull request #97133 from Infinisil/improved-toPretty
Improve `generators.toPretty`
2020-09-21 17:11:49 +02:00
Robert Hensing
f3893d8b53
Merge pull request #97119 from Infinisil/types.anything
Introduce `types.anything`
2020-09-21 08:49:24 +02:00
Silvan Mosberger
05e4d371ef
lib/generators.toPretty: Print [] and {} compactly 2020-09-17 18:20:39 +02:00
Silvan Mosberger
d0be9e9810
lib/generators.toPretty: Switch away from δ and λ
- These symbols can be confusing for those not familiar with them
- There's no harm in making these more obvious
- Terminals may not print them correctly either

Also changes the function argument printing slightly to be more obvious
2020-09-17 18:20:35 +02:00
Silvan Mosberger
073e9b2aed
lib/generators.toPretty: Improved string printing, handling newlines 2020-09-17 18:20:31 +02:00
Silvan Mosberger
47f2eb89c1
lib/generators.toPretty: Implement multiline printing 2020-09-17 18:20:25 +02:00
Silvan Mosberger
0f6231702f
lib/generators.toPretty: Only quote attribute names if necessary 2020-09-17 18:20:08 +02:00
Silvan Mosberger
6a7d250007
lib/tests: Add tests for types.anything 2020-09-15 21:06:05 +02:00
Silvan Mosberger
f320dbae41
lib/tests: Add test for freeform option docs 2020-09-04 15:50:13 +02:00
Eelco Dolstra
2d50c7c08e
Don't set $NIX_DB_DIR
This variable was removed in 2016.
2020-08-24 18:50:20 +02:00
Robert Hensing
6d0a85fe52
Merge pull request #82743 from Infinisil/partially-typed-v2
Freeform modules
2020-08-15 12:13:58 +02:00
Silvan Mosberger
42cf8130d7
lib/modules: Add syntactic sugar for config._module.freeformType
This introduces `freeformType` as a top-level module attribute, allowing
definitions like

  {
    freeformType = ...;
    options = ...;
    config = ...;
  }
2020-08-14 22:49:04 +02:00
Silvan Mosberger
e0ded8f4ba
lib/modules: Fix freeform modules when there's no definitions 2020-08-10 17:27:33 +02:00
Emery Hemingway
ccedb29f4b Define a i686-genode system double 2020-08-04 18:08:56 +02:00
Silvan Mosberger
446d80d28d
lib/tests: Add tests for freeform modules 2020-08-03 22:37:01 +02:00
zowoq
c8500de47b lib/*: editorconfig fixes 2020-07-31 15:07:33 +10:00
John Ericson
5c56778efd
Merge pull request #93568 from aaronjanse/aj-redox
Add Redox OS as a target
2020-07-22 12:56:00 -04:00
Aaron Janse
60fd049b65 redox: add as target 2020-07-21 13:11:36 -07:00
Bas van Dijk
6e7822b8f3 lib: toHex -> toHexString & toBase -> toBaseDigits
This makes the type of these functions more apparent from the name.
2020-07-20 13:14:19 +02:00
Bas van Dijk
00022fbeda lib: add the toHex and toBase utility functions
`toHex` converts the given positive integer to a string of the hexadecimal
representation of that integer. For example:

```
toHex 0 => "0"

toHex 16 => "10"

toHex 250 => "FA"
```

`toBase base i` converts the positive integer `i` to a list of it
digits in the given `base`. For example:

```
toBase 10 123 => [ 1 2 3 ]

toBase 2 6 => [ 1 1 0 ]

toBase 16 250 => [ 15 10 ]
```
2020-07-20 13:09:26 +02:00
Silvan Mosberger
a89b773984
lib/tests: Allow overriding pkgs independent of lib being tested 2020-04-25 23:40:20 +02:00
Silvan Mosberger
f579564062
lib/maintainer-list: Implement validity checks 2020-04-13 17:28:00 +02:00
Silvan Mosberger
a90d8de242
lib/tests/release.nix: Avoid importing nixpkgs into the store
Improves build time by about a factor of two on my system
2020-04-13 17:27:05 +02:00
Silvan Mosberger
0bc7f3440a
lib/tests/modules.sh: Don't depend on $PWD 2020-04-13 17:27:04 +02:00
Silvan Mosberger
f75c11cfdf
Merge pull request #83241 from Infinisil/valid-drv-name
lib/strings: Add `sanitizeDerivationName` function
2020-04-02 05:58:13 +02:00
Silvan Mosberger
4b206ac83b
lib/strings: Add sanitizeDerivationName function 2020-03-30 01:15:30 +02:00
Emery Hemingway
9f91fa02a6 lib/systems: Add Genode platform definitions
Add platform definitions for 64-bit ARM and x86. This is sufficient for
for building Genode where a toolchain is provided as an overlay.

Toolchain: git+https://git.sr.ht/~ehmry/genodepkgs?rev=14fc773ac9ecd2cbb30cb4612b284eee83d83546
2020-03-24 20:41:21 +05:30
John Ericson
19a0b38cbe
Merge pull request #82882 from obsidiansystems/armv6-embedded
Misc fixes for armv6 bare metal cross
2020-03-19 10:38:22 -04:00
Silvan Mosberger
742e3fc002
lib/tests: Check for nested option-dependent definitions 2020-03-19 03:50:47 +01:00
Silvan Mosberger
9eecf2d057
Revert "lib/modules: Throw better error when definitions assign to an option set"
This reverts commit 15c873b486.

This was causing infinite recursion when depending on nested options
2020-03-19 03:50:15 +01:00
John Ericson
7c0d3f6f70 lib: Fix systems test for new armv6l-none 2020-03-18 17:43:11 -04:00
Robert Hensing
5f357b20b3
Merge pull request #82751 from Infinisil/minor-module-improvements
Minor module improvements
2020-03-18 10:06:06 +01:00
Silvan Mosberger
e931de58a2
lib/modules: Fix type checks not being done before merging
Co-Authored-By: Robert Hensing <robert@roberthensing.nl>
2020-03-18 04:38:53 +01:00
Silvan Mosberger
15c873b486
lib/modules: Throw better error when definitions assign to an option set 2020-03-18 04:38:50 +01:00
Robert Hensing
31206e44e1 lib/modules: Test the ability for config to depend on options for compatibility 2020-03-17 20:21:10 +01:00
Silvan Mosberger
575354babf
lib/generators: Add toINI option for duplicate keys 2020-03-10 16:01:04 +01:00
Eelco Dolstra
5c389f84d4 lib/tests/misc.nix: Don't make a copy on Nixpkgs 2020-02-10 16:21:04 +01:00
Eelco Dolstra
a274da605d lib/tests/misc.nix: Fix dependency on currentSystem
This doesn't work in pure mode.
2020-02-10 16:20:41 +01:00
Profpatsch
b2654c226a lib/cli,lib/tests/misc: somewhat more standard formatting 2020-01-23 14:47:38 +01:00
Profpatsch
582354d3b6 lib/cli: encodeGNUCommandLine -> toGNUCommandLineShell
The semantic difference between `encode` and `to` is not apparent.
Users are likely to confuse both functions (which leads to unexpected
error messages about the wrong types). Like in `generators.nix`, all
functions should be prefixed by `to`.

Furthermore, converting to a string depends on the target context. In
this case, it’s a POSIX shell, so we should name it that (compare
`escapeShellArg` in `strings.nix`).

We can later add versions that escape for embedding in e.g. python
scripts or similar.
2020-01-23 14:47:38 +01:00
Robert Hensing
8da81465c1
Merge pull request #75539 from Gabriel439/gabriel/renderOptions
Add `pkgs.lib.encodeGNUCommandLine`
2020-01-14 12:04:05 +01:00
Robert Hensing
9884cb3ed0
Merge pull request #76861 from Infinisil/paths-as-submodules
lib/types: Allow paths as submodule values
2020-01-12 14:19:04 +01:00
Silvan Mosberger
ab10e87414
lib/tests: Add tests for attrsOf and lazyAttrsOf 2020-01-10 16:20:31 +01:00
Silvan Mosberger
092107cdc1
lib/tests: Fix module tests
Fix the broken test in https://github.com/NixOS/nixpkgs/pull/77416

Apparently hydra uses `nix-build lib/tests/release.nix` to run all
tests, where IFD isn't allowed. Fortunately we can get around this with
builtins.toFile, which doesn't require IFD, but still can test the
properties we want.
2020-01-10 16:02:36 +01:00
Silvan Mosberger
2955e6bd26
lib/tests: Add test case for imports from derivations 2020-01-10 04:13:28 +01:00
Silvan Mosberger
e9c16ec186
Merge pull request #76857 from Infinisil/recursive-disableModules
Apply `disabledModules` recursively
2020-01-09 18:20:12 +01:00
Silvan Mosberger
b89b23b6b2
lib/tests: Add tests for recursive disabledModules 2020-01-09 17:26:08 +01:00
Silvan Mosberger
6525da6321
lib/types: Allow paths as submodule values 2020-01-08 23:54:45 +01:00
rnhmjoj
cde46494c6 lib/tests: remove strictly loaOf tests and rebase on attrsOf 2020-01-06 10:39:19 -05:00
Gabriel Gonzalez
6d584c2614 Factor out a toGNUCommandLine utility
... as suggested by @roberth
2020-01-05 13:03:00 -08:00
Silvan Mosberger
be3f887ac4
lib/tests: Temporarily disable submodule path test
Until https://github.com/NixOS/nixpkgs/pull/76861 or so is merged
2020-01-03 06:02:55 +01:00
Silvan Mosberger
cdf79db19d
Module system improvements for NixOS as a submodule (#75031)
Module system improvements for NixOS as a submodule
2020-01-02 20:38:45 +01:00
Silvan Mosberger
cc81320a46
lib/tests: Add submoduleWith tests 2020-01-02 09:59:35 +01:00
Gabriel Gonzalez
5edd4dd44c Use a more realistic example that exercises all encodings
... as suggested by @roberth

This also caught a bug in rendering lists, which this change also fixes
2019-12-15 08:21:41 -08:00