mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-30 01:26:15 +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,32 +275,15 @@ static void createUserEnv(EvalState & state, const UserEnvElems & elems,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void queryInstSources(EvalState & state,
|
static UserEnvElems filterBySelector(const UserEnvElems & allElems,
|
||||||
const InstallSourceInfo & instSource, const Strings & args,
|
const Strings & args)
|
||||||
UserEnvElems & elems)
|
|
||||||
{
|
{
|
||||||
InstallSourceType type = instSource.type;
|
|
||||||
if (type == srcUnknown && args.size() > 0 && args.front()[0] == '/')
|
|
||||||
type = srcStorePaths;
|
|
||||||
|
|
||||||
switch (type) {
|
|
||||||
|
|
||||||
/* Get the available user environment elements from the
|
|
||||||
derivations specified in a Nix expression, including only
|
|
||||||
those with names matching any of the names in `args'. */
|
|
||||||
case srcUnknown:
|
|
||||||
case srcNixExprDrvs: {
|
|
||||||
|
|
||||||
DrvNames selectors = drvNamesFromArgs(args);
|
DrvNames selectors = drvNamesFromArgs(args);
|
||||||
|
|
||||||
/* Load the derivations from the (default or specified)
|
UserEnvElems elems;
|
||||||
Nix expression. */
|
|
||||||
UserEnvElems allElems;
|
|
||||||
loadDerivations(state, instSource.nixExprPath,
|
|
||||||
instSource.systemFilter, allElems);
|
|
||||||
|
|
||||||
/* Filter out the ones we're not interested in. */
|
/* Filter out the ones we're not interested in. */
|
||||||
for (UserEnvElems::iterator i = allElems.begin();
|
for (UserEnvElems::const_iterator i = allElems.begin();
|
||||||
i != allElems.end(); ++i)
|
i != allElems.end(); ++i)
|
||||||
{
|
{
|
||||||
DrvName drvName(i->second.name);
|
DrvName drvName(i->second.name);
|
||||||
|
@ -319,6 +304,34 @@ static void queryInstSources(EvalState & state,
|
||||||
throw Error(format("selector `%1%' matches no derivations")
|
throw Error(format("selector `%1%' matches no derivations")
|
||||||
% i->fullName);
|
% i->fullName);
|
||||||
|
|
||||||
|
return elems;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void queryInstSources(EvalState & state,
|
||||||
|
const InstallSourceInfo & instSource, const Strings & args,
|
||||||
|
UserEnvElems & elems)
|
||||||
|
{
|
||||||
|
InstallSourceType type = instSource.type;
|
||||||
|
if (type == srcUnknown && args.size() > 0 && args.front()[0] == '/')
|
||||||
|
type = srcStorePaths;
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
|
||||||
|
/* Get the available user environment elements from the
|
||||||
|
derivations specified in a Nix expression, including only
|
||||||
|
those with names matching any of the names in `args'. */
|
||||||
|
case srcUnknown:
|
||||||
|
case srcNixExprDrvs: {
|
||||||
|
|
||||||
|
/* Load the derivations from the (default or specified)
|
||||||
|
Nix expression. */
|
||||||
|
UserEnvElems allElems;
|
||||||
|
loadDerivations(state, instSource.nixExprPath,
|
||||||
|
instSource.systemFilter, allElems);
|
||||||
|
|
||||||
|
elems = filterBySelector(allElems, args);
|
||||||
|
|
||||||
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