forked from lix-project/lix
* Nix-env operations now by default filter out any derivations for
system types other than the current system. I.e., `nix-env -i' won't install derivations for other system types, and `nix-env -q' won't show them. The flag `--system-filter SYSTEM' can be used to override the system type used for filtering (but not for building!). The value `*' can be used not to filter anything.
This commit is contained in:
parent
8f6254e823
commit
292d6468ec
|
@ -18,6 +18,7 @@ struct Globals
|
||||||
EvalState state;
|
EvalState state;
|
||||||
bool dryRun;
|
bool dryRun;
|
||||||
bool preserveInstalled;
|
bool preserveInstalled;
|
||||||
|
string systemFilter;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -116,11 +117,20 @@ bool parseDerivations(EvalState & state, Expr e, DrvInfos & drvs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void loadDerivations(EvalState & state, Path nePath, DrvInfos & drvs)
|
void loadDerivations(EvalState & state, Path nePath, DrvInfos & drvs,
|
||||||
|
string systemFilter)
|
||||||
{
|
{
|
||||||
Expr e = parseExprFromFile(state, absPath(nePath));
|
Expr e = parseExprFromFile(state, absPath(nePath));
|
||||||
if (!parseDerivations(state, e, drvs))
|
if (!parseDerivations(state, e, drvs))
|
||||||
throw Error("set of derivations expected");
|
throw Error("set of derivations expected");
|
||||||
|
|
||||||
|
/* Filter out all derivations not applicable to the current
|
||||||
|
system. */
|
||||||
|
for (DrvInfos::iterator i = drvs.begin(), j; i != drvs.end(); i = j) {
|
||||||
|
j = i; j++;
|
||||||
|
if (systemFilter != "*" && i->second.system != systemFilter)
|
||||||
|
drvs.erase(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -235,13 +245,13 @@ void createUserEnv(EvalState & state, const DrvInfos & drvs,
|
||||||
|
|
||||||
static void installDerivations(EvalState & state,
|
static void installDerivations(EvalState & state,
|
||||||
Path nePath, DrvNames & selectors, const Path & profile,
|
Path nePath, DrvNames & selectors, const Path & profile,
|
||||||
bool dryRun, bool preserveInstalled)
|
bool dryRun, bool preserveInstalled, string systemFilter)
|
||||||
{
|
{
|
||||||
debug(format("installing derivations from `%1%'") % nePath);
|
debug(format("installing derivations from `%1%'") % nePath);
|
||||||
|
|
||||||
/* Fetch all derivations from the input file. */
|
/* Fetch all derivations from the input file. */
|
||||||
DrvInfos availDrvs;
|
DrvInfos availDrvs;
|
||||||
loadDerivations(state, nePath, availDrvs);
|
loadDerivations(state, nePath, availDrvs, systemFilter);
|
||||||
|
|
||||||
/* Filter out the ones we're not interested in. */
|
/* Filter out the ones we're not interested in. */
|
||||||
DrvInfos selectedDrvs;
|
DrvInfos selectedDrvs;
|
||||||
|
@ -302,7 +312,7 @@ static void opInstall(Globals & globals,
|
||||||
|
|
||||||
installDerivations(globals.state, globals.nixExprPath,
|
installDerivations(globals.state, globals.nixExprPath,
|
||||||
drvNames, globals.profile, globals.dryRun,
|
drvNames, globals.profile, globals.dryRun,
|
||||||
globals.preserveInstalled);
|
globals.preserveInstalled, globals.systemFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -311,7 +321,7 @@ typedef enum { utLt, utLeq, utAlways } UpgradeType;
|
||||||
|
|
||||||
static void upgradeDerivations(EvalState & state,
|
static void upgradeDerivations(EvalState & state,
|
||||||
Path nePath, DrvNames & selectors, const Path & profile,
|
Path nePath, DrvNames & selectors, const Path & profile,
|
||||||
UpgradeType upgradeType, bool dryRun)
|
UpgradeType upgradeType, bool dryRun, string systemFilter)
|
||||||
{
|
{
|
||||||
debug(format("upgrading derivations from `%1%'") % nePath);
|
debug(format("upgrading derivations from `%1%'") % nePath);
|
||||||
|
|
||||||
|
@ -326,7 +336,7 @@ static void upgradeDerivations(EvalState & state,
|
||||||
|
|
||||||
/* Fetch all derivations from the input file. */
|
/* Fetch all derivations from the input file. */
|
||||||
DrvInfos availDrvs;
|
DrvInfos availDrvs;
|
||||||
loadDerivations(state, nePath, availDrvs);
|
loadDerivations(state, nePath, availDrvs, systemFilter);
|
||||||
|
|
||||||
/* Go through all installed derivations. */
|
/* Go through all installed derivations. */
|
||||||
DrvInfos newDrvs;
|
DrvInfos newDrvs;
|
||||||
|
@ -412,7 +422,8 @@ static void opUpgrade(Globals & globals,
|
||||||
DrvNames drvNames = drvNamesFromArgs(opArgs);
|
DrvNames drvNames = drvNamesFromArgs(opArgs);
|
||||||
|
|
||||||
upgradeDerivations(globals.state, globals.nixExprPath,
|
upgradeDerivations(globals.state, globals.nixExprPath,
|
||||||
drvNames, globals.profile, upgradeType, globals.dryRun);
|
drvNames, globals.profile, upgradeType, globals.dryRun,
|
||||||
|
globals.systemFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -465,7 +476,7 @@ typedef list<Strings> Table;
|
||||||
|
|
||||||
void printTable(Table & table)
|
void printTable(Table & table)
|
||||||
{
|
{
|
||||||
int nrColumns = table.front().size();
|
int nrColumns = table.size() > 0 ? table.front().size() : 0;
|
||||||
|
|
||||||
vector<int> widths;
|
vector<int> widths;
|
||||||
widths.resize(nrColumns);
|
widths.resize(nrColumns);
|
||||||
|
@ -520,7 +531,8 @@ static void opQuery(Globals & globals,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case sAvailable: {
|
case sAvailable: {
|
||||||
loadDerivations(globals.state, globals.nixExprPath, drvs);
|
loadDerivations(globals.state, globals.nixExprPath,
|
||||||
|
drvs, globals.systemFilter);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -702,6 +714,7 @@ void run(Strings args)
|
||||||
globals.nixExprPath = getDefNixExprPath();
|
globals.nixExprPath = getDefNixExprPath();
|
||||||
globals.dryRun = false;
|
globals.dryRun = false;
|
||||||
globals.preserveInstalled = false;
|
globals.preserveInstalled = false;
|
||||||
|
globals.systemFilter = thisSystem;
|
||||||
|
|
||||||
for (Strings::iterator i = args.begin(); i != args.end(); ++i) {
|
for (Strings::iterator i = args.begin(); i != args.end(); ++i) {
|
||||||
string arg = *i;
|
string arg = *i;
|
||||||
|
@ -744,6 +757,12 @@ void run(Strings args)
|
||||||
}
|
}
|
||||||
else if (arg == "--preserve-installed" || arg == "-P")
|
else if (arg == "--preserve-installed" || arg == "-P")
|
||||||
globals.preserveInstalled = true;
|
globals.preserveInstalled = true;
|
||||||
|
else if (arg == "--system-filter") {
|
||||||
|
++i;
|
||||||
|
if (i == args.end()) throw UsageError(
|
||||||
|
format("`%1%' requires an argument") % arg);
|
||||||
|
globals.systemFilter = *i;
|
||||||
|
}
|
||||||
else if (arg[0] == '-')
|
else if (arg[0] == '-')
|
||||||
opFlags.push_back(arg);
|
opFlags.push_back(arg);
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue