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`.
This commit is contained in:
Maximilian Bosch 2021-07-23 10:49:51 +02:00
parent 55ea29fd8c
commit fbc9084c39
No known key found for this signature in database
GPG Key ID: 091DBF4D1FC46B8E

View File

@ -247,7 +247,7 @@ rec {
showDefs = defs: concatMapStrings (def:
let
# Pretty print the value for display, if successful
prettyEval = builtins.tryEval (lib.generators.toPretty {} def.value);
prettyEval = builtins.tryEval (lib.generators.toPretty { depthLimit = 10; } def.value);
# Split it into its lines
lines = filter (v: ! isList v) (builtins.split "\n" prettyEval.value);
# Only display the first 5 lines, and indent them for better visibility