diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 93c130284..1f4d0f761 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -1297,7 +1297,7 @@ void EvalState::getAttrFieldThrow(Value & attrs, const std::vector & sel throw Error("Missing attribute path '%s'", "ImTooLazyToImplementThisRightNow"); } -std::vector EvalState::getFields(Value & attrs, const Pos & pos) +std::vector EvalState::getFields(Value & attrs, const Pos & pos) { auto eval_cache = attrs.getEvalCache(); if (eval_cache.isEmpty()) { @@ -1305,34 +1305,14 @@ std::vector EvalState::getFields(Value & attrs, const Pos & pos) eval_cache = attrs.getEvalCache(); } if (auto attrNames = eval_cache.listChildren(symbols)) { - bool everythingCached = true; - std::vector res; - for (auto & attrName : *attrNames) { - auto newValue = allocValue(); - try { - if (lazyGetAttrField(attrs, {attrName}, pos, *newValue) != LazyValueType::Missing) { - res.push_back(Attr(attrName, newValue)); - } else { - everythingCached = false; - break; - } - } catch (EvalError & e) { - // XXX: Ugly hack to hide the error - newValue->mkThunk( - &baseEnv, - new ExprApp( - parseExprFromString("throw", "/"), - new ExprString(symbols.create(e.what())) - ) - ); - } - } - if (everythingCached) return res; + return *attrNames; } forceValue(attrs); - auto attrsStart = attrs.attrs->attrs; - return std::vector(attrsStart, attrsStart + attrs.attrs->size()); + std::vector res; + for (auto & attr : *attrs.attrs) + res.push_back(attr.name); + return res; } void ExprSelect::eval(EvalState & state, Env & env, Value & v) diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index 73ef7f598..9d2ee2941 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -371,7 +371,7 @@ public: // found void getAttrFieldThrow(Value & attrs, const std::vector & selector, const Pos & pos, Value & dest); - std::vector getFields(Value & attrs, const Pos & pos); + std::vector getFields(Value & attrs, const Pos & pos); }; diff --git a/src/nix/search.cc b/src/nix/search.cc index 928f11fea..05272fd36 100644 --- a/src/nix/search.cc +++ b/src/nix/search.cc @@ -93,10 +93,20 @@ struct CmdSearch : InstallableCommand, MixJSON fmt("evaluating '%s'", concatStringsSep(".", attrPath))); auto recurse = [&]() { - for (auto & attr : state->getFields(current, noPos)) { + for (auto & attrName : state->getFields(current, noPos)) { + try { auto attrPath2(attrPath); - attrPath2.push_back(attr.name); - visit2(*attr.value, attrPath2, false); + attrPath2.push_back(attrName); + auto attrValue = state->allocValue(); + auto value_ = allocRootValue(attrValue); + state->lazyGetAttrField(current, {attrName}, noPos, + *attrValue); + visit2(*attrValue, attrPath2, false); + } catch (EvalError &e) { + if (!(attrPath.size() > 0 && + attrPath[0] == "legacyPackages")) + throw; + } } };