Commit graph

2999 commits

Author SHA1 Message Date
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
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