Commit Graph

2970 Commits

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