mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-23 06:26:15 +02:00
Always enter first level of attrset in nix search
This makes nix search always go through the first level of an attribute set, even if it's not a top level attribute. For instance, you can now list all GHC compilers with: $ nix search nixpkgs#haskell.compiler ... This is similar to how nix-env works when you pass in -A.
This commit is contained in:
parent
c8937ba9f3
commit
e38cd5becb
1 changed files with 7 additions and 4 deletions
|
@ -81,9 +81,9 @@ struct CmdSearch : InstallableCommand, MixJSON
|
||||||
|
|
||||||
uint64_t results = 0;
|
uint64_t results = 0;
|
||||||
|
|
||||||
std::function<void(eval_cache::AttrCursor & cursor, const std::vector<Symbol> & attrPath)> visit;
|
std::function<void(eval_cache::AttrCursor & cursor, const std::vector<Symbol> & attrPath, bool initialRecurse)> visit;
|
||||||
|
|
||||||
visit = [&](eval_cache::AttrCursor & cursor, const std::vector<Symbol> & attrPath)
|
visit = [&](eval_cache::AttrCursor & cursor, const std::vector<Symbol> & attrPath, bool initialRecurse)
|
||||||
{
|
{
|
||||||
Activity act(*logger, lvlInfo, actUnknown,
|
Activity act(*logger, lvlInfo, actUnknown,
|
||||||
fmt("evaluating '%s'", concatStringsSep(".", attrPath)));
|
fmt("evaluating '%s'", concatStringsSep(".", attrPath)));
|
||||||
|
@ -94,7 +94,7 @@ struct CmdSearch : InstallableCommand, MixJSON
|
||||||
auto cursor2 = cursor.getAttr(attr);
|
auto cursor2 = cursor.getAttr(attr);
|
||||||
auto attrPath2(attrPath);
|
auto attrPath2(attrPath);
|
||||||
attrPath2.push_back(attr);
|
attrPath2.push_back(attr);
|
||||||
visit(*cursor2, attrPath2);
|
visit(*cursor2, attrPath2, false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -150,6 +150,9 @@ struct CmdSearch : InstallableCommand, MixJSON
|
||||||
|| (attrPath[0] == "packages" && attrPath.size() <= 2))
|
|| (attrPath[0] == "packages" && attrPath.size() <= 2))
|
||||||
recurse();
|
recurse();
|
||||||
|
|
||||||
|
else if (initialRecurse)
|
||||||
|
recurse();
|
||||||
|
|
||||||
else if (attrPath[0] == "legacyPackages" && attrPath.size() > 2) {
|
else if (attrPath[0] == "legacyPackages" && attrPath.size() > 2) {
|
||||||
auto attr = cursor.maybeGetAttr(state->sRecurseForDerivations);
|
auto attr = cursor.maybeGetAttr(state->sRecurseForDerivations);
|
||||||
if (attr && attr->getBool())
|
if (attr && attr->getBool())
|
||||||
|
@ -163,7 +166,7 @@ struct CmdSearch : InstallableCommand, MixJSON
|
||||||
};
|
};
|
||||||
|
|
||||||
for (auto & [cursor, prefix] : installable->getCursors(*state))
|
for (auto & [cursor, prefix] : installable->getCursors(*state))
|
||||||
visit(*cursor, parseAttrPath(*state, prefix));
|
visit(*cursor, parseAttrPath(*state, prefix), true);
|
||||||
|
|
||||||
if (!json && !results)
|
if (!json && !results)
|
||||||
throw Error("no results for the given search term(s)!");
|
throw Error("no results for the given search term(s)!");
|
||||||
|
|
Loading…
Reference in a new issue