nixpkgs/lib
sternenseemann d9a7d03da8 lib/generators: fix toPretty throwing on (partially applied) builtins
An high level example case of this problem occuring can be found below:

nix-repl> lib.generators.toPretty {} (lib.concatStringsSep "\n")
error: 'functionArgs' requires a function, at /home/lukas/src/nix/nixpkgs/lib/trivial.nix:334:42

However this does not happen on other partially applied functions:

nix-repl> lib.generators.toPretty {} (lib.concatMapStringsSep "\n")
"<function>"

The issue, as it turns out is that while builtins are functions,
builtins.functionArgs throws if is passed a builtin or a partially
applied builtin:

nix-repl> lib.generators.toPretty {} builtins.toString
error: 'functionArgs' requires a function, at /home/lukas/src/nix/nixpkgs/lib/trivial.nix:334:42

nix-repl> lib.generators.toPretty {} (builtins.foldl' (a: b: a + b))
error: 'functionArgs' requires a function, at /home/lukas/src/nix/nixpkgs/lib/trivial.nix:334:42

I'm pretty sure this qualifies as a nix bug and should be filed
accordingly, but we can work around it in lib.generators.toPretty by
using tryEval and falling back to {} which functionArgs _should_ return
for builtins.

The nix behavior is inconsistent to say the least:

nix-repl> builtins.functionArgs builtins.functionArgs
error: 'functionArgs' requires a function, at (string):1:1

nix-repl> builtins.typeOf builtins.functionArgs
"lambda"

builtins.functionArgs (a: 1 + a)
{ }

nix-repl> builtins.typeOf (a: 1 + a)
"lambda"
2021-01-31 15:35:17 +01:00
..
systems gcc: fix armhf target 2021-01-29 10:48:23 +01:00
tests lib/tests: More functionTo tests 2021-01-27 00:17:56 +01:00
asserts.nix
attrsets.nix
cli.nix
customisation.nix lib: Create makeScopeWithSplicing 2020-11-19 00:07:14 -05:00
debug.nix lib/debug: add traceFnSeqN 2021-01-25 19:25:50 +01:00
default.nix lib/debug: add traceFnSeqN 2021-01-25 19:25:50 +01:00
deprecated.nix
fetchers.nix
filesystem.nix lib: Add readTree function to filesystem 2020-10-19 16:42:21 -07:00
fixed-points.nix lib: Add composeManyExtensions 2020-11-13 21:37:57 +01:00
generators.nix lib/generators: fix toPretty throwing on (partially applied) builtins 2021-01-31 15:35:17 +01:00
kernel.nix
licenses.nix treewide: fix double quoted strings in meta.description 2021-01-24 19:56:59 +07:00
lists.nix lib.lists.unique: Switch from recursive function to using a fold 2020-11-24 14:31:54 +01:00
meta.nix
minver.nix
modules.nix lib/modules: Set submodule type for renamed option sets 2021-01-21 21:57:48 +01:00
options.nix Revert "Module-builtin assertions, disabling assertions and submodule assertions" 2020-12-18 16:44:37 +01:00
sources.nix lib/sources.nix: fix incorrect inherit 2020-10-30 23:19:22 +01:00
strings-with-deps.nix lib: Use Nix's static scope checking, fix error message, optimize 2020-10-22 13:46:47 +02:00
strings.nix lib/string: drop redundant string in description of toInt. 2020-12-05 14:35:30 +00:00
trivial.nix
types.nix lib/types: Improved functionTo merging 2021-01-27 00:16:23 +01:00
versions.nix
zip-int-bits.nix