Commit Graph

3150 Commits

Author SHA1 Message Date
Robert Hensing
f771d39750
Merge pull request #171946 from ncfavier/toShellVars-derivations
lib/strings/toShellVars: handle derivations as strings
2022-05-12 14:43:48 +02:00
Fabian Affolter
b544d177a2 lib.licenses: add DRL-1.0
https://spdx.org/licenses/DRL-1.0.html
https://github.com/SigmaHQ/sigma/blob/master/LICENSE.Detection.Rules.md
2022-05-10 11:11:40 +02:00
Robert Hensing
4d2237c841 lib.foldAttrs: Clarify example 2022-05-10 07:01:00 +02:00
Naïm Favier
4d2ea62d82
lib/strings/toShellVars: handle derivations as strings 2022-05-07 17:01:51 +02:00
matthewcroughan
4d9801a78f lib: add inPureEvalMode
This makes a value that is true if builtins does not contain the
currentSystem function, but false if it does.
2022-05-06 15:42:52 +01:00
Rick van Schijndel
b9e8ed239f
Merge pull request #161156 from a-m-joseph/abort-on-failed-platform-detection-instead-of-silently-assuming-pc
platforms.nix: use {} on failed detection instead of silently assuming pc
2022-05-04 05:37:16 +02:00
Adam Joseph
006c38fa53 platforms.nix: use {} on failed detection instead of silently assuming pc
This patch causes the autodetection code in lib/systems/platforms.nix
to return {} if it cannot detect the platform and one of the
platform.nix-detection-provided attributes (linux-kernel, gcc, and
rustc) are accessed, rather than silently assuming the "pc" platform
as was previously done.

It is definitely safe to assume that code using these attributes is
prepared to deal with `gcc` and `rustc` not being defined, because
many of the working entries in this file don't define it.

Regarding `linux-kernel` the situation is less certain, but some code
(`lib/systems/default.nix` for example) is already designed to deal
with that attribute being missing.  At worst it would result in an
"attribute not found" error.

While adding mips64el bootstrap support to nixpkgs, the silent
assumption that mips64el routers are actually Intel PCs caused
significant frustration.  This commit removes that assumption in order
to save people who port nixpkgs to new platforms in the future from
this frustration.
2022-05-03 13:31:41 -07: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
Daniel Thwaites
e888c2133f
lib/strings: convert to string within hasInfix
This should fix the issue mentioned here:
https://github.com/NixOS/nixpkgs/pull/168175#issuecomment-1107830574
2022-05-01 17:39:42 +01:00
Robert Hensing
c2451ed1a2
Merge pull request #167776 from hercules-ci/lib-modules-allow-disable-_modules.args-docs-internal
lib.modules: Allow making _module.args internal
2022-04-30 13:43:08 +02:00
Adam Joseph
4d46ee8691 platforms.nix: use inherit syntax 2022-04-28 03:52:15 -07: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
Adam Joseph
eabc6d2902 lib/systems/platforms.nix: fix broken mips32 detection
Prior to this commit, nixpkgs would assume that every little-endian
mips32 system was a "fuloong2f_n32".

Not only are there plenty of mips32 chips other than the fuloong, but
the fuloong is actually a mips64 chip!  Note that the "n32" ABI is
(confusingly) an ABI for 64-bit mips chips (like the "x32" ABI for
amd64 chips -- both are ABIs which use 32-bit pointers on an
otherwise-64-bit system).

This error causes far-ranging problems.  One of them was particularly
difficult to track down: it caused GCC to select 128-bit `long double`
types, which is invalid for the mips32 ABI.  This isn't noticed until
you try to build musl-libc, which is careful to check for these things.

Prior to this commit,

  nix-build . -A pkgsCross.mipsel-linux-gnu.pkgsStatic.hello

would fail.  With this commit and #170736, it succeeds.
2022-04-27 23:49:09 -07:00
Adam Joseph
3e60871330 lib/systems/platforms.nix: use "32" instead of "o32" for mips32 ABI
There is only one ABI for 32-bit MIPS chips.  Before mips64, it didn't
really have a name.

The 64-bit MIPS ABI comes in two flavors, "n64" and "n32".  It is
commonplace to refer to the old 32-bit ABI as "o32" (MIPS and SGI
documents do this).

However, when configuring gcc, one must use --with-abi=32, not
--with-abi=o32.

Let's keep GCC happy with this commit.
2022-04-27 23:46:02 -07:00
Robert Hensing
5f8cb21011
Merge pull request #170583 from ncfavier/mkShellVars
lib/strings: add toShellVars
2022-04-27 23:33:28 +02:00
Naïm Camille Favier
535997fa52
lib/strings: fix quoting of example
Co-authored-by: Silvan Mosberger <github@infinisil.com>
2022-04-27 19:42:40 +02: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
Klemens Nanni
7bec3e60ef lib/types: Drop misleading plural from type descriptions #170561
Probably being the most prominent document demonstrating the problem,
configuration.nix(5) describes various types in plural, e.g.
- `           Type: list of strings`
- `           Type: list of systemd options`

However, there are other cases where appending "s" to the inner type
effectively changes the type, e.g.
- ```
           Type: list of string matching the pattern
           [a-zA-Z0-9@%:_.\-]+[.](service|socket|device|mount|automount|swap|target|path|timer|scope|slice)s
```

This should've read "list of string[s]..." but instead changes the
regular expression.

Simply drop the best-effort plural in favour of correctness and
simplicity rather than adding more grammar related logic/trying to fix
this.
2022-04-27 05:59:46 +02:00
Artturi
c95f5e185e
Merge pull request #167247 from Artturin/addgetmainprog
lib/meta: add getExe to get the main program of a drv
2022-04-26 21:42:23 +03:00
Robert Hensing
27a62a9c60
Merge pull request #168778 from hercules-ci/issue-168767-extendModules-module-dedup-collision
`lib.types.submoduleWith`: Avoid `_key` collisions after `extendModules` (issue #168767)
2022-04-26 13:01:28 +02:00
Sandro
294ed1bed7
Merge pull request #168111 from a-m-joseph/lib-systems-inspect-powerpc
lib/systems/inspect.nix: add isPower64
2022-04-25 02:22:48 +02:00
Artturin
379b9c8be3 lib/meta: add getExe to get the main program of a drv 2022-04-24 04:19:49 +03:00
Robert Hensing
224426ba6d lib.types.submoduleWith: Avoid _key collisions after extendModules 2022-04-24 00:07:59 +02:00
Daniel Thwaites
4f9b8a0702
lib/strings: optimise hasInfix function (#168175)
* lib/strings: optimise hasInfix function

* lib/strings: optimise hasInfix further using regex

* rstudio: call hasInfix with a string

* lib/strings: remove let from hasInfix

Co-authored-by: pennae <82953136+pennae@users.noreply.github.com>

Co-authored-by: pennae <82953136+pennae@users.noreply.github.com>
2022-04-22 12:43:25 -04:00
Artturin
4aab12d5a1 lib/systems/platforms: correctly import examples.nix
before: :p lib.systems failed with
error: getting status of '...examples': no such file or directory
2022-04-15 20:25:58 +03: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
matthewcroughan
cad8bbe589 lib: init flakes.nix
This commit creates flakes.nix, which is a library containing functions
which relate to interacting with flakes. It also moves related functions
from trivial.nix into it.
2022-04-12 19:28:23 +01:00
matthewcroughan
c190b08bb7 lib: add callLocklessFlake
This is essentially a copy of the function of the same name, from
flake-compat. callLocklessFlake is useful when trying to utilise a
flake.nix without a lock file, often for when you want to create a
subflake from within a parent flake.

Co-authored-by: Tom Bereknyei <tomberek@gmail.com>
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2022-04-12 19:27:24 +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
Robert Hensing
14aa201b65 lib.modules: Allow making _module.args internal
This allows other module system consumers to
disable these docs via option merging.

For instance arion uses asciidoc instead of
docbook so that would look awful.
2022-04-11 11:17:34 +02:00
Adam Joseph
81afd541f9 lib/systems/inspect.nix: add isPower64
This commit adds an `isPower64` predicate to the two existing
predicates for this architecture (`isPower` and `isPowerPC`).

Note that `isPowerPC` matches only 32-bit machines, whereas `isPower`
matches both 64-bit and 32-bit machines.  Prior to this commit there
was no single `isXXX` predicate for `powerpc64le`.
2022-04-10 01:56:28 -07: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
Robert Hensing
fffabe7500 lib.sanitizeDerivationName: Simplify regex
`^` and `$` are implicit in `match`.
2022-04-05 19:14:09 +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
1c00bf3948 lib/customization: Improve callPackage error message for missing args
This uses the levenshtein distance to look through all possible
arguments to find ones that are close to what was requested:

  error: Function in /home/infinisil/src/nixpkgs/pkgs/tools/text/ripgrep/default.nix
    called without required argument "fetchFromGithub",
    did you mean "fetchFromGitHub" or "fetchFromGitLab"?

With https://github.com/NixOS/nix/pull/3468 (in current nixUnstable) the error
message becomes even better, adding line location info
2022-04-01 22:03:05 +02:00
Silvan Mosberger
f8c1aee5da lib/tests: Add tests for levenshtein functions 2022-04-01 22:03:05 +02:00
Silvan Mosberger
975a1ae339 lib/strings: Add levenshtein distance functions
Adds some functions related to string similarity:
- lib.strings.commonPrefixLength
- lib.strings.commonSuffixLength
- lib.strings.levenshtein
- lib.strings.levenshteinAtMost
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
342a3c32c9 lib.sanitizeDerivationName: Optimize the common case 2022-03-31 18:31:11 +02:00
github-actions[bot]
03106b0236
Merge master into haskell-updates 2022-03-29 00:12:40 +00:00
Robert Hensing
9dd71d8c50
Merge pull request #165956 from ncfavier/lib-warn-throw
lib/trivial: actually expose warnIfNot and throwIf
2022-03-28 14:07:53 +02:00
github-actions[bot]
f0839d8bcd
Merge master into haskell-updates 2022-03-28 00:11:42 +00:00
Naïm Favier
9f5796be49
lib/trivial: actually expose warnIfNot and throwIf 2022-03-27 16:48:33 +02:00
Sandro
ac5ea36581
Merge pull request #165672 from yoctocell/patatt-init 2022-03-27 14:53:39 +02:00
Sandro
3cc111d919
Merge pull request #165597 from ckiee/generaluser-init 2022-03-27 12:54:25 +02:00
sternenseemann
372d0a707e Merge remote-tracking branch 'origin/master' into haskell-updates 2022-03-26 09:59:28 +01:00
Silvan Mosberger
99d9d45630
Merge pull request #164651 from Infinisil/remove-optionSet
lib/modules: Finally remove deprecated types.optionSet
2022-03-25 17:41:57 +01:00
github-actions[bot]
79b7796557
Merge master into haskell-updates 2022-03-25 00:11:06 +00:00
Xinglu Chen
e13494d071
lib.licenses: add MIT-0
<https://spdx.org/licenses/MIT-0.html>
2022-03-24 18:49:26 +01:00
Robert Hensing
ce5a33e62b
Merge pull request #164660 from ncfavier/tests-restrict-arguments
nixos/testing: restrict arguments to makeTest
2022-03-24 17:01:47 +01:00
ckie
2bc1cd1ac4
soundfont-generaluser: init at 1.471 2022-03-24 12:49:38 +02:00
github-actions[bot]
b86264453e
Merge master into haskell-updates 2022-03-23 00:11:32 +00:00
Silvan Mosberger
a38220e61d
Merge pull request #164890 from ncfavier/lib-warn-throw
lib/trivial: add warnIfNot and throwIf
2022-03-22 21:12:11 +01:00
github-actions[bot]
cf3e30f70f
Merge master into haskell-updates 2022-03-22 00:12:28 +00:00
Robert Hensing
6c469679f6 Merge remote-tracking branch 'upstream/master' into tests-restrict-arguments 2022-03-21 23:17:17 +01:00
Robert Hensing
84274cbc95 lib: Add toFunction 2022-03-21 23:14:10 +01:00
Robert Hensing
6a0b24b276 lib: applyIfFunction -> applyModuleArgsIfFunction 2022-03-21 23:14:10 +01:00
Kevin Cox
8ce16fcf62
Merge pull request #163451 from hercules-ci/stop-premature-warnings
Stop premature warnings, including `nix.settings` migration
2022-03-21 10:10:40 -04:00
Robert Hensing
1eb627c4cf lib.mkRenamedOptionModuleWith: Remove warnWhenRead
Let's keep things simple and not poke holes in the
improved migration process.
2022-03-21 14:41:22 +01:00
github-actions[bot]
05517edcd8
Merge master into haskell-updates 2022-03-20 00:11:09 +00:00
Naïm Favier
7fae930a37
lib/trivial: add warnIfNot and throwIf
Negated versions of warnIf and throwIfNot.
2022-03-19 20:40:40 +01:00
Robert Hensing
5ff918bf55
Merge pull request #147077 from Infinisil/updateAttrPaths
Introduce `lib.updateManyAttrsByPath`
2022-03-19 19:00:03 +01:00
Silvan Mosberger
96698efe0c lib/modules: Finally remove deprecated types.optionSet
types.optionSet has been deprecated for almost 10 years now
(0e333688ce)! A removal
was already attempted in 2019
(27982b408e), but it was promptly
reinstantiated since some third-party uses were discovered
(f531ce75e4178c6867cc1d0f7fec96b2d5c3f1cb).

It's finally time to remove it for good :)
2022-03-18 04:51:27 +01:00
github-actions[bot]
d6d71873fc
Merge master into haskell-updates 2022-03-18 00:10:51 +00: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
github-actions[bot]
6863d678bc
Merge master into haskell-updates 2022-03-17 00:10:36 +00:00
Robert Hensing
0395086d0c
Merge pull request #162271 from Infinisil/warn-no-type
Throw an error for options without a type
2022-03-16 22:58:45 +01: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
626ecc7bd7 lib.generators: fix references to test file 2022-03-14 10:30:55 +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
github-actions[bot]
b21a694014
Merge master into haskell-updates 2022-03-12 00:10:12 +00:00
Robert Hensing
679ec68d57
Merge pull request #163127 from hercules-ci/optimize-optionSet-compat
lib/modules.nix: Optimize optionSet legacy compat code
2022-03-11 17:36:16 +01:00
sternenseemann
f5c34205ad Merge remote-tracking branch 'origin/master' into haskell-updates 2022-03-11 16:47:23 +01:00
Robert Hensing
a15fbdb88f
Merge pull request #163443 from ncfavier/fix-types-package
lib.types.package: only call toDerivation when necessary
2022-03-11 11:56:44 +01:00
Naïm Favier
9c2266c031
lib.types.package: only call toDerivation when necessary
The current logic assumes that everything that isn't a derivation is a
store path, but it can also be something that's *coercible* to a store
path, like a flake input.

Unnecessary uses of `lib.toDerivation` result in errors in pure evaluation
mode when `builtins.storePath` is disabled.

Also document what a `package` is.
2022-03-11 11:26:34 +01:00
Adam Joseph
ff69b8c2bf Ericson2314's suggestion here: https://github.com/NixOS/nixpkgs/pull/161158#discussion_r822295406 2022-03-10 20:30:19 -08:00
Adam Joseph
6de935a012 This commit adds only comments to platforms.nix. 2022-03-10 20:30:19 -08:00
Adam Joseph
ed4fa55fc3 comment: explain why gnuabi64 has a rustc.config but gnuabin32 does not. 2022-03-10 20:30:18 -08:00
Adam Joseph
998fd408e0 remove float = "hard" from mips entries 2022-03-10 20:30:18 -08:00
Adam Joseph
e748e1fd18 https://github.com/NixOS/nixpkgs/pull/161158#pullrequestreview-903824553 2022-03-10 20:30:18 -08: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
github-actions[bot]
966cf602cc
Merge master into haskell-updates 2022-03-10 00:10:28 +00:00
sternenseemann
47f837f5e8 haskell.compiler: ghc921 -> ghc922
https://www.haskell.org/ghc/download_ghc_9_2_2.html
2022-03-09 16:42:07 +01:00
Robert Hensing
3ddac7a41a lib.isDerivation: Simplify 2022-03-09 15:48:30 +01:00
Robert Hensing
7377ea57ff lib: Add mkRenamedOptionModuleWith
Adds support for sinceRelease
2022-03-09 14:50:51 +01:00
Levi Wright
752a8c516d
lib/systems: Fix uclibc float-abi being flipped
uclibceabihf and uclibceabi's float hardness was flipped, which causes many headaches
2022-03-07 17:05:51 +00:00
Robert Hensing
c4b38702e5 lib/modules.nix: Add comment about internal shorthand null value 2022-03-07 11:23:24 +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
e162ed8a14 lib/modules.nix: Move comment to the actual legacy code 2022-03-07 11:21:19 +01:00
Robert Hensing
02de37ca07 lib/modules.nix: Optimize optionSet legacy compat code
It's still in the hot path.
2022-03-07 11:07:50 +01:00
Robert Hensing
db08290453 Revert "lib.modules: Remove redundant fixupOptionType in option injection"
This reverts commit 6b077c47ff.

Thanks Infinisil for discovering this problem:

> After a lot of trial and error, trying to prove why fixupOptionType should
> be used here or not, I figured it out: It's needed for the sake of file
> locations in error messages.
2022-03-07 10:59:03 +01:00
Robert Hensing
2050669922 lib.modules: Inline a private function
This should save about four calls per module.
2022-03-03 00:29:15 +01:00
Robert Hensing
28aeae2126 lib.modules: Default shorthandOnlyDefinesConfig to true when null 2022-03-03 00:29:14 +01:00
Robert Hensing
6b077c47ff lib.modules: Remove redundant fixupOptionType in option injection 2022-03-03 00:29:14 +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
81f342d1f3 lib.modules: Explain why options can only be merged into submodules 2022-03-03 00:28:35 +01:00
Robert Hensing
0c09eb343d lib.modules: Refactor option scanning slightly
This scans the options with fewer function calls, improving performance.

It also removes a let Env from the happy flow of the new logic.
2022-03-03 00:28:35 +01:00
Robert Hensing
58a8a48e9d lib.types.submodule: Remove redundant isSubmodule attr 2022-03-03 00:28:35 +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
6bcfd61109
Merge pull request #162283 from Infinisil/functionTo.description
lib/types: Fix functionTo description
2022-03-02 19:42:48 +01:00
Silvan Mosberger
c1dfec2be6
Merge pull request #149689 from Infinisil/types-type
Introduce `types.optionType` and use it for `freeformType`
2022-03-02 18:29:44 +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
fb023114ed lib/types: Fix functionTo description 2022-03-01 02:04:35 +01:00
Janne Heß
0c766a100e lib/options: Throw error for options without a type
Makes all options rendered in the manual throw an error if they don't
have a type specified.

This is a follow-up to #76184

Co-Authored-By: Silvan Mosberger <contact@infinisil.com>
2022-02-28 22:51:41 +01:00
0x4A6F
3362ff0f7b
Merge pull request #157301 from pennae/lib-add-mkPackageOption
lib: add mkPackageOption to default.nix
2022-02-28 20:37:59 +01:00
Silvan Mosberger
ff13cd5d3e lib/modules: Use types.raw for _module.args
Fixes https://github.com/NixOS/nixpkgs/issues/53458, as types.raw
doesn't allow setting multiple values
2022-02-22 15:54:45 +01:00
Silvan Mosberger
665344f148 lib/types: Introduce types.raw for unprocessed values 2022-02-22 15:54:44 +01:00
Vikram Narayanan
229c47beee license: Add Volatility Software License 2022-02-20 13:40:38 -08:00
Silvan Mosberger
b333395be5 lib/tests: Add tests for emptyValue 2022-02-17 18:48:30 +01:00
Silvan Mosberger
382289027f lib/types: Fix emptyValue of listOf and nonEmptyListOf
An empty list is [], not {}!

Also, non-empty lists shouldn't have a default of an empty list!
2022-02-17 18:48:27 +01:00
Renaud
980ed8dd76
Merge pull request #155707 from 06kellyjac/feh
feh: correct license
2022-02-16 13:31:43 +01:00
Jonathan Ringer
12fd8a77e1
Merge remote-tracking branch 'origin/master' into staging-next
Conflicts:
	pkgs/top-level/aliases.nix
2022-02-10 09:21:09 -08:00
John Rinehart
5688e7ff35 fix: typo in lib/attrsets.nix 2022-02-10 01:16:20 +02:00
Jonathan Ringer
46fd0afcb3
Merge remote-tracking branch 'origin/master' into staging-next
Conflicts:
	pkgs/development/python-modules/pysdl2/default.nix
	pkgs/top-level/aliases.nix
2022-02-06 18:36:59 -08:00
Robert Hensing
8403e02a5d
Merge pull request #126769 from ncfavier/nixosSystem-lib
nixos: move default module location logic to `eval-config.nix`
2022-02-06 22:49:17 +01:00
Jonathan Ringer
e680c83323
Merge remote-tracking branch 'origin/master' into staging-next
Conflicts:
	pkgs/tools/graphics/scrot/default.nix
2022-02-06 10:36:30 -08:00
Jan Tojnar
1e1396aafc lib.sources: Improve docs
Change comment type so than nixdoc picks them up into Nixpkgs manual.
Also improve phrasing a bit and move stuff around so that it is formatted better.
2022-01-30 02:04:51 +01:00
Jan Tojnar
2f012d93ed lib.trivial: Change comment type before concat function
C-style comment was being picked up by nixdoc as a documentation comment for the function.
2022-01-30 02:02:09 +01:00
pennae
1c0918d828 lib: add mkPackageOption to default.nix
this was forgotten in #155669
2022-01-29 18:28:20 +01:00
06kellyjac
e98d8f7207 feh: correct license 2022-01-28 14:23:25 +00:00
Naïm Favier
5a07097772
lib/modules: introduce setDefaultModuleLocation
Wraps a module with a default location for reporting errors.
2022-01-27 22:12:53 +01:00
Dmitry Kalinkin
0693fd77f7
Merge branch 'staging-next' into staging
Conflicts:
	nixos/doc/manual/from_md/release-notes/rl-2205.section.xml
	nixos/doc/manual/release-notes/rl-2205.section.md
	pkgs/development/python-modules/aioesphomeapi/default.nix
	pkgs/development/python-modules/mat2/default.nix
	pkgs/development/python-modules/pydevccu/default.nix
	pkgs/development/python-modules/pywlroots/default.nix
	pkgs/development/python-modules/rokuecp/default.nix
2022-01-27 00:54:10 -05:00
Robert Hensing
8919495cac
Merge pull request #156503 from hercules-ci/nixos-add-system.build-options
nixos: Add `system.build.`{`toplevel`,`installBootLoader`}, improve error message
2022-01-25 14:13:24 +01:00
Jonathan Ringer
e379e3d4bb
Merge remote-tracking branch 'origin/staging-next' into staging
Conflicts:
	pkgs/development/python-modules/googleapis-common-protos/default.nix
2022-01-24 23:49:19 -08:00
Thiago Kenji Okada
f0e9f54d6e lib/meta: fix typo in platformMatch comment 2022-01-24 12:54:22 -03:00
Alyssa Ross
1a60dd2adc
Merge remote-tracking branch 'nixpkgs/staging-next' into staging
Conflicts:
	pkgs/development/python-modules/cupy/default.nix
	pkgs/development/python-modules/staticjinja/default.nix
2022-01-24 15:39:34 +00:00
Robert Hensing
8691ab3d47 lib.modules: Define mergeOneOption in terms of mergeUniqueOption 2022-01-24 16:23:18 +01:00
Robert Hensing
ba3e91ed43 lib.types: Add unique like uniq, but custom errors
Couldn't extend types.uniq and it had a silly name anyway.
Now we can have better error messages.
2022-01-24 16:14:55 +01:00
pennae
865a9ed3f5
Merge pull request #155669 from schuelermine/patch-mkPackageOption
lib/options: Add mkPackageOption
2022-01-24 13:35:32 +00:00
Martin Weinelt
6d2ded1012
Merge pull request #156215 from Atemu/update/svt-av1 2022-01-24 01:30:16 +01:00
Anselm Schüler
c008b3d100 nixos/docs/option-declarations: Document mkEnableOption and mkPackageOption
This is a squashed commit. These are the original commit messages:

lib/option: Improve comment

better comment

Update documentation

Updated nixos/doc/manual/development/options-declarations.md with info on mkEnableOption and mkPackageOption.
Updated the comment on mkEnableOption in lib/options.nix

remove trailing whitespace

nixos/doc/option-declarations: Update IDs & formatting

nixos/docs/option-declarations: Escape angle brackets

Build DB from MD

(Amended) Fix typo
Co-authored-by: pennae <82953136+pennae@users.noreply.github.com>

(Amended) Build DB from MD (again)
2022-01-23 19:44:21 +01:00
c0bw3b
f4d82e40e8 lib.licenses: add MIT-advertising 2022-01-23 18:06:50 +01:00
Anselm Schüler
fdf7ede344 lib/options: Add mkPackageOption
This is a squashed commit. These are the original commit messages:

lib/options: Add mkPackageOption

lib/options: Add missing semicolon

lib/options.nix: Make mkPackageOption more complicated

lib/options: Fix indent. & spacing

lib/options.nix: Remove example and align comment

lib/options: ravenous overuse of arguments

lib/options: Format better

lib/options: Add default examplePath decl

lib/options: Make better mkPackageOption function

lib/options: Remove trailing whitespace

lib/options: Improve mkPackageOptions

lib/options: Remove pkgs prefixing
Co-authored-by: pennae <82953136+pennae@users.noreply.github.com>

lib/options: Slim down mkPackageOption further

lib/options: mkPackageOption: Add "pkgs." to example

lib/options: mkPackageOption: Make name & pkgs single arguments

lib/options: mkPackageOption: Swap name & pkgs

lib/options: Remove unnecessary import
Co-authored-by: pennae <82953136+pennae@users.noreply.github.com>
2022-01-23 14:23:03 +01:00
Atemu
52bec72f73 licenses: add Alliance for Open Media Patent License 1.0 2022-01-22 22:15:50 +01:00
c0bw3b
3ec5a9f36b lib.licenses: add Imlib2 2022-01-22 18:50:40 +01:00
Robert Hensing
c4a5efa965
Merge pull request #155522 from Julow/single_line_str
types.singleLineStr: strings that don't contain '\n'
2022-01-21 17:39:13 +01:00
Jules Aguillon
1394bfc32a types.singleLineStr: Improve description
Co-authored-by: pennae <82953136+pennae@users.noreply.github.com>
2022-01-21 09:16:56 +01:00
Jules Aguillon
4baf8548fb types.singleLineStr: Allow and trim trailing \n
Allow a \n character at the end of the string and remove it during the
merge function.

An option of this type will resolve to the value "foo" whether it is set
to "foo" or "foo\n".

This is useful when using 'builtins.readFile' or ''-strings, which might
add an unintended newline (for example, bash trim the final newline from
a subshell).
2022-01-20 18:49:54 +01:00
sternenseemann
48965506a1 lib/asserts: use throw to display message for assertMsg
`assert` has the annoying property that it dumps a lot of code at the
user without the built in capability to display a nicer message. We have
worked around this using `assertMsg` which would *additionally* display
a nice message. We can do even better: By using `throw` we can make
evaluation fail before assert draws its conclusions and prevent it from
displaying the code making up the assert condition, so we get the nicer
message of `throw` and the syntactical convenience of `assert`.

Before:

    nix-repl> python.override { reproducibleBuild = true; stripBytecode = false; }
    trace: Deterministic builds require stripping bytecode.
    error: assertion (((lib).assertMsg  (reproducibleBuild -> stripBytecode))  "Deterministic builds require stripping bytecode.") failed at /home/lukas/src/nix/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/default.nix:45:1

After:

    nix-repl> python.override { reproducibleBuild = true; stripBytecode = false; }
    error: Deterministic builds require stripping bytecode.
2022-01-19 00:50:06 +01:00
Jules Aguillon
f25a13212b types.singleLineStr: Disallow \r 2022-01-18 23:56:50 +01:00
Jules Aguillon
df590070b0 types.singleLineStr: strings that don't contain '\n'
Add a new type, inheriting 'types.str' but checking whether the value
doesn't contain any newline characters.

The motivation comes from a problem with the
'users.users.${u}.openssh.authorizedKeys' option.
It is easy to unintentionally insert a newline character at the end of a
string, or even in the middle, for example:

    restricted_ssh_keys = command: keys:
      let
        prefix = ''
          command="${command}",no-pty,no-agent-forwarding,no-port-forwarding,no-X11-forwarding
        '';
      in map (key: "${prefix} ${key}") keys;

The 'prefix' string ends with a newline, which ends up in the middle of
a key entry after a few manipulations.

This is problematic because the key file is built by concatenating all
the keys with 'concatStringsSep "\n"', with result in two entries for
the faulty key:

    ''
      command="...",options...
      MY_KEY
    ''

This is hard to debug and might be dangerous. This is now caught at
build time.
2022-01-18 22:06:34 +01:00
pennae
6d44bc5b90
Merge pull request #152392 from polykernel/attrset-optimizations-patch-1
lib/attrset: various function optimizations
2022-01-11 16:01:52 +00:00
Robert Hensing
f1c69cb52d
Merge pull request #152046 from pennae/optimize-modules-byName
lib/modules: optimize byName
2022-01-10 14:02:39 +01:00
José Romildo
4fc67da841 lib.checkListOfEnum: init 2022-01-09 19:21:08 -03:00
Robert Hensing
c253b04a2f
Merge pull request #151748 from hercules-ci/check-nixpkgs-overlays-type
Check nixpkgs overlays argument types
2022-01-05 12:40:51 +01:00
pennae
fc614c37c6 nixos/documentation: split options doc build
most modules can be evaluated for their documentation in a very
restricted environment that doesn't include all of nixpkgs. this
evaluation can then be cached and reused for subsequent builds, merging
only documentation that has changed into the cached set. since nixos
ships with a large number of modules of which only a few are used in any
given config this can save evaluation a huge percentage of nixos
options available in any given config.

in tests of this caching, despite having to copy most of nixos/, saves
about 80% of the time needed to build the system manual, or about two
second on the machine used for testing. build time for a full system
config shrank from 9.4s to 7.4s, while turning documentation off
entirely shortened the build to 7.1s.
2022-01-02 19:46:13 +01:00
pennae
0de4ecff8c lib/modules: extract multiply-used value in byName
module.${attr} is used at least twice, so it must be evaluated at least
twice (and since it's a function argument, be turned into a thunk
twice).
2021-12-28 16:53:50 +01:00
polykernel
63ce7d3184 lib/attrset: miscellaneous optimizations
- Eta reduce `mapAttrsRecursiveCond`, `foldAttrs`, `getAttrFromPath`.
- Modify `matchAttrs` to use `elemAt` instead of `head (tail xs)` to access
  elements.
- Modify `matchAttrs` to use `any id` instead of `foldr and true`.
2021-12-27 22:24:28 -05:00
polykernel
a54f2231c9 lib/attrset: optimize element access in recursiveUpdateUntil
- Eta reduce formal arguments of `recursiveUpdate'.
- Access elements in `recursiveUpdateUntil` using `elemAt` and `head`
  directly instead of `head (tail xs)` which copies a singleton unnecessarily.
  (`elemAt` is used instead of `last` to save a primitive call to `length`,
  this is possible because the 2-tuple structure is guranteed)
- Use `length` instead of comparison to empty list to save a copy.
2021-12-27 18:17:52 -05:00
pennae
2dcae7d82f lib/attrsets: use builtins.zipAttrsWith if available 2021-12-25 15:20:26 +01:00
pennae
afecbb2f75 lib/modules: optimize byName
the foldl is equivalent to a zip with concat. list concatenation in nix
is an O(n) operation, which makes this operation extremely inefficient
when large numbers of modules are involved.

this change reduces the number of list elements by 7 million on the
system used to write this, total memory spent on lists by 58MB, and
total memory allocated on the GC heap by almost 100MB (with a similar
reduction in GC heap size). it's also slightly faster.
2021-12-25 00:19:44 +01:00
Robert Hensing
f2c5c706f4 lib.throwIfNot: init 2021-12-22 13:13:50 +01:00
Graham Christensen
06edb74413
Merge pull request #148785 from pennae/more-option-doc-staticizing
treewide: more defaultText for options
2021-12-17 11:14:08 -05:00
sternenseemann
9066c52e5a lib.systems.supported: remove aarch64-darwin from Tier 3 list
While it is a fact of life that aarch64-darwin is built on Hydra, it has
never formally been elevated from the Tier 7 state it was originally
assigned in RFC 0046. Since platform Tier status is not only
descriptive, but also normative, a consensus to commit to supporting
aarch64-darwin would need to be reached.
2021-12-16 17:51:21 +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
Jörg Thalheim
108ca3d04b
Merge pull request #149924 from Mic92/aarch64be-embedded
pkgsCross.aarch64be-embedded: fix eval
2021-12-09 22:11:37 +00:00
Jörg Thalheim
a8c277c8a8 pkgsCross.x86_64-netbsd-llvm: mark as broken 2021-12-09 23:08:40 +01:00
Jörg Thalheim
41a1e7fc36 pkgsCross.ppcle-embedded: fix eval 2021-12-09 22:23:15 +01:00
Jörg Thalheim
ce33ed7545 pkgsCross.aarch64be-embedded: fix eval 2021-12-09 21:49:19 +01:00
Silvan Mosberger
6d80d3c964 nixos/modules: Allow options to be coerced to a string for convenience 2021-12-08 21:41:17 +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
Silvan Mosberger
d2c50190b7
Merge pull request #141856 from ShamrockLee/lib-spdx-license
lib/meta: add getLicenseFromSpdxId function (resumed)
2021-12-07 18:37:13 +01:00
Robert Hensing
260b941dd0 lib/modules: Deprecate args and check 2021-12-02 18:23:43 +00:00
Robert Hensing
b37f099ae7 lib/modules: Pass legacy args argument along through extendModules 2021-12-02 17:45:48 +00:00
Shamrock Lee
60950f739e lib/meta: add getLicenseFromSpdxId function
Move function spdxLicense, internally used in yarn2nix
to lib/meta.nix, and
rename to getLicenseFromSpdxId

A similar function is implemented in poetry2nix,
but the one originally in yarn2nix seems beter.
since it falls back to an license-like attrset
for mismatched case
instead of a plain string
2021-12-02 18:33:48 +08: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
Timothy DeHerrera
2768bc07f7
add release notes for 22.05 and update codename 2021-11-22 15:10:53 -07:00
Robert Hensing
d464ccfdd9 modules: Add moduleType to module arguments 2021-11-22 16:50:50 +01:00
Robert Hensing
426ab31fde modules: Document that extendModules is also a module argument 2021-11-22 16:10:18 +01:00
Taeer Bar-Yam
0bef0c38f7 lib.modules: add mkDerivedConfig
mkDerivedConfig : Option a -> (a -> Definition b) -> Definition b

Create config definitions with the same priority as the definition of another option.
This should be used for option definitions where one option sets the value of another as a convenience.
For instance a config file could be set with a `text` or `source` option, where text translates to a `source`
value using `mkDerivedConfig options.text (pkgs.writeText "filename.conf")`.

It takes care of setting the right priority using `mkOverride`.
2021-11-15 07:03:41 -05:00
Jonathan Ringer
dbe6e96d0a
lib/systems: add x86_64-darwin hostPlatform 2021-11-10 11:37:34 -08: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
844a9e746f lib/modules: Use strict fold' as recursiveUpdate is also strict
recursiveUpdate does not produce an attrset until it has evaluated
both its arguments to weak head normal form.

    nix-repl> lib.recursiveUpdate (throw "a") (throw "b")
    error: b

    nix-repl> lib.recursiveUpdate (throw "a") {}
    error: a
2021-11-03 19:47:03 +01:00
Robert Hensing
541ce53a3b lib/modules: Fix import* comments
Very confusing otherwise.
2021-11-03 19:39:31 +01:00
Robert Hensing
8b584158a5 lib/modules: Remove a lib.flip
In hot code, the overhead (envs, applies) can matter.
2021-11-03 19:34:27 +01: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
bfaa9426c0 lib/modules: Short-circuit unmatchedDefns earlier 2021-11-03 19:05:26 +01:00
Robert Helgesson
c7678aff1b
lib: fix escapeXML example in documentation
The previous example output was forgotten copy-paste from some other
function.
2021-11-02 22:43:25 +01:00
Ben Siraphob
481afad265
Merge pull request #144072 from polykernel/lib-lists-mutuallyexclusive-optimization 2021-11-02 02:46:27 -05:00
polykernel
cd6397519f lib/lists: mutuallyExclusive function optimization
The current implementation of `mutuallyExclusive` builds a new list with
length subtracted by one on every recursive call which is expensive. When
b is empty, the function still traverses a in its entirety before returning
a result.

The new implementation uses `any` to check if each element of list b is in
list a using `elem`. This maintains short circuiting when list a or b is empty
and has a worst case time complexity of O(nm).
2021-11-01 16:29:01 -04:00
Robert Hensing
86f5136baf modules: Update evalModules doc 2021-11-01 09:38:51 +01:00
Robert Hensing
64dfd983df modules: Add visible = "shallow" to hide only sub-options 2021-11-01 09:34:07 +01:00
Robert Hensing
27644a82a9 modules: Add extendModules to module args 2021-11-01 09:34:07 +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
Robert Hensing
d6ebd537e5 lib/modules: Short-circuit unmatchedDefns when configs is empty 2021-10-31 22:28:42 +01:00
Ryan Burns
81ee86a2c6
Merge pull request #139284 from r-burns/powernv-kernel-config
lib/systems: update powernv kernel config
2021-10-28 13:53:16 -07:00
Silvan Mosberger
98f82e9c35
Merge pull request #141789 from pennae/eval-opt
lib: make extendDerivation lighter on eval
2021-10-21 20:17:32 +02:00
Markus S. Wamser
8e394b8533 licenses: add CAPEC 2021-10-15 23:10:34 +02:00
pennae
dc895fb281 lib: make extendDerivation lighter on eval
the fix to extendDerivation in #140051 unwittingly worsened eval performance by
quite a bit. set elements alone needed over 1GB extra after the change, which
seems disproportionate to how small it was. if we flip the logic used to
determine which outputs to install around and keep a "this one exactly" flag in
the specific outputs instead of a "all of them" in the root we can avoid most
of that cost.
2021-10-15 16:39:10 +02:00
Robert Hensing
a541ce1fe7
Merge pull request #140763 from hercules-ci/abort-on-warn
lib.warn: Add NIX_ABORT_ON_WARN for call traces
2021-10-13 22:43:39 +02:00
Robert Hensing
c9b7cc79e6 lib.warn: Add NIX_ABORT_ON_WARN for call traces 2021-10-13 22:43:06 +02:00
zimbatm
60d3ef0484
lib.systems.supported.tier3: add aarch64-darwin
aarch64-darwin is getting built by hydra
2021-10-06 17:27:32 +02: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
Jonas Chevalier
8377a7bca9
lib: add list of supported systems (#140428)
Adds the first 3 tiers of RFC0046 that are being used in flake.nix.
2021-10-05 11:14:47 +02:00
Robert Hensing
0699530f08
Merge pull request #136909 from ncfavier/cleanup-defaults-examples
nixos/doc: clean up defaults and examples
2021-10-04 20:37: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
Naïm Favier
52a2e4136e
lib/options: add literalExpression and literalDocBook, deprecate literalExample 2021-10-03 17:19:19 +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
243a61e183
Merge pull request #140051 from pennae/extend-derivation
fix nested calls to extendDerivation
2021-10-02 17:03:24 +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
Delta
48eba3e35c ocamlPackages.lustre-v6: init at 6.103.3 2021-09-30 21:38:06 +02:00
pennae
9b3b8f74bb fix nested calls to extendDerivation
if extendDerivation is called on something that already had extendDerivation
called on it (eg a mkDerivation result) the second call will set
outputUnspecified=true on every output by way of propagating attributes of the
full derivation to the individual outputs. this in turn causes buildEnv--and
thus nix-shell and environment.systemPackages--to install every output of such a
derivation even when only a specific output was requested, which renders the
point of multiple outputs moot. this happens in python modules (see #139756),
though it seems that tcl and possibly others should also be affected.
2021-09-30 17:34:07 +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
Ryan Burns
288cc2007b lib/systems: update powernv kernel config
PowerNV was looking for a nonexisting zImage file.
Remove unnecessary .file / .installTarget.

Also add config options needed for default minimal
NixOS config and QEMU VirtIO/VirtFS devices.
2021-09-28 17:41:13 -07:00
Maximilian Bosch
681758d415
lib/generators: fix error message 2021-09-28 22:26:51 +02:00
Alyssa Ross
f446318916
lib.cleanSource: ignore sockets
I'm working on a project that involves running a virtual machine
monitor program, which creates a control socket in the project
directory (because it doesn't make sense to put it anywhere else).
This obviously isn't part of the source of my program, so I think
cleanSource should filter it out.
2021-09-17 10:03:00 +00:00
zimbatm
f882fbcee0
lib.generators.toINI: serialize derivations to string
This is the common case when passing a derivation, we want to access the
store path.
2021-09-12 06:26:21 +02:00
zimbatm
9e90a400a5
lib.generators.toGitINI: don't traverse derivations
Consider a derivation a value to be serialized.

    nix-repl> lib.generators.toGitINI { hello = { drv = pkgs.hello; }; }
    error: evaluation aborted with the following error message: 'generators.mkValueStringDefault: attrsets not supported: <derivation /nix/store/533q15q67sl6dl0272dyi7m7w5pwkkjh-hello-2.10.drv>'

Fixes #137390
2021-09-12 06:26:20 +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
polykernel
de81edf6ef lib/strings: fix infinite recursion on concatStringsSep fallback
The current implementation of the concatStringsSep fallback references
concatStrings whcih is just a partial application of concatStringsSep,
forming a circular dependency. Although this will almost never be
encountered as (assuming the user does not explicitly trigger it):
  1. the or operator will short circuit both in lazy and strict
     evaluation
  2. this can only occur in Nix versions prior to 1.10
     which is not compatible with various nix operations as of 2.3.15

However it is still important if scopedImport is used or the builtins
have been overwritten. lib.foldl' is used instead of builtins.foldl'
as the foldl' primops was introduced in the same release as concatStringsSep.
2021-08-26 20:08:05 -04:00
Robert Hensing
cdf0aa2907
Merge pull request #135794 from shlevy/composeManyFlakeCompat
lib.compose{Many,}Extensions: Make compatible with nix flake check
2021-08-26 16:37:09 +02:00
Paul-Nicolas Madelaine
fa61f7635d replace dead links 2021-08-26 23:14:50 +09:00
Shea Levy
d09222e48f
lib.compose{Many,}Extensions: Make compatible with nix flake check 2021-08-26 09:12:17 -04:00
Maximilian Bosch
b96101a35f
lib/modules: grammar fix in error msg 2021-08-26 00:37:33 +02: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
b6d3c9f821
lib/modules: fix error-message when declaring an option inside `config'
The message I originally implemented here was to catch a mixup of
`config' and `options' in a `types.submodule'[1]. However it looks
rather weird for a wrongly declared top-level option.

So I decided to throw

    error: The option `foo' does not exist. Definition values:
           - In `<unknown-file>':
               {
                 bar = {
                   _type = "option";
                   type = {
                     _type = "option-type";
               ...

           It seems as you're trying to declare an option by placing it into `config' rather than `options'!

for an expression like

    with import ./lib;

    evalModules {
      modules = [
        {
          foo.bar = mkOption {
            type = types.str;
          };
        }
      ];
    }

[1]  fa30c9abed
2021-08-25 23:18:27 +02:00
Maximilian Bosch
fbc9084c39
lib/options: use depthLimit for toPretty when showing a definition
When having a bogus declaration such as

    { lib, ... }:
    {
      foo.bar = mkOption {
        type = types.str;
      };
    }

the evaluation will terminate with a not-so helpful

    error: stack overflow (possible infinite recursion)

To make sure a useful error is still provided, I added a `depthLimit` of
`10` which should be perfectly sufficient to `toPretty` when it's used
in an error-case for `showDefs`.
2021-08-25 23:18:27 +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
polykernel
3f4ce46a47 lib: optimize setAttrByPath and cleaup imports
- Remove inheritance of `lists.fold` as it isn't used anywhere.
- Inherit `foldl'` for consistency as only `cartesianProductOfSets` explicitly
  reference lib.
- Inline `foldr` to generate nested attrs instead of using `listToAttrs` and `tail`.
2021-08-23 18:04:47 -04:00
Harrison Houghton
9d71711aec lib: export strings/escapeRegex
I see no reason why I should be disallowed from using it.
2021-08-22 00:01:38 -04:00
Luke Granger-Brown
5ab1ce6734
Merge pull request #134763 from r-burns/fix-scaleway
lib/systems: fix scaleway-c1 platform
2021-08-21 03:40:30 +01:00
Alyssa Ross
273bab6bb6
lib.systems.inspect.patterns.isGnu: init
This allows checking e.g. stdenv.hostPlatform.isGnu, just like isMusl
or isUClibc.  It was already possible to check for glibc with
stdenv.hostPlatform.libc == "glibc", but when that doesn't line up
with how every other platform check works, this is apparently
sufficiently non-obvious that we've ended up with stuff like adding
glibc.static if !isMusl, which is obviously wrong.
2021-08-19 13:03:53 +00:00
Ryan Burns
525c69e724 lib/systems: fix scaleway-c1 platform
This regressed in 9c213398b3

The recursiveUpdate gave the platform both gcc.cpu and gcc.arch attrs
instead of only gcc.cpu. This is invalid; gcc configuration fails with:

```
Switch "--with-arch" may not be used with switch "--with-cpu"
```

So we revert to using `//` to retain only gcc.cpu
(which is more specific than the processor arch).
2021-08-18 21:52:14 -07:00
lassulus
229ff549e6 lib: inherit mkImageMediaOverride 2021-08-18 14:21:16 +02:00
Lassulus
6a74d5562e
Merge pull request #132583 from blaggacao/fix/soft-force-the-file-system-layout-for-boot-media
nixos/boot-media: soft-force entire fs layout
2021-08-17 22:36:41 +02:00