diff --git a/lix/libcmd/repl.cc b/lix/libcmd/repl.cc index e0b0658cd..38b849054 100644 --- a/lix/libcmd/repl.cc +++ b/lix/libcmd/repl.cc @@ -210,13 +210,12 @@ struct NixRepl void printValue(std::ostream & str, Value & v, unsigned int maxDepth = std::numeric_limits::max(), - bool replDerivation = false) + unsigned int derivationPathDepth = 0) { ::nix::printValue(state, str, v, PrintOptions { .ansiColors = true, .force = true, - .derivationPaths = !replDerivation, - .replDerivation = replDerivation, + .derivationPathDepth = derivationPathDepth, .maxDepth = maxDepth, .prettyIndent = 2, .errors = ErrorPrintBehavior::ThrowTopLevel, @@ -796,9 +795,9 @@ ProcessLineResult NixRepl::processLine(std::string line) if (v.type() == nString) { std::cout << v.str(); } else if (v.type() == nAttrs && state.isDerivation(v)) { - printValue(std::cout, v, 2, true); + printValue(std::cout, v, 2, 1); } else { - printValue(std::cout, v, std::numeric_limits::max()); + printValue(std::cout, v, std::numeric_limits::max(), 0); } std::cout << std::endl; } diff --git a/lix/libexpr/print-options.hh b/lix/libexpr/print-options.hh index b374507d3..db851fccb 100644 --- a/lix/libexpr/print-options.hh +++ b/lix/libexpr/print-options.hh @@ -48,16 +48,12 @@ struct PrintOptions bool force = false; /** - * If true and `force` is set, print derivations as - * `«derivation /nix/store/...»` instead of as attribute sets. + * Determines at what depth derivations start getting printed as paths. + * When `force` is true and our print depth is greater than or equal to + * this value, print derivations as `«derivation /nix/store/...»` + * instead of as attribute sets. */ - bool derivationPaths = false; - - /** - * If true, we are interactively printing a full derivation and should - * switch back to printing paths as desired normally after the first entry. - */ - bool replDerivation = false; + size_t derivationPathDepth = std::numeric_limits::max(); /** * If true, track which values have been printed and skip them on diff --git a/lix/libexpr/print.cc b/lix/libexpr/print.cc index 48a2ff8f5..d6e844711 100644 --- a/lix/libexpr/print.cc +++ b/lix/libexpr/print.cc @@ -281,16 +281,13 @@ private: void printAttrs(Value & v, size_t depth) { - if (options.force && options.derivationPaths && state.isDerivation(v)) { + bool shouldSimplifyDerivations = options.force && depth >= options.derivationPathDepth; + bool isDerivation = state.isDerivation(v); + if (shouldSimplifyDerivations && isDerivation) { printDerivation(v); } else if (seen && !v.attrs()->empty() && !seen->insert(v.attrs()).second) { printRepeated(); } else if (depth < options.maxDepth || v.attrs()->empty()) { - bool isPrintingReplDerivation = depth == 0 && options.replDerivation && state.isDerivation(v); - if (isPrintingReplDerivation) { - // Switch back to eliding paths if it was initially off. - options.derivationPaths = true; - } increaseIndent(); output << "{"; @@ -331,7 +328,7 @@ private: output << " = "; // Elide repeated drvAttrs attribute. - if (isPrintingReplDerivation && i.first == "drvAttrs") { + if (!shouldSimplifyDerivations && isDerivation && i.first == "drvAttrs") { state.forceValue(i.second->value, noPos); if (i.second->value.type() == ValueType::nAttrs) { printElided(i.second->value.attrs()->size(), "attribute", "attributes"); diff --git a/lix/nix/eval.cc b/lix/nix/eval.cc index 64beb152e..12bf356a8 100644 --- a/lix/nix/eval.cc +++ b/lix/nix/eval.cc @@ -110,7 +110,7 @@ struct CmdEval : MixJSON, InstallableCommand, MixReadOnlyOption v, PrintOptions{ .force = true, - .derivationPaths = true, + .derivationPathDepth = 0, .errors = ErrorPrintBehavior::ThrowTopLevel, } ) diff --git a/tests/unit/libexpr/value/print.cc b/tests/unit/libexpr/value/print.cc index 70f4d3465..de6948bcb 100644 --- a/tests/unit/libexpr/value/print.cc +++ b/tests/unit/libexpr/value/print.cc @@ -450,7 +450,7 @@ TEST_F(ValuePrintingTests, ansiColorsDerivation) PrintOptions { .ansiColors = true, .force = true, - .derivationPaths = true + .derivationPathDepth = 0 }); test(vAttrs, @@ -507,7 +507,7 @@ TEST_F(ValuePrintingTests, ansiColorsDerivationError) PrintOptions { .ansiColors = true, .force = true, - .derivationPaths = true, + .derivationPathDepth = 0, }); }