diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2004-07-01 13:56:56 +0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2004-07-01 13:56:56 +0000 |
commit | 292d6468ec73212a2ada3bd5f7f3f6e897f9086e (patch) | |
tree | 1aeee44144d636ae12d007b333f14534d279d7ab /src | |
parent | 8f6254e8234c5f4a16b1b7d632065ebb0162b307 (diff) |
* 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.
Diffstat (limited to 'src')
-rw-r--r-- | src/nix-env/main.cc | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/src/nix-env/main.cc b/src/nix-env/main.cc index a80f882de..8e5ba67e9 100644 --- a/src/nix-env/main.cc +++ b/src/nix-env/main.cc @@ -18,6 +18,7 @@ struct Globals EvalState state; bool dryRun; 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)); if (!parseDerivations(state, e, drvs)) 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, Path nePath, DrvNames & selectors, const Path & profile, - bool dryRun, bool preserveInstalled) + bool dryRun, bool preserveInstalled, string systemFilter) { debug(format("installing derivations from `%1%'") % nePath); /* Fetch all derivations from the input file. */ DrvInfos availDrvs; - loadDerivations(state, nePath, availDrvs); + loadDerivations(state, nePath, availDrvs, systemFilter); /* Filter out the ones we're not interested in. */ DrvInfos selectedDrvs; @@ -302,7 +312,7 @@ static void opInstall(Globals & globals, installDerivations(globals.state, globals.nixExprPath, 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, Path nePath, DrvNames & selectors, const Path & profile, - UpgradeType upgradeType, bool dryRun) + UpgradeType upgradeType, bool dryRun, string systemFilter) { debug(format("upgrading derivations from `%1%'") % nePath); @@ -326,7 +336,7 @@ static void upgradeDerivations(EvalState & state, /* Fetch all derivations from the input file. */ DrvInfos availDrvs; - loadDerivations(state, nePath, availDrvs); + loadDerivations(state, nePath, availDrvs, systemFilter); /* Go through all installed derivations. */ DrvInfos newDrvs; @@ -412,7 +422,8 @@ static void opUpgrade(Globals & globals, DrvNames drvNames = drvNamesFromArgs(opArgs); 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) { - int nrColumns = table.front().size(); + int nrColumns = table.size() > 0 ? table.front().size() : 0; vector<int> widths; widths.resize(nrColumns); @@ -520,7 +531,8 @@ static void opQuery(Globals & globals, break; case sAvailable: { - loadDerivations(globals.state, globals.nixExprPath, drvs); + loadDerivations(globals.state, globals.nixExprPath, + drvs, globals.systemFilter); break; } @@ -702,6 +714,7 @@ void run(Strings args) globals.nixExprPath = getDefNixExprPath(); globals.dryRun = false; globals.preserveInstalled = false; + globals.systemFilter = thisSystem; for (Strings::iterator i = args.begin(); i != args.end(); ++i) { string arg = *i; @@ -744,6 +757,12 @@ void run(Strings args) } else if (arg == "--preserve-installed" || arg == "-P") 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] == '-') opFlags.push_back(arg); else |