mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-26 15:56:18 +02:00
* And yet another installation source: the ability to copy user
environment elements from one user environment to another, e.g., $ nix-env -i --from-profile /nix/var/nix/profiles/other-profile aterm copies the `aterm' component installed in the `other-profile' to the user's current profile.
This commit is contained in:
parent
0083562f75
commit
e17910cfb5
1 changed files with 46 additions and 34 deletions
|
@ -169,12 +169,12 @@ struct AddPos : TermFun
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static void queryInstalled(EvalState & state, UserEnvElems & elems,
|
static UserEnvElems queryInstalled(EvalState & state, const Path & userEnv)
|
||||||
const Path & userEnv)
|
|
||||||
{
|
{
|
||||||
Path path = userEnv + "/manifest";
|
Path path = userEnv + "/manifest";
|
||||||
|
|
||||||
if (!pathExists(path)) return; /* not an error, assume nothing installed */
|
if (!pathExists(path))
|
||||||
|
return UserEnvElems(); /* not an error, assume nothing installed */
|
||||||
|
|
||||||
Expr e = ATreadFromNamedFile(path.c_str());
|
Expr e = ATreadFromNamedFile(path.c_str());
|
||||||
if (!e) throw Error(format("cannot read Nix expression from `%1%'") % path);
|
if (!e) throw Error(format("cannot read Nix expression from `%1%'") % path);
|
||||||
|
@ -183,7 +183,9 @@ static void queryInstalled(EvalState & state, UserEnvElems & elems,
|
||||||
AddPos addPos;
|
AddPos addPos;
|
||||||
e = bottomupRewrite(addPos, e);
|
e = bottomupRewrite(addPos, e);
|
||||||
|
|
||||||
|
UserEnvElems elems;
|
||||||
parseDerivations(state, e, elems);
|
parseDerivations(state, e, elems);
|
||||||
|
return elems;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -273,6 +275,39 @@ static void createUserEnv(EvalState & state, const UserEnvElems & elems,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static UserEnvElems filterBySelector(const UserEnvElems & allElems,
|
||||||
|
const Strings & args)
|
||||||
|
{
|
||||||
|
DrvNames selectors = drvNamesFromArgs(args);
|
||||||
|
|
||||||
|
UserEnvElems elems;
|
||||||
|
|
||||||
|
/* Filter out the ones we're not interested in. */
|
||||||
|
for (UserEnvElems::const_iterator i = allElems.begin();
|
||||||
|
i != allElems.end(); ++i)
|
||||||
|
{
|
||||||
|
DrvName drvName(i->second.name);
|
||||||
|
for (DrvNames::iterator j = selectors.begin();
|
||||||
|
j != selectors.end(); ++j)
|
||||||
|
{
|
||||||
|
if (j->matches(drvName)) {
|
||||||
|
j->hits++;
|
||||||
|
elems.insert(*i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check that all selectors have been used. */
|
||||||
|
for (DrvNames::iterator i = selectors.begin();
|
||||||
|
i != selectors.end(); ++i)
|
||||||
|
if (i->hits == 0)
|
||||||
|
throw Error(format("selector `%1%' matches no derivations")
|
||||||
|
% i->fullName);
|
||||||
|
|
||||||
|
return elems;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void queryInstSources(EvalState & state,
|
static void queryInstSources(EvalState & state,
|
||||||
const InstallSourceInfo & instSource, const Strings & args,
|
const InstallSourceInfo & instSource, const Strings & args,
|
||||||
UserEnvElems & elems)
|
UserEnvElems & elems)
|
||||||
|
@ -289,35 +324,13 @@ static void queryInstSources(EvalState & state,
|
||||||
case srcUnknown:
|
case srcUnknown:
|
||||||
case srcNixExprDrvs: {
|
case srcNixExprDrvs: {
|
||||||
|
|
||||||
DrvNames selectors = drvNamesFromArgs(args);
|
|
||||||
|
|
||||||
/* Load the derivations from the (default or specified)
|
/* Load the derivations from the (default or specified)
|
||||||
Nix expression. */
|
Nix expression. */
|
||||||
UserEnvElems allElems;
|
UserEnvElems allElems;
|
||||||
loadDerivations(state, instSource.nixExprPath,
|
loadDerivations(state, instSource.nixExprPath,
|
||||||
instSource.systemFilter, allElems);
|
instSource.systemFilter, allElems);
|
||||||
|
|
||||||
/* Filter out the ones we're not interested in. */
|
elems = filterBySelector(allElems, args);
|
||||||
for (UserEnvElems::iterator i = allElems.begin();
|
|
||||||
i != allElems.end(); ++i)
|
|
||||||
{
|
|
||||||
DrvName drvName(i->second.name);
|
|
||||||
for (DrvNames::iterator j = selectors.begin();
|
|
||||||
j != selectors.end(); ++j)
|
|
||||||
{
|
|
||||||
if (j->matches(drvName)) {
|
|
||||||
j->hits++;
|
|
||||||
elems.insert(*i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check that all selectors have been used. */
|
|
||||||
for (DrvNames::iterator i = selectors.begin();
|
|
||||||
i != selectors.end(); ++i)
|
|
||||||
if (i->hits == 0)
|
|
||||||
throw Error(format("selector `%1%' matches no derivations")
|
|
||||||
% i->fullName);
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -373,6 +386,8 @@ static void queryInstSources(EvalState & state,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case srcProfile:
|
case srcProfile:
|
||||||
|
elems = filterBySelector(
|
||||||
|
queryInstalled(state, instSource.profile), args);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -396,8 +411,7 @@ static void installDerivations(Globals & globals,
|
||||||
|
|
||||||
/* Add in the already installed derivations, unless they have the
|
/* Add in the already installed derivations, unless they have the
|
||||||
same name as a to-be-installed element. */
|
same name as a to-be-installed element. */
|
||||||
UserEnvElems installedElems;
|
UserEnvElems installedElems = queryInstalled(globals.state, profile);
|
||||||
queryInstalled(globals.state, installedElems, profile);
|
|
||||||
|
|
||||||
for (UserEnvElems::iterator i = installedElems.begin();
|
for (UserEnvElems::iterator i = installedElems.begin();
|
||||||
i != installedElems.end(); ++i)
|
i != installedElems.end(); ++i)
|
||||||
|
@ -443,8 +457,7 @@ static void upgradeDerivations(Globals & globals,
|
||||||
name and a higher version number. */
|
name and a higher version number. */
|
||||||
|
|
||||||
/* Load the currently installed derivations. */
|
/* Load the currently installed derivations. */
|
||||||
UserEnvElems installedElems;
|
UserEnvElems installedElems = queryInstalled(globals.state, profile);
|
||||||
queryInstalled(globals.state, installedElems, profile);
|
|
||||||
|
|
||||||
/* Fetch all derivations from the input file. */
|
/* Fetch all derivations from the input file. */
|
||||||
UserEnvElems availElems;
|
UserEnvElems availElems;
|
||||||
|
@ -519,8 +532,7 @@ static void opUpgrade(Globals & globals,
|
||||||
static void uninstallDerivations(Globals & globals, DrvNames & selectors,
|
static void uninstallDerivations(Globals & globals, DrvNames & selectors,
|
||||||
Path & profile)
|
Path & profile)
|
||||||
{
|
{
|
||||||
UserEnvElems installedElems;
|
UserEnvElems installedElems = queryInstalled(globals.state, profile);
|
||||||
queryInstalled(globals.state, installedElems, profile);
|
|
||||||
|
|
||||||
for (UserEnvElems::iterator i = installedElems.begin();
|
for (UserEnvElems::iterator i = installedElems.begin();
|
||||||
i != installedElems.end(); ++i)
|
i != installedElems.end(); ++i)
|
||||||
|
@ -631,7 +643,7 @@ static void opQuery(Globals & globals,
|
||||||
switch (source) {
|
switch (source) {
|
||||||
|
|
||||||
case sInstalled:
|
case sInstalled:
|
||||||
queryInstalled(globals.state, elems, globals.profile);
|
elems = queryInstalled(globals.state, globals.profile);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case sAvailable: {
|
case sAvailable: {
|
||||||
|
@ -656,7 +668,7 @@ static void opQuery(Globals & globals,
|
||||||
UserEnvElems installed; /* installed paths */
|
UserEnvElems installed; /* installed paths */
|
||||||
|
|
||||||
if (printStatus)
|
if (printStatus)
|
||||||
queryInstalled(globals.state, installed, globals.profile);
|
installed = queryInstalled(globals.state, globals.profile);
|
||||||
|
|
||||||
/* Print the desired columns. */
|
/* Print the desired columns. */
|
||||||
Table table;
|
Table table;
|
||||||
|
|
Loading…
Reference in a new issue