mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-10 08:16:15 +02:00
* Allow the system attribute of derivations to be queried in
`nix-env -q'. * Queries can now be combined, e.g., `nix-env -q --status --system'.
This commit is contained in:
parent
b584253af4
commit
593bc23d8b
1 changed files with 51 additions and 38 deletions
|
@ -28,6 +28,7 @@ typedef void (* Operation) (Globals & globals,
|
||||||
struct DrvInfo
|
struct DrvInfo
|
||||||
{
|
{
|
||||||
string name;
|
string name;
|
||||||
|
string system;
|
||||||
Path drvPath;
|
Path drvPath;
|
||||||
Path outPath;
|
Path outPath;
|
||||||
Hash drvHash;
|
Hash drvHash;
|
||||||
|
@ -56,6 +57,12 @@ bool parseDerivation(EvalState & state, Expr e, DrvInfo & drv)
|
||||||
if (!a) throw badTerm("derivation name missing", e);
|
if (!a) throw badTerm("derivation name missing", e);
|
||||||
drv.name = evalString(state, a);
|
drv.name = evalString(state, a);
|
||||||
|
|
||||||
|
a = queryAttr(e, "system");
|
||||||
|
if (!a)
|
||||||
|
drv.system = "unknown";
|
||||||
|
else
|
||||||
|
drv.system = evalString(state, a);
|
||||||
|
|
||||||
a = queryAttr(e, "drvPath");
|
a = queryAttr(e, "drvPath");
|
||||||
if (!a) throw badTerm("derivation path missing", e);
|
if (!a) throw badTerm("derivation path missing", e);
|
||||||
drv.drvPath = evalPath(state, a);
|
drv.drvPath = evalPath(state, a);
|
||||||
|
@ -181,11 +188,13 @@ void createUserEnv(EvalState & state, const DrvInfos & drvs,
|
||||||
"Attrs(["
|
"Attrs(["
|
||||||
"Bind(\"type\", Str(\"derivation\"), NoPos), "
|
"Bind(\"type\", Str(\"derivation\"), NoPos), "
|
||||||
"Bind(\"name\", Str(<str>), NoPos), "
|
"Bind(\"name\", Str(<str>), NoPos), "
|
||||||
|
"Bind(\"system\", Str(<str>), NoPos), "
|
||||||
"Bind(\"drvPath\", Path(<str>), NoPos), "
|
"Bind(\"drvPath\", Path(<str>), NoPos), "
|
||||||
"Bind(\"drvHash\", Str(<str>), NoPos), "
|
"Bind(\"drvHash\", Str(<str>), NoPos), "
|
||||||
"Bind(\"outPath\", Path(<str>), NoPos)"
|
"Bind(\"outPath\", Path(<str>), NoPos)"
|
||||||
"])",
|
"])",
|
||||||
i->second.name.c_str(),
|
i->second.name.c_str(),
|
||||||
|
i->second.system.c_str(),
|
||||||
i->second.drvPath.c_str(),
|
i->second.drvPath.c_str(),
|
||||||
((string) i->second.drvHash).c_str(),
|
((string) i->second.drvHash).c_str(),
|
||||||
i->second.outPath.c_str());
|
i->second.outPath.c_str());
|
||||||
|
@ -454,14 +463,19 @@ static bool cmpDrvByName(const DrvInfo & a, const DrvInfo & b)
|
||||||
static void opQuery(Globals & globals,
|
static void opQuery(Globals & globals,
|
||||||
Strings opFlags, Strings opArgs)
|
Strings opFlags, Strings opArgs)
|
||||||
{
|
{
|
||||||
enum { qName, qDrvPath, qStatus } query = qName;
|
bool printStatus = false;
|
||||||
|
bool printName = true;
|
||||||
|
bool printSystem = false;
|
||||||
|
bool printDrvPath = false;
|
||||||
|
|
||||||
enum { sInstalled, sAvailable } source = sInstalled;
|
enum { sInstalled, sAvailable } source = sInstalled;
|
||||||
|
|
||||||
for (Strings::iterator i = opFlags.begin();
|
for (Strings::iterator i = opFlags.begin();
|
||||||
i != opFlags.end(); ++i)
|
i != opFlags.end(); ++i)
|
||||||
if (*i == "--name") query = qName;
|
if (*i == "--status" || *i == "-s") printStatus = true;
|
||||||
else if (*i == "--expr") query = qDrvPath;
|
else if (*i == "--no-name") printName = false;
|
||||||
else if (*i == "--status" || *i == "-s") query = qStatus;
|
else if (*i == "--system") printSystem = true;
|
||||||
|
else if (*i == "--expr") printDrvPath = true;
|
||||||
else if (*i == "--installed") source = sInstalled;
|
else if (*i == "--installed") source = sInstalled;
|
||||||
else if (*i == "--available" || *i == "-a") source = sAvailable;
|
else if (*i == "--available" || *i == "-a") source = sAvailable;
|
||||||
else throw UsageError(format("unknown flag `%1%'") % *i);
|
else throw UsageError(format("unknown flag `%1%'") % *i);
|
||||||
|
@ -491,43 +505,42 @@ static void opQuery(Globals & globals,
|
||||||
drvs2.push_back(i->second);
|
drvs2.push_back(i->second);
|
||||||
sort(drvs2.begin(), drvs2.end(), cmpDrvByName);
|
sort(drvs2.begin(), drvs2.end(), cmpDrvByName);
|
||||||
|
|
||||||
/* Perform the specified query on the derivations. */
|
/* We only need to know the installed paths when we are querying
|
||||||
switch (query) {
|
the status of the derivation. */
|
||||||
|
PathSet installedPaths; /* output paths of installed drvs */
|
||||||
|
|
||||||
case qName: {
|
if (printStatus) {
|
||||||
for (DrvInfoList::iterator i = drvs2.begin(); i != drvs2.end(); ++i)
|
DrvInfos installed;
|
||||||
cout << format("%1%\n") % i->name;
|
queryInstalled(globals.state, installed, globals.profile);
|
||||||
break;
|
|
||||||
|
for (DrvInfos::iterator i = installed.begin();
|
||||||
|
i != installed.end(); ++i)
|
||||||
|
installedPaths.insert(i->second.outPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Print the desired columns. */
|
||||||
|
for (DrvInfoList::iterator i = drvs2.begin(); i != drvs2.end(); ++i) {
|
||||||
|
|
||||||
|
Strings columns;
|
||||||
|
|
||||||
|
if (printStatus) {
|
||||||
|
Substitutes subs = querySubstitutes(i->drvPath);
|
||||||
|
columns.push_back(
|
||||||
|
(string) (installedPaths.find(i->outPath)
|
||||||
|
!= installedPaths.end() ? "I" : "-")
|
||||||
|
+ (isValidPath(i->outPath) ? "P" : "-")
|
||||||
|
+ (subs.size() > 0 ? "S" : "-"));
|
||||||
}
|
}
|
||||||
|
|
||||||
case qDrvPath: {
|
if (printName) columns.push_back(i->name);
|
||||||
for (DrvInfoList::iterator i = drvs2.begin(); i != drvs2.end(); ++i)
|
|
||||||
cout << format("%1%\n") % i->drvPath;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case qStatus: {
|
if (printSystem) columns.push_back(i->system);
|
||||||
DrvInfos installed;
|
|
||||||
queryInstalled(globals.state, installed, globals.profile);
|
|
||||||
|
|
||||||
PathSet installedPaths; /* output paths of installed drvs */
|
if (printDrvPath) columns.push_back(i->drvPath);
|
||||||
for (DrvInfos::iterator i = installed.begin();
|
|
||||||
i != installed.end(); ++i)
|
|
||||||
installedPaths.insert(i->second.outPath);
|
|
||||||
|
|
||||||
for (DrvInfoList::iterator i = drvs2.begin(); i != drvs2.end(); ++i) {
|
for (Strings::iterator j = columns.begin(); j != columns.end(); ++j)
|
||||||
Substitutes subs = querySubstitutes(i->drvPath);
|
cout << *j << " ";
|
||||||
cout << format("%1%%2%%3% %4%\n")
|
cout << endl;
|
||||||
% (installedPaths.find(i->outPath)
|
|
||||||
!= installedPaths.end() ? 'I' : '-')
|
|
||||||
% (isValidPath(i->outPath) ? 'P' : '-')
|
|
||||||
% (subs.size() > 0 ? 'S' : '-')
|
|
||||||
% i->name;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default: abort();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue