2004-02-06 16:57:10 +02:00
|
|
|
#include "profiles.hh"
|
2004-02-06 16:49:41 +02:00
|
|
|
#include "names.hh"
|
2003-11-19 19:27:16 +02:00
|
|
|
#include "globals.hh"
|
2005-01-19 18:39:47 +02:00
|
|
|
#include "build.hh"
|
2006-03-06 13:21:15 +02:00
|
|
|
#include "misc.hh"
|
2005-02-14 19:35:10 +02:00
|
|
|
#include "gc.hh"
|
2003-11-19 19:27:16 +02:00
|
|
|
#include "shared.hh"
|
|
|
|
#include "parser.hh"
|
|
|
|
#include "eval.hh"
|
2003-12-01 17:55:05 +02:00
|
|
|
#include "help.txt.hh"
|
2004-10-29 14:22:49 +03:00
|
|
|
#include "nixexpr-ast.hh"
|
2006-02-08 15:21:16 +02:00
|
|
|
#include "get-drvs.hh"
|
2006-07-26 18:05:15 +03:00
|
|
|
#include "attr-path.hh"
|
2006-06-15 14:56:49 +03:00
|
|
|
#include "pathlocks.hh"
|
2006-08-03 18:52:09 +03:00
|
|
|
#include "xml-writer.hh"
|
2006-09-05 00:06:23 +03:00
|
|
|
#include "store.hh"
|
|
|
|
#include "db.hh"
|
|
|
|
#include "util.hh"
|
2003-11-19 19:27:16 +02:00
|
|
|
|
2004-02-06 18:03:27 +02:00
|
|
|
#include <cerrno>
|
|
|
|
#include <ctime>
|
2005-05-04 19:33:20 +03:00
|
|
|
#include <algorithm>
|
2006-03-01 19:44:28 +02:00
|
|
|
#include <iostream>
|
2006-08-03 18:52:09 +03:00
|
|
|
#include <sstream>
|
2004-02-06 18:03:27 +02:00
|
|
|
|
2005-10-06 18:01:46 +03:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2003-11-19 19:27:16 +02:00
|
|
|
|
2006-09-05 00:06:23 +03:00
|
|
|
using namespace nix;
|
|
|
|
using std::cout;
|
|
|
|
|
|
|
|
|
2005-02-11 18:56:45 +02:00
|
|
|
typedef enum {
|
|
|
|
srcNixExprDrvs,
|
|
|
|
srcNixExprs,
|
|
|
|
srcStorePaths,
|
|
|
|
srcProfile,
|
2006-07-25 14:53:22 +03:00
|
|
|
srcAttrPath,
|
2005-02-11 18:56:45 +02:00
|
|
|
srcUnknown
|
|
|
|
} InstallSourceType;
|
|
|
|
|
|
|
|
|
|
|
|
struct InstallSourceInfo
|
|
|
|
{
|
|
|
|
InstallSourceType type;
|
|
|
|
Path nixExprPath; /* for srcNixExprDrvs, srcNixExprs */
|
|
|
|
Path profile; /* for srcProfile */
|
|
|
|
string systemFilter; /* for srcNixExprDrvs */
|
2006-08-23 19:33:21 +03:00
|
|
|
ATermMap autoArgs;
|
|
|
|
InstallSourceInfo() : autoArgs(128) { };
|
2005-02-11 18:56:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-12-22 00:34:41 +02:00
|
|
|
struct Globals
|
|
|
|
{
|
2005-02-11 18:56:45 +02:00
|
|
|
InstallSourceInfo instSource;
|
2004-02-06 12:30:20 +02:00
|
|
|
Path profile;
|
2003-12-22 00:34:41 +02:00
|
|
|
EvalState state;
|
2004-02-09 13:59:39 +02:00
|
|
|
bool dryRun;
|
2004-06-28 17:40:26 +03:00
|
|
|
bool preserveInstalled;
|
2005-02-14 15:07:09 +02:00
|
|
|
bool keepDerivations;
|
2006-09-25 17:00:59 +03:00
|
|
|
string forceName;
|
2003-12-22 00:34:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
typedef void (* Operation) (Globals & globals,
|
2003-11-19 19:27:16 +02:00
|
|
|
Strings opFlags, Strings opArgs);
|
|
|
|
|
|
|
|
|
2003-12-01 17:55:05 +02:00
|
|
|
void printHelp()
|
|
|
|
{
|
|
|
|
cout << string((char *) helpText, sizeof helpText);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-11 18:56:45 +02:00
|
|
|
static void loadDerivations(EvalState & state, Path nixExprPath,
|
2006-08-23 19:33:21 +03:00
|
|
|
string systemFilter, const ATermMap & autoArgs, DrvInfos & elems)
|
2003-11-19 19:27:16 +02:00
|
|
|
{
|
2006-02-08 15:21:16 +02:00
|
|
|
getDerivations(state,
|
2006-08-23 19:33:21 +03:00
|
|
|
parseExprFromFile(state, absPath(nixExprPath)), "", autoArgs, elems);
|
2004-07-01 16:56:56 +03:00
|
|
|
|
|
|
|
/* Filter out all derivations not applicable to the current
|
|
|
|
system. */
|
2006-02-08 15:21:16 +02:00
|
|
|
for (DrvInfos::iterator i = elems.begin(), j; i != elems.end(); i = j) {
|
2004-07-01 16:56:56 +03:00
|
|
|
j = i; j++;
|
2006-02-08 15:21:16 +02:00
|
|
|
if (systemFilter != "*" && i->system != systemFilter)
|
2005-02-14 18:16:02 +02:00
|
|
|
elems.erase(i);
|
2005-02-11 18:56:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-01-05 18:26:43 +02:00
|
|
|
static Path getHomeDir()
|
|
|
|
{
|
2004-05-12 12:35:51 +03:00
|
|
|
Path homeDir(getEnv("HOME", ""));
|
2004-01-05 18:26:43 +02:00
|
|
|
if (homeDir == "") throw Error("HOME environment variable not set");
|
|
|
|
return homeDir;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Path getDefNixExprPath()
|
|
|
|
{
|
|
|
|
return getHomeDir() + "/.nix-defexpr";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-04-06 01:27:41 +03:00
|
|
|
struct AddPos : TermFun
|
|
|
|
{
|
|
|
|
ATerm operator () (ATerm e)
|
|
|
|
{
|
|
|
|
ATerm x, y, z;
|
2004-10-27 01:54:26 +03:00
|
|
|
if (matchBind(e, x, y, z)) return e;
|
|
|
|
if (matchBind2(e, x, y))
|
|
|
|
return makeBind(x, y, makeNoPos());
|
2004-04-06 01:27:41 +03:00
|
|
|
return e;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-02-08 15:21:16 +02:00
|
|
|
static DrvInfos queryInstalled(EvalState & state, const Path & userEnv)
|
2003-11-19 23:32:03 +02:00
|
|
|
{
|
2003-12-22 00:34:41 +02:00
|
|
|
Path path = userEnv + "/manifest";
|
2003-11-19 23:32:03 +02:00
|
|
|
|
2005-02-15 12:49:31 +02:00
|
|
|
if (!pathExists(path))
|
2006-02-08 15:21:16 +02:00
|
|
|
return DrvInfos(); /* not an error, assume nothing installed */
|
2003-11-19 23:32:03 +02:00
|
|
|
|
|
|
|
Expr e = ATreadFromNamedFile(path.c_str());
|
|
|
|
if (!e) throw Error(format("cannot read Nix expression from `%1%'") % path);
|
|
|
|
|
2004-04-06 01:27:41 +03:00
|
|
|
/* Compatibility: Bind(x, y) -> Bind(x, y, NoPos). */
|
|
|
|
AddPos addPos;
|
|
|
|
e = bottomupRewrite(addPos, e);
|
|
|
|
|
2006-02-08 15:21:16 +02:00
|
|
|
DrvInfos elems;
|
2006-07-28 19:03:28 +03:00
|
|
|
getDerivations(state, e, "", ATermMap(1), elems);
|
2005-02-15 12:49:31 +02:00
|
|
|
return elems;
|
2003-11-19 23:32:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-08 15:21:16 +02:00
|
|
|
static void createUserEnv(EvalState & state, const DrvInfos & elems,
|
2005-02-14 15:07:09 +02:00
|
|
|
const Path & profile, bool keepDerivations)
|
2003-11-19 19:27:16 +02:00
|
|
|
{
|
2005-02-11 18:56:45 +02:00
|
|
|
/* Build the components in the user environment, if they don't
|
|
|
|
exist already. */
|
|
|
|
PathSet drvsToBuild;
|
2006-02-08 15:21:16 +02:00
|
|
|
for (DrvInfos::const_iterator i = elems.begin();
|
2005-02-14 18:16:02 +02:00
|
|
|
i != elems.end(); ++i)
|
2005-02-17 17:48:50 +02:00
|
|
|
/* Call to `isDerivation' is for compatibility with Nix <= 0.7
|
|
|
|
user environments. */
|
2006-02-08 15:21:16 +02:00
|
|
|
if (i->queryDrvPath(state) != "" &&
|
|
|
|
isDerivation(i->queryDrvPath(state)))
|
|
|
|
drvsToBuild.insert(i->queryDrvPath(state));
|
2005-02-11 18:56:45 +02:00
|
|
|
|
|
|
|
debug(format("building user environment dependencies"));
|
|
|
|
buildDerivations(drvsToBuild);
|
|
|
|
|
2003-11-19 19:27:16 +02:00
|
|
|
/* Get the environment builder expression. */
|
2004-02-04 18:03:29 +02:00
|
|
|
Expr envBuilder = parseExprFromFile(state,
|
|
|
|
nixDataDir + "/nix/corepkgs/buildenv"); /* !!! */
|
2003-11-19 19:27:16 +02:00
|
|
|
|
|
|
|
/* Construct the whole top level derivation. */
|
2005-02-11 18:56:45 +02:00
|
|
|
PathSet references;
|
|
|
|
ATermList manifest = ATempty;
|
2003-11-19 19:27:16 +02:00
|
|
|
ATermList inputs = ATempty;
|
2006-02-08 15:21:16 +02:00
|
|
|
for (DrvInfos::const_iterator i = elems.begin();
|
2005-02-14 18:16:02 +02:00
|
|
|
i != elems.end(); ++i)
|
2003-11-19 19:27:16 +02:00
|
|
|
{
|
2006-02-08 15:21:16 +02:00
|
|
|
Path drvPath = keepDerivations ? i->queryDrvPath(state) : "";
|
2005-02-14 15:07:09 +02:00
|
|
|
ATerm t = makeAttrs(ATmakeList5(
|
2004-11-03 20:12:03 +02:00
|
|
|
makeBind(toATerm("type"),
|
2006-10-16 18:55:34 +03:00
|
|
|
makeStr("derivation"), makeNoPos()),
|
2004-11-03 20:12:03 +02:00
|
|
|
makeBind(toATerm("name"),
|
2006-10-16 18:55:34 +03:00
|
|
|
makeStr(i->name), makeNoPos()),
|
2004-11-03 20:12:03 +02:00
|
|
|
makeBind(toATerm("system"),
|
2006-10-16 18:55:34 +03:00
|
|
|
makeStr(i->system), makeNoPos()),
|
2005-02-14 15:07:09 +02:00
|
|
|
makeBind(toATerm("drvPath"),
|
2006-10-16 18:55:34 +03:00
|
|
|
makeStr(drvPath), makeNoPos()),
|
2004-11-03 20:12:03 +02:00
|
|
|
makeBind(toATerm("outPath"),
|
2006-10-16 18:55:34 +03:00
|
|
|
makeStr(i->queryOutPath(state)), makeNoPos())
|
2004-10-27 01:54:26 +03:00
|
|
|
));
|
2005-02-11 18:56:45 +02:00
|
|
|
manifest = ATinsert(manifest, t);
|
2006-10-16 18:55:34 +03:00
|
|
|
inputs = ATinsert(inputs, makeStr(i->queryOutPath(state)));
|
2005-02-14 19:35:10 +02:00
|
|
|
|
|
|
|
/* This is only necessary when installing store paths, e.g.,
|
|
|
|
`nix-env -i /nix/store/abcd...-foo'. */
|
2006-02-08 15:21:16 +02:00
|
|
|
addTempRoot(i->queryOutPath(state));
|
|
|
|
ensurePath(i->queryOutPath(state));
|
2005-02-14 19:35:10 +02:00
|
|
|
|
2006-02-08 15:21:16 +02:00
|
|
|
references.insert(i->queryOutPath(state));
|
2005-02-14 15:07:09 +02:00
|
|
|
if (drvPath != "") references.insert(drvPath);
|
2003-11-19 19:27:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Also write a copy of the list of inputs to the store; we need
|
|
|
|
it for future modifications of the environment. */
|
2005-02-11 18:56:45 +02:00
|
|
|
Path manifestFile = addTextToStore("env-manifest",
|
|
|
|
atPrint(makeList(ATreverse(manifest))), references);
|
|
|
|
|
2004-10-27 01:54:26 +03:00
|
|
|
Expr topLevel = makeCall(envBuilder, makeAttrs(ATmakeList3(
|
2004-11-03 20:12:03 +02:00
|
|
|
makeBind(toATerm("system"),
|
2006-10-16 18:55:34 +03:00
|
|
|
makeStr(thisSystem), makeNoPos()),
|
2005-02-11 18:56:45 +02:00
|
|
|
makeBind(toATerm("derivations"),
|
|
|
|
makeList(ATreverse(inputs)), makeNoPos()),
|
2004-11-03 20:12:03 +02:00
|
|
|
makeBind(toATerm("manifest"),
|
2006-10-16 18:55:34 +03:00
|
|
|
makeStr(manifestFile), makeNoPos())
|
2004-10-27 01:54:26 +03:00
|
|
|
)));
|
2003-11-19 19:27:16 +02:00
|
|
|
|
|
|
|
/* Instantiate it. */
|
|
|
|
debug(format("evaluating builder expression `%1%'") % topLevel);
|
2006-02-08 15:21:16 +02:00
|
|
|
DrvInfo topLevelDrv;
|
|
|
|
if (!getDerivation(state, topLevel, topLevelDrv))
|
2003-11-19 19:27:16 +02:00
|
|
|
abort();
|
|
|
|
|
|
|
|
/* Realise the resulting store expression. */
|
2005-01-19 13:16:11 +02:00
|
|
|
debug(format("building user environment"));
|
2005-05-08 13:32:09 +03:00
|
|
|
buildDerivations(singleton<PathSet>(topLevelDrv.queryDrvPath(state)));
|
2003-11-19 19:27:16 +02:00
|
|
|
|
|
|
|
/* Switch the current user environment to the output path. */
|
|
|
|
debug(format("switching to new user environment"));
|
2005-05-08 13:32:09 +03:00
|
|
|
Path generation = createGeneration(profile, topLevelDrv.queryOutPath(state));
|
2004-02-06 12:30:20 +02:00
|
|
|
switchLink(profile, generation);
|
2003-11-19 19:27:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-17 19:47:54 +02:00
|
|
|
static DrvInfos filterBySelector(EvalState & state,
|
|
|
|
const DrvInfos & allElems,
|
|
|
|
const Strings & args, bool newestOnly)
|
2005-02-15 12:49:31 +02:00
|
|
|
{
|
|
|
|
DrvNames selectors = drvNamesFromArgs(args);
|
|
|
|
|
2006-02-08 15:21:16 +02:00
|
|
|
DrvInfos elems;
|
2006-03-10 12:24:46 +02:00
|
|
|
set<unsigned int> done;
|
2005-02-15 12:49:31 +02:00
|
|
|
|
2006-02-17 19:47:54 +02:00
|
|
|
for (DrvNames::iterator i = selectors.begin();
|
|
|
|
i != selectors.end(); ++i)
|
|
|
|
{
|
2006-09-05 00:06:23 +03:00
|
|
|
typedef list<std::pair<DrvInfo, unsigned int> > Matches;
|
2006-03-10 12:24:46 +02:00
|
|
|
Matches matches;
|
|
|
|
unsigned int n = 0;
|
2006-02-17 19:47:54 +02:00
|
|
|
for (DrvInfos::const_iterator j = allElems.begin();
|
2006-03-10 12:24:46 +02:00
|
|
|
j != allElems.end(); ++j, ++n)
|
2006-02-17 19:47:54 +02:00
|
|
|
{
|
|
|
|
DrvName drvName(j->name);
|
|
|
|
if (i->matches(drvName)) {
|
|
|
|
i->hits++;
|
2006-09-05 00:06:23 +03:00
|
|
|
matches.push_back(std::pair<DrvInfo, unsigned int>(*j, n));
|
2006-02-17 19:47:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-17 20:11:45 +02:00
|
|
|
/* If `newestOnly', if a selector matches multiple derivations
|
|
|
|
with the same name, pick the one with the highest version.
|
|
|
|
If there are multiple derivations with the same name *and*
|
|
|
|
version, then pick the first one. */
|
2006-02-17 19:47:54 +02:00
|
|
|
if (newestOnly) {
|
|
|
|
|
|
|
|
/* Map from package names to derivations. */
|
2006-09-05 00:06:23 +03:00
|
|
|
typedef map<string, std::pair<DrvInfo, unsigned int> > Newest;
|
2006-03-10 12:24:46 +02:00
|
|
|
Newest newest;
|
2006-02-17 20:11:45 +02:00
|
|
|
StringSet multiple;
|
2006-02-17 19:47:54 +02:00
|
|
|
|
2006-03-10 12:24:46 +02:00
|
|
|
for (Matches::iterator j = matches.begin(); j != matches.end(); ++j) {
|
|
|
|
DrvName drvName(j->first.name);
|
|
|
|
Newest::iterator k = newest.find(drvName.name);
|
2006-02-17 20:11:45 +02:00
|
|
|
if (k != newest.end()) {
|
2006-03-10 12:24:46 +02:00
|
|
|
int d = compareVersions(drvName.version, DrvName(k->second.first.name).version);
|
2006-02-17 20:11:45 +02:00
|
|
|
if (d > 0) newest[drvName.name] = *j;
|
2006-03-10 12:24:46 +02:00
|
|
|
else if (d == 0) multiple.insert(j->first.name);
|
2006-02-17 20:11:45 +02:00
|
|
|
} else
|
2006-02-17 19:47:54 +02:00
|
|
|
newest[drvName.name] = *j;
|
|
|
|
}
|
|
|
|
|
|
|
|
matches.clear();
|
2006-03-10 12:24:46 +02:00
|
|
|
for (Newest::iterator j = newest.begin(); j != newest.end(); ++j) {
|
|
|
|
if (multiple.find(j->second.first.name) != multiple.end())
|
2006-02-17 20:11:45 +02:00
|
|
|
printMsg(lvlInfo,
|
|
|
|
format("warning: there are multiple derivations named `%1%'; using the first one")
|
2006-03-10 12:24:46 +02:00
|
|
|
% j->second.first.name);
|
2006-02-17 19:47:54 +02:00
|
|
|
matches.push_back(j->second);
|
2006-02-17 20:11:45 +02:00
|
|
|
}
|
2006-02-17 19:47:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Insert only those elements in the final list that we
|
|
|
|
haven't inserted before. */
|
2006-03-10 12:24:46 +02:00
|
|
|
for (Matches::iterator j = matches.begin(); j != matches.end(); ++j)
|
|
|
|
if (done.find(j->second) == done.end()) {
|
|
|
|
done.insert(j->second);
|
|
|
|
elems.push_back(j->first);
|
2006-02-17 19:47:54 +02:00
|
|
|
}
|
|
|
|
}
|
2005-02-15 12:49:31 +02:00
|
|
|
|
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-14 18:16:02 +02:00
|
|
|
static void queryInstSources(EvalState & state,
|
|
|
|
const InstallSourceInfo & instSource, const Strings & args,
|
2006-02-17 19:47:54 +02:00
|
|
|
DrvInfos & elems, bool newestOnly)
|
2003-11-20 15:48:48 +02:00
|
|
|
{
|
2005-02-14 19:35:10 +02:00
|
|
|
InstallSourceType type = instSource.type;
|
|
|
|
if (type == srcUnknown && args.size() > 0 && args.front()[0] == '/')
|
|
|
|
type = srcStorePaths;
|
|
|
|
|
|
|
|
switch (type) {
|
2003-11-20 15:48:48 +02:00
|
|
|
|
2005-02-14 18:16:02 +02:00
|
|
|
/* 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. */
|
2006-02-08 15:21:16 +02:00
|
|
|
DrvInfos allElems;
|
2005-02-14 18:16:02 +02:00
|
|
|
loadDerivations(state, instSource.nixExprPath,
|
2006-08-23 19:33:21 +03:00
|
|
|
instSource.systemFilter, instSource.autoArgs, allElems);
|
2005-02-14 18:16:02 +02:00
|
|
|
|
2006-02-17 19:47:54 +02:00
|
|
|
elems = filterBySelector(state, allElems, args, newestOnly);
|
2005-02-14 18:16:02 +02:00
|
|
|
|
|
|
|
break;
|
2003-11-24 13:01:19 +02:00
|
|
|
}
|
2005-02-14 18:16:02 +02:00
|
|
|
|
2005-02-14 19:07:43 +02:00
|
|
|
/* Get the available user environment elements from the Nix
|
|
|
|
expressions specified on the command line; these should be
|
|
|
|
functions that take the default Nix expression file as
|
|
|
|
argument, e.g., if the file is `./foo.nix', then the
|
|
|
|
argument `x: x.bar' is equivalent to `(x: x.bar)
|
|
|
|
(import ./foo.nix)' = `(import ./foo.nix).bar'. */
|
2005-02-15 14:05:47 +02:00
|
|
|
case srcNixExprs: {
|
|
|
|
|
2005-02-14 19:07:43 +02:00
|
|
|
|
|
|
|
Expr e1 = parseExprFromFile(state,
|
|
|
|
absPath(instSource.nixExprPath));
|
|
|
|
|
|
|
|
for (Strings::const_iterator i = args.begin();
|
|
|
|
i != args.end(); ++i)
|
|
|
|
{
|
|
|
|
Expr e2 = parseExprFromString(state, *i, absPath("."));
|
|
|
|
Expr call = makeCall(e2, e1);
|
2006-08-23 19:33:21 +03:00
|
|
|
getDerivations(state, call, "", instSource.autoArgs, elems);
|
2005-02-14 19:07:43 +02:00
|
|
|
}
|
|
|
|
|
2005-02-14 18:16:02 +02:00
|
|
|
break;
|
2005-02-15 14:05:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* The available user environment elements are specified as a
|
|
|
|
list of store paths (which may or may not be
|
|
|
|
derivations). */
|
|
|
|
case srcStorePaths: {
|
2005-02-14 19:35:10 +02:00
|
|
|
|
|
|
|
for (Strings::const_iterator i = args.begin();
|
|
|
|
i != args.end(); ++i)
|
|
|
|
{
|
|
|
|
assertStorePath(*i);
|
|
|
|
|
2006-02-08 15:21:16 +02:00
|
|
|
DrvInfo elem;
|
2006-09-05 00:06:23 +03:00
|
|
|
elem.attrs = boost::shared_ptr<ATermMap>(new ATermMap(0)); /* ugh... */
|
2005-02-14 19:35:10 +02:00
|
|
|
string name = baseNameOf(*i);
|
2006-05-11 05:19:43 +03:00
|
|
|
string::size_type dash = name.find('-');
|
2005-02-14 19:35:10 +02:00
|
|
|
if (dash != string::npos)
|
|
|
|
name = string(name, dash + 1);
|
|
|
|
|
|
|
|
if (isDerivation(*i)) {
|
2005-05-09 20:55:35 +03:00
|
|
|
elem.setDrvPath(*i);
|
|
|
|
elem.setOutPath(findOutput(derivationFromPath(*i), "out"));
|
2005-02-14 19:35:10 +02:00
|
|
|
if (name.size() >= drvExtension.size() &&
|
|
|
|
string(name, name.size() - drvExtension.size()) == drvExtension)
|
|
|
|
name = string(name, 0, name.size() - drvExtension.size());
|
|
|
|
}
|
2005-05-09 20:55:35 +03:00
|
|
|
else elem.setOutPath(*i);
|
2005-02-14 19:35:10 +02:00
|
|
|
|
|
|
|
elem.name = name;
|
2006-02-08 16:32:33 +02:00
|
|
|
|
|
|
|
elems.push_back(elem);
|
2005-02-14 19:35:10 +02:00
|
|
|
}
|
|
|
|
|
2005-02-14 18:16:02 +02:00
|
|
|
break;
|
2005-02-15 14:05:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the available user environment elements from another
|
|
|
|
user environment. These are then filtered as in the
|
|
|
|
`srcNixExprDrvs' case. */
|
|
|
|
case srcProfile: {
|
2006-02-17 19:47:54 +02:00
|
|
|
elems = filterBySelector(state,
|
|
|
|
queryInstalled(state, instSource.profile),
|
|
|
|
args, newestOnly);
|
2005-02-14 18:16:02 +02:00
|
|
|
break;
|
2005-02-15 14:05:47 +02:00
|
|
|
}
|
2006-07-25 14:53:22 +03:00
|
|
|
|
|
|
|
case srcAttrPath: {
|
|
|
|
for (Strings::const_iterator i = args.begin();
|
|
|
|
i != args.end(); ++i)
|
|
|
|
getDerivations(state,
|
2006-08-23 19:33:21 +03:00
|
|
|
findAlongAttrPath(state, *i, instSource.autoArgs,
|
2006-07-26 18:05:15 +03:00
|
|
|
parseExprFromFile(state, instSource.nixExprPath)),
|
2006-08-23 19:33:21 +03:00
|
|
|
"", instSource.autoArgs, elems);
|
2006-07-25 14:53:22 +03:00
|
|
|
break;
|
|
|
|
}
|
2003-11-20 15:48:48 +02:00
|
|
|
}
|
2005-02-14 18:16:02 +02:00
|
|
|
}
|
2003-11-20 15:48:48 +02:00
|
|
|
|
2004-06-28 17:40:26 +03:00
|
|
|
|
2006-03-06 13:21:15 +02:00
|
|
|
static void printMissing(EvalState & state, const DrvInfos & elems)
|
|
|
|
{
|
|
|
|
PathSet targets, willBuild, willSubstitute;
|
|
|
|
for (DrvInfos::const_iterator i = elems.begin(); i != elems.end(); ++i) {
|
|
|
|
Path drvPath = i->queryDrvPath(state);
|
|
|
|
if (drvPath != "")
|
|
|
|
targets.insert(drvPath);
|
|
|
|
else
|
|
|
|
targets.insert(i->queryOutPath(state));
|
|
|
|
}
|
|
|
|
|
|
|
|
queryMissing(targets, willBuild, willSubstitute);
|
|
|
|
|
|
|
|
if (!willBuild.empty()) {
|
|
|
|
printMsg(lvlInfo, format("the following derivations will be built:"));
|
|
|
|
for (PathSet::iterator i = willBuild.begin(); i != willBuild.end(); ++i)
|
|
|
|
printMsg(lvlInfo, format(" %1%") % *i);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!willSubstitute.empty()) {
|
|
|
|
printMsg(lvlInfo, format("the following paths will be substituted:"));
|
|
|
|
for (PathSet::iterator i = willSubstitute.begin(); i != willSubstitute.end(); ++i)
|
|
|
|
printMsg(lvlInfo, format(" %1%") % *i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-15 14:56:49 +03:00
|
|
|
static void lockProfile(PathLocks & lock, const Path & profile)
|
|
|
|
{
|
|
|
|
lock.lockPaths(singleton<PathSet>(profile),
|
|
|
|
(format("waiting for lock on profile `%1%'") % profile).str());
|
|
|
|
lock.setDeletion(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-14 18:16:02 +02:00
|
|
|
static void installDerivations(Globals & globals,
|
|
|
|
const Strings & args, const Path & profile)
|
|
|
|
{
|
|
|
|
debug(format("installing derivations"));
|
|
|
|
|
|
|
|
/* Get the set of user environment elements to be installed. */
|
2006-02-08 15:21:16 +02:00
|
|
|
DrvInfos newElems;
|
2006-02-17 19:47:54 +02:00
|
|
|
queryInstSources(globals.state, globals.instSource, args, newElems, true);
|
2005-02-14 18:16:02 +02:00
|
|
|
|
|
|
|
StringSet newNames;
|
2006-09-25 17:00:59 +03:00
|
|
|
for (DrvInfos::iterator i = newElems.begin(); i != newElems.end(); ++i) {
|
|
|
|
/* `forceName' is a hack to get package names right in some
|
|
|
|
one-click installs, namely those where the name used in the
|
|
|
|
path is not the one we want (e.g., `java-front' versus
|
|
|
|
`java-front-0.9pre15899'). */
|
|
|
|
if (globals.forceName != "")
|
|
|
|
i->name = globals.forceName;
|
2006-02-08 15:21:16 +02:00
|
|
|
newNames.insert(DrvName(i->name).name);
|
2006-09-25 17:00:59 +03:00
|
|
|
}
|
2005-02-14 18:16:02 +02:00
|
|
|
|
|
|
|
/* Add in the already installed derivations, unless they have the
|
|
|
|
same name as a to-be-installed element. */
|
2006-06-15 14:56:49 +03:00
|
|
|
PathLocks lock;
|
|
|
|
lockProfile(lock, profile);
|
2006-02-08 15:21:16 +02:00
|
|
|
DrvInfos installedElems = queryInstalled(globals.state, profile);
|
2005-02-14 18:16:02 +02:00
|
|
|
|
2006-02-17 18:26:28 +02:00
|
|
|
DrvInfos allElems(newElems);
|
2006-02-08 15:21:16 +02:00
|
|
|
for (DrvInfos::iterator i = installedElems.begin();
|
2005-02-14 18:16:02 +02:00
|
|
|
i != installedElems.end(); ++i)
|
2004-06-28 17:40:26 +03:00
|
|
|
{
|
2006-02-08 15:21:16 +02:00
|
|
|
DrvName drvName(i->name);
|
2005-02-14 15:07:09 +02:00
|
|
|
if (!globals.preserveInstalled &&
|
2005-02-14 18:16:02 +02:00
|
|
|
newNames.find(drvName.name) != newNames.end())
|
2004-06-28 17:40:26 +03:00
|
|
|
printMsg(lvlInfo,
|
2006-02-17 18:26:28 +02:00
|
|
|
format("replacing old `%1%'") % i->name);
|
2004-06-28 17:40:26 +03:00
|
|
|
else
|
2006-02-17 18:26:28 +02:00
|
|
|
allElems.push_back(*i);
|
2004-06-28 17:40:26 +03:00
|
|
|
}
|
2003-11-20 15:48:48 +02:00
|
|
|
|
2006-02-17 18:26:28 +02:00
|
|
|
for (DrvInfos::iterator i = newElems.begin(); i != newElems.end(); ++i)
|
|
|
|
printMsg(lvlInfo,
|
|
|
|
format("installing `%1%'") % i->name);
|
|
|
|
|
2006-03-06 13:21:15 +02:00
|
|
|
if (globals.dryRun) {
|
|
|
|
printMissing(globals.state, newElems);
|
|
|
|
return;
|
|
|
|
}
|
2004-02-09 13:59:39 +02:00
|
|
|
|
2006-02-17 18:26:28 +02:00
|
|
|
createUserEnv(globals.state, allElems,
|
2005-02-14 15:07:09 +02:00
|
|
|
profile, globals.keepDerivations);
|
2003-11-20 15:48:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-22 00:34:41 +02:00
|
|
|
static void opInstall(Globals & globals,
|
2003-11-19 19:27:16 +02:00
|
|
|
Strings opFlags, Strings opArgs)
|
|
|
|
{
|
2003-12-22 00:34:41 +02:00
|
|
|
if (opFlags.size() > 0)
|
2006-07-25 14:53:22 +03:00
|
|
|
throw UsageError(format("unknown flag `%1%'") % opFlags.front());
|
2003-11-19 19:27:16 +02:00
|
|
|
|
2005-02-14 18:16:02 +02:00
|
|
|
installDerivations(globals, opArgs, globals.profile);
|
2003-12-22 01:58:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-27 15:17:25 +03:00
|
|
|
typedef enum { utLt, utLeq, utEq, utAlways } UpgradeType;
|
2004-02-09 13:59:39 +02:00
|
|
|
|
|
|
|
|
2005-02-14 15:07:09 +02:00
|
|
|
static void upgradeDerivations(Globals & globals,
|
2005-02-14 18:16:02 +02:00
|
|
|
const Strings & args, const Path & profile,
|
2005-02-14 15:07:09 +02:00
|
|
|
UpgradeType upgradeType)
|
* Upgrade operation in `nix-env'. For instance, you can say
nix-env -u foo.nix strategoxt
to replace the installed `strategoxt' derivation with the one from `foo.nix', if
the latter has a higher version number. This is a no-op if `strategoxt' is not
installed. Wildcards are also accepted, so
nix-env -u foo.nix '*'
will replace any installed derivation with newer versions from `foo.nix', if
available.
The notion of "version number" is somewhat ad hoc, but should be useful in most
cases, as evidenced by the following unit tests for the version comparator:
TEST("1.0", "2.3", -1);
TEST("2.1", "2.3", -1);
TEST("2.3", "2.3", 0);
TEST("2.5", "2.3", 1);
TEST("3.1", "2.3", 1);
TEST("2.3.1", "2.3", 1);
TEST("2.3.1", "2.3a", 1);
TEST("2.3pre1", "2.3", -1);
TEST("2.3pre3", "2.3pre12", -1);
TEST("2.3a", "2.3c", -1);
TEST("2.3pre1", "2.3c", -1);
TEST("2.3pre1", "2.3q", -1);
(-1 = less, 0 = equal, 1 = greater)
* A new verbosity level `lvlInfo', between `lvlError' and `lvlTalkative'. This is
the default for `nix-env', so without any `-v' flags users should get useful
output, e.g.,
$ nix-env -u foo.nix strategoxt
upgrading `strategoxt-0.9.2' to `strategoxt-0.9.3'
2003-12-22 18:04:00 +02:00
|
|
|
{
|
2005-02-11 18:56:45 +02:00
|
|
|
debug(format("upgrading derivations"));
|
* Upgrade operation in `nix-env'. For instance, you can say
nix-env -u foo.nix strategoxt
to replace the installed `strategoxt' derivation with the one from `foo.nix', if
the latter has a higher version number. This is a no-op if `strategoxt' is not
installed. Wildcards are also accepted, so
nix-env -u foo.nix '*'
will replace any installed derivation with newer versions from `foo.nix', if
available.
The notion of "version number" is somewhat ad hoc, but should be useful in most
cases, as evidenced by the following unit tests for the version comparator:
TEST("1.0", "2.3", -1);
TEST("2.1", "2.3", -1);
TEST("2.3", "2.3", 0);
TEST("2.5", "2.3", 1);
TEST("3.1", "2.3", 1);
TEST("2.3.1", "2.3", 1);
TEST("2.3.1", "2.3a", 1);
TEST("2.3pre1", "2.3", -1);
TEST("2.3pre3", "2.3pre12", -1);
TEST("2.3a", "2.3c", -1);
TEST("2.3pre1", "2.3c", -1);
TEST("2.3pre1", "2.3q", -1);
(-1 = less, 0 = equal, 1 = greater)
* A new verbosity level `lvlInfo', between `lvlError' and `lvlTalkative'. This is
the default for `nix-env', so without any `-v' flags users should get useful
output, e.g.,
$ nix-env -u foo.nix strategoxt
upgrading `strategoxt-0.9.2' to `strategoxt-0.9.3'
2003-12-22 18:04:00 +02:00
|
|
|
|
|
|
|
/* Upgrade works as follows: we take all currently installed
|
|
|
|
derivations, and for any derivation matching any selector, look
|
|
|
|
for a derivation in the input Nix expression that has the same
|
|
|
|
name and a higher version number. */
|
|
|
|
|
|
|
|
/* Load the currently installed derivations. */
|
2006-06-15 14:56:49 +03:00
|
|
|
PathLocks lock;
|
|
|
|
lockProfile(lock, profile);
|
2006-02-08 15:21:16 +02:00
|
|
|
DrvInfos installedElems = queryInstalled(globals.state, profile);
|
* Upgrade operation in `nix-env'. For instance, you can say
nix-env -u foo.nix strategoxt
to replace the installed `strategoxt' derivation with the one from `foo.nix', if
the latter has a higher version number. This is a no-op if `strategoxt' is not
installed. Wildcards are also accepted, so
nix-env -u foo.nix '*'
will replace any installed derivation with newer versions from `foo.nix', if
available.
The notion of "version number" is somewhat ad hoc, but should be useful in most
cases, as evidenced by the following unit tests for the version comparator:
TEST("1.0", "2.3", -1);
TEST("2.1", "2.3", -1);
TEST("2.3", "2.3", 0);
TEST("2.5", "2.3", 1);
TEST("3.1", "2.3", 1);
TEST("2.3.1", "2.3", 1);
TEST("2.3.1", "2.3a", 1);
TEST("2.3pre1", "2.3", -1);
TEST("2.3pre3", "2.3pre12", -1);
TEST("2.3a", "2.3c", -1);
TEST("2.3pre1", "2.3c", -1);
TEST("2.3pre1", "2.3q", -1);
(-1 = less, 0 = equal, 1 = greater)
* A new verbosity level `lvlInfo', between `lvlError' and `lvlTalkative'. This is
the default for `nix-env', so without any `-v' flags users should get useful
output, e.g.,
$ nix-env -u foo.nix strategoxt
upgrading `strategoxt-0.9.2' to `strategoxt-0.9.3'
2003-12-22 18:04:00 +02:00
|
|
|
|
|
|
|
/* Fetch all derivations from the input file. */
|
2006-02-08 15:21:16 +02:00
|
|
|
DrvInfos availElems;
|
2006-02-17 19:47:54 +02:00
|
|
|
queryInstSources(globals.state, globals.instSource, args, availElems, false);
|
* Upgrade operation in `nix-env'. For instance, you can say
nix-env -u foo.nix strategoxt
to replace the installed `strategoxt' derivation with the one from `foo.nix', if
the latter has a higher version number. This is a no-op if `strategoxt' is not
installed. Wildcards are also accepted, so
nix-env -u foo.nix '*'
will replace any installed derivation with newer versions from `foo.nix', if
available.
The notion of "version number" is somewhat ad hoc, but should be useful in most
cases, as evidenced by the following unit tests for the version comparator:
TEST("1.0", "2.3", -1);
TEST("2.1", "2.3", -1);
TEST("2.3", "2.3", 0);
TEST("2.5", "2.3", 1);
TEST("3.1", "2.3", 1);
TEST("2.3.1", "2.3", 1);
TEST("2.3.1", "2.3a", 1);
TEST("2.3pre1", "2.3", -1);
TEST("2.3pre3", "2.3pre12", -1);
TEST("2.3a", "2.3c", -1);
TEST("2.3pre1", "2.3c", -1);
TEST("2.3pre1", "2.3q", -1);
(-1 = less, 0 = equal, 1 = greater)
* A new verbosity level `lvlInfo', between `lvlError' and `lvlTalkative'. This is
the default for `nix-env', so without any `-v' flags users should get useful
output, e.g.,
$ nix-env -u foo.nix strategoxt
upgrading `strategoxt-0.9.2' to `strategoxt-0.9.3'
2003-12-22 18:04:00 +02:00
|
|
|
|
|
|
|
/* Go through all installed derivations. */
|
2006-02-08 15:21:16 +02:00
|
|
|
DrvInfos newElems;
|
|
|
|
for (DrvInfos::iterator i = installedElems.begin();
|
2005-02-14 18:16:02 +02:00
|
|
|
i != installedElems.end(); ++i)
|
* Upgrade operation in `nix-env'. For instance, you can say
nix-env -u foo.nix strategoxt
to replace the installed `strategoxt' derivation with the one from `foo.nix', if
the latter has a higher version number. This is a no-op if `strategoxt' is not
installed. Wildcards are also accepted, so
nix-env -u foo.nix '*'
will replace any installed derivation with newer versions from `foo.nix', if
available.
The notion of "version number" is somewhat ad hoc, but should be useful in most
cases, as evidenced by the following unit tests for the version comparator:
TEST("1.0", "2.3", -1);
TEST("2.1", "2.3", -1);
TEST("2.3", "2.3", 0);
TEST("2.5", "2.3", 1);
TEST("3.1", "2.3", 1);
TEST("2.3.1", "2.3", 1);
TEST("2.3.1", "2.3a", 1);
TEST("2.3pre1", "2.3", -1);
TEST("2.3pre3", "2.3pre12", -1);
TEST("2.3a", "2.3c", -1);
TEST("2.3pre1", "2.3c", -1);
TEST("2.3pre1", "2.3q", -1);
(-1 = less, 0 = equal, 1 = greater)
* A new verbosity level `lvlInfo', between `lvlError' and `lvlTalkative'. This is
the default for `nix-env', so without any `-v' flags users should get useful
output, e.g.,
$ nix-env -u foo.nix strategoxt
upgrading `strategoxt-0.9.2' to `strategoxt-0.9.3'
2003-12-22 18:04:00 +02:00
|
|
|
{
|
2006-02-08 15:21:16 +02:00
|
|
|
DrvName drvName(i->name);
|
* Upgrade operation in `nix-env'. For instance, you can say
nix-env -u foo.nix strategoxt
to replace the installed `strategoxt' derivation with the one from `foo.nix', if
the latter has a higher version number. This is a no-op if `strategoxt' is not
installed. Wildcards are also accepted, so
nix-env -u foo.nix '*'
will replace any installed derivation with newer versions from `foo.nix', if
available.
The notion of "version number" is somewhat ad hoc, but should be useful in most
cases, as evidenced by the following unit tests for the version comparator:
TEST("1.0", "2.3", -1);
TEST("2.1", "2.3", -1);
TEST("2.3", "2.3", 0);
TEST("2.5", "2.3", 1);
TEST("3.1", "2.3", 1);
TEST("2.3.1", "2.3", 1);
TEST("2.3.1", "2.3a", 1);
TEST("2.3pre1", "2.3", -1);
TEST("2.3pre3", "2.3pre12", -1);
TEST("2.3a", "2.3c", -1);
TEST("2.3pre1", "2.3c", -1);
TEST("2.3pre1", "2.3q", -1);
(-1 = less, 0 = equal, 1 = greater)
* A new verbosity level `lvlInfo', between `lvlError' and `lvlTalkative'. This is
the default for `nix-env', so without any `-v' flags users should get useful
output, e.g.,
$ nix-env -u foo.nix strategoxt
upgrading `strategoxt-0.9.2' to `strategoxt-0.9.3'
2003-12-22 18:04:00 +02:00
|
|
|
|
2005-02-14 18:16:02 +02:00
|
|
|
/* Find the derivation in the input Nix expression with the
|
|
|
|
same name and satisfying the version constraints specified
|
|
|
|
by upgradeType. If there are multiple matches, take the
|
|
|
|
one with highest version. */
|
2006-02-08 15:21:16 +02:00
|
|
|
DrvInfos::iterator bestElem = availElems.end();
|
2004-02-09 13:59:39 +02:00
|
|
|
DrvName bestName;
|
2006-02-08 15:21:16 +02:00
|
|
|
for (DrvInfos::iterator j = availElems.begin();
|
2005-02-14 18:16:02 +02:00
|
|
|
j != availElems.end(); ++j)
|
2004-02-09 13:59:39 +02:00
|
|
|
{
|
2006-02-08 15:21:16 +02:00
|
|
|
DrvName newName(j->name);
|
2004-02-09 13:59:39 +02:00
|
|
|
if (newName.name == drvName.name) {
|
|
|
|
int d = compareVersions(drvName.version, newName.version);
|
|
|
|
if (upgradeType == utLt && d < 0 ||
|
|
|
|
upgradeType == utLeq && d <= 0 ||
|
2006-06-27 15:17:25 +03:00
|
|
|
upgradeType == utEq && d == 0 ||
|
2004-02-09 13:59:39 +02:00
|
|
|
upgradeType == utAlways)
|
|
|
|
{
|
2005-02-14 18:16:02 +02:00
|
|
|
if ((bestElem == availElems.end() ||
|
2004-06-28 16:37:05 +03:00
|
|
|
compareVersions(
|
|
|
|
bestName.version, newName.version) < 0))
|
2004-02-09 13:59:39 +02:00
|
|
|
{
|
2005-02-14 18:16:02 +02:00
|
|
|
bestElem = j;
|
2004-02-09 13:59:39 +02:00
|
|
|
bestName = newName;
|
|
|
|
}
|
|
|
|
}
|
2003-12-24 00:13:36 +02:00
|
|
|
}
|
* Upgrade operation in `nix-env'. For instance, you can say
nix-env -u foo.nix strategoxt
to replace the installed `strategoxt' derivation with the one from `foo.nix', if
the latter has a higher version number. This is a no-op if `strategoxt' is not
installed. Wildcards are also accepted, so
nix-env -u foo.nix '*'
will replace any installed derivation with newer versions from `foo.nix', if
available.
The notion of "version number" is somewhat ad hoc, but should be useful in most
cases, as evidenced by the following unit tests for the version comparator:
TEST("1.0", "2.3", -1);
TEST("2.1", "2.3", -1);
TEST("2.3", "2.3", 0);
TEST("2.5", "2.3", 1);
TEST("3.1", "2.3", 1);
TEST("2.3.1", "2.3", 1);
TEST("2.3.1", "2.3a", 1);
TEST("2.3pre1", "2.3", -1);
TEST("2.3pre3", "2.3pre12", -1);
TEST("2.3a", "2.3c", -1);
TEST("2.3pre1", "2.3c", -1);
TEST("2.3pre1", "2.3q", -1);
(-1 = less, 0 = equal, 1 = greater)
* A new verbosity level `lvlInfo', between `lvlError' and `lvlTalkative'. This is
the default for `nix-env', so without any `-v' flags users should get useful
output, e.g.,
$ nix-env -u foo.nix strategoxt
upgrading `strategoxt-0.9.2' to `strategoxt-0.9.3'
2003-12-22 18:04:00 +02:00
|
|
|
}
|
|
|
|
|
2005-02-14 18:16:02 +02:00
|
|
|
if (bestElem != availElems.end() &&
|
2006-02-08 15:21:16 +02:00
|
|
|
i->queryOutPath(globals.state) !=
|
|
|
|
bestElem->queryOutPath(globals.state))
|
2004-02-09 13:59:39 +02:00
|
|
|
{
|
* Upgrade operation in `nix-env'. For instance, you can say
nix-env -u foo.nix strategoxt
to replace the installed `strategoxt' derivation with the one from `foo.nix', if
the latter has a higher version number. This is a no-op if `strategoxt' is not
installed. Wildcards are also accepted, so
nix-env -u foo.nix '*'
will replace any installed derivation with newer versions from `foo.nix', if
available.
The notion of "version number" is somewhat ad hoc, but should be useful in most
cases, as evidenced by the following unit tests for the version comparator:
TEST("1.0", "2.3", -1);
TEST("2.1", "2.3", -1);
TEST("2.3", "2.3", 0);
TEST("2.5", "2.3", 1);
TEST("3.1", "2.3", 1);
TEST("2.3.1", "2.3", 1);
TEST("2.3.1", "2.3a", 1);
TEST("2.3pre1", "2.3", -1);
TEST("2.3pre3", "2.3pre12", -1);
TEST("2.3a", "2.3c", -1);
TEST("2.3pre1", "2.3c", -1);
TEST("2.3pre1", "2.3q", -1);
(-1 = less, 0 = equal, 1 = greater)
* A new verbosity level `lvlInfo', between `lvlError' and `lvlTalkative'. This is
the default for `nix-env', so without any `-v' flags users should get useful
output, e.g.,
$ nix-env -u foo.nix strategoxt
upgrading `strategoxt-0.9.2' to `strategoxt-0.9.3'
2003-12-22 18:04:00 +02:00
|
|
|
printMsg(lvlInfo,
|
|
|
|
format("upgrading `%1%' to `%2%'")
|
2006-02-08 15:21:16 +02:00
|
|
|
% i->name % bestElem->name);
|
|
|
|
newElems.push_back(*bestElem);
|
|
|
|
} else newElems.push_back(*i);
|
* Upgrade operation in `nix-env'. For instance, you can say
nix-env -u foo.nix strategoxt
to replace the installed `strategoxt' derivation with the one from `foo.nix', if
the latter has a higher version number. This is a no-op if `strategoxt' is not
installed. Wildcards are also accepted, so
nix-env -u foo.nix '*'
will replace any installed derivation with newer versions from `foo.nix', if
available.
The notion of "version number" is somewhat ad hoc, but should be useful in most
cases, as evidenced by the following unit tests for the version comparator:
TEST("1.0", "2.3", -1);
TEST("2.1", "2.3", -1);
TEST("2.3", "2.3", 0);
TEST("2.5", "2.3", 1);
TEST("3.1", "2.3", 1);
TEST("2.3.1", "2.3", 1);
TEST("2.3.1", "2.3a", 1);
TEST("2.3pre1", "2.3", -1);
TEST("2.3pre3", "2.3pre12", -1);
TEST("2.3a", "2.3c", -1);
TEST("2.3pre1", "2.3c", -1);
TEST("2.3pre1", "2.3q", -1);
(-1 = less, 0 = equal, 1 = greater)
* A new verbosity level `lvlInfo', between `lvlError' and `lvlTalkative'. This is
the default for `nix-env', so without any `-v' flags users should get useful
output, e.g.,
$ nix-env -u foo.nix strategoxt
upgrading `strategoxt-0.9.2' to `strategoxt-0.9.3'
2003-12-22 18:04:00 +02:00
|
|
|
}
|
|
|
|
|
2006-03-06 13:21:15 +02:00
|
|
|
if (globals.dryRun) {
|
|
|
|
printMissing(globals.state, newElems);
|
|
|
|
return;
|
|
|
|
}
|
2004-02-09 13:59:39 +02:00
|
|
|
|
2005-02-14 18:16:02 +02:00
|
|
|
createUserEnv(globals.state, newElems,
|
2005-02-14 15:07:09 +02:00
|
|
|
profile, globals.keepDerivations);
|
* Upgrade operation in `nix-env'. For instance, you can say
nix-env -u foo.nix strategoxt
to replace the installed `strategoxt' derivation with the one from `foo.nix', if
the latter has a higher version number. This is a no-op if `strategoxt' is not
installed. Wildcards are also accepted, so
nix-env -u foo.nix '*'
will replace any installed derivation with newer versions from `foo.nix', if
available.
The notion of "version number" is somewhat ad hoc, but should be useful in most
cases, as evidenced by the following unit tests for the version comparator:
TEST("1.0", "2.3", -1);
TEST("2.1", "2.3", -1);
TEST("2.3", "2.3", 0);
TEST("2.5", "2.3", 1);
TEST("3.1", "2.3", 1);
TEST("2.3.1", "2.3", 1);
TEST("2.3.1", "2.3a", 1);
TEST("2.3pre1", "2.3", -1);
TEST("2.3pre3", "2.3pre12", -1);
TEST("2.3a", "2.3c", -1);
TEST("2.3pre1", "2.3c", -1);
TEST("2.3pre1", "2.3q", -1);
(-1 = less, 0 = equal, 1 = greater)
* A new verbosity level `lvlInfo', between `lvlError' and `lvlTalkative'. This is
the default for `nix-env', so without any `-v' flags users should get useful
output, e.g.,
$ nix-env -u foo.nix strategoxt
upgrading `strategoxt-0.9.2' to `strategoxt-0.9.3'
2003-12-22 18:04:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-22 01:58:56 +02:00
|
|
|
static void opUpgrade(Globals & globals,
|
|
|
|
Strings opFlags, Strings opArgs)
|
|
|
|
{
|
2004-02-09 13:59:39 +02:00
|
|
|
UpgradeType upgradeType = utLt;
|
|
|
|
for (Strings::iterator i = opFlags.begin();
|
|
|
|
i != opFlags.end(); ++i)
|
|
|
|
if (*i == "--lt") upgradeType = utLt;
|
|
|
|
else if (*i == "--leq") upgradeType = utLeq;
|
2006-06-27 15:17:25 +03:00
|
|
|
else if (*i == "--eq") upgradeType = utEq;
|
2004-02-09 13:59:39 +02:00
|
|
|
else if (*i == "--always") upgradeType = utAlways;
|
|
|
|
else throw UsageError(format("unknown flag `%1%'") % *i);
|
2003-12-22 01:58:56 +02:00
|
|
|
|
2005-02-14 18:16:02 +02:00
|
|
|
upgradeDerivations(globals, opArgs, globals.profile, upgradeType);
|
2003-11-19 19:27:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-14 15:07:09 +02:00
|
|
|
static void uninstallDerivations(Globals & globals, DrvNames & selectors,
|
|
|
|
Path & profile)
|
2003-11-20 15:48:48 +02:00
|
|
|
{
|
2006-06-15 14:56:49 +03:00
|
|
|
PathLocks lock;
|
|
|
|
lockProfile(lock, profile);
|
2006-02-08 15:21:16 +02:00
|
|
|
DrvInfos installedElems = queryInstalled(globals.state, profile);
|
|
|
|
DrvInfos newElems;
|
2003-11-20 15:48:48 +02:00
|
|
|
|
2006-02-08 15:21:16 +02:00
|
|
|
for (DrvInfos::iterator i = installedElems.begin();
|
2005-02-14 18:16:02 +02:00
|
|
|
i != installedElems.end(); ++i)
|
2003-11-20 15:48:48 +02:00
|
|
|
{
|
2006-02-08 15:21:16 +02:00
|
|
|
DrvName drvName(i->name);
|
2005-09-01 21:14:04 +03:00
|
|
|
bool found = false;
|
2003-12-22 01:58:56 +02:00
|
|
|
for (DrvNames::iterator j = selectors.begin();
|
|
|
|
j != selectors.end(); ++j)
|
* Upgrade operation in `nix-env'. For instance, you can say
nix-env -u foo.nix strategoxt
to replace the installed `strategoxt' derivation with the one from `foo.nix', if
the latter has a higher version number. This is a no-op if `strategoxt' is not
installed. Wildcards are also accepted, so
nix-env -u foo.nix '*'
will replace any installed derivation with newer versions from `foo.nix', if
available.
The notion of "version number" is somewhat ad hoc, but should be useful in most
cases, as evidenced by the following unit tests for the version comparator:
TEST("1.0", "2.3", -1);
TEST("2.1", "2.3", -1);
TEST("2.3", "2.3", 0);
TEST("2.5", "2.3", 1);
TEST("3.1", "2.3", 1);
TEST("2.3.1", "2.3", 1);
TEST("2.3.1", "2.3a", 1);
TEST("2.3pre1", "2.3", -1);
TEST("2.3pre3", "2.3pre12", -1);
TEST("2.3a", "2.3c", -1);
TEST("2.3pre1", "2.3c", -1);
TEST("2.3pre1", "2.3q", -1);
(-1 = less, 0 = equal, 1 = greater)
* A new verbosity level `lvlInfo', between `lvlError' and `lvlTalkative'. This is
the default for `nix-env', so without any `-v' flags users should get useful
output, e.g.,
$ nix-env -u foo.nix strategoxt
upgrading `strategoxt-0.9.2' to `strategoxt-0.9.3'
2003-12-22 18:04:00 +02:00
|
|
|
if (j->matches(drvName)) {
|
|
|
|
printMsg(lvlInfo,
|
2006-02-08 15:21:16 +02:00
|
|
|
format("uninstalling `%1%'") % i->name);
|
2005-09-01 21:14:04 +03:00
|
|
|
found = true;
|
|
|
|
break;
|
* Upgrade operation in `nix-env'. For instance, you can say
nix-env -u foo.nix strategoxt
to replace the installed `strategoxt' derivation with the one from `foo.nix', if
the latter has a higher version number. This is a no-op if `strategoxt' is not
installed. Wildcards are also accepted, so
nix-env -u foo.nix '*'
will replace any installed derivation with newer versions from `foo.nix', if
available.
The notion of "version number" is somewhat ad hoc, but should be useful in most
cases, as evidenced by the following unit tests for the version comparator:
TEST("1.0", "2.3", -1);
TEST("2.1", "2.3", -1);
TEST("2.3", "2.3", 0);
TEST("2.5", "2.3", 1);
TEST("3.1", "2.3", 1);
TEST("2.3.1", "2.3", 1);
TEST("2.3.1", "2.3a", 1);
TEST("2.3pre1", "2.3", -1);
TEST("2.3pre3", "2.3pre12", -1);
TEST("2.3a", "2.3c", -1);
TEST("2.3pre1", "2.3c", -1);
TEST("2.3pre1", "2.3q", -1);
(-1 = less, 0 = equal, 1 = greater)
* A new verbosity level `lvlInfo', between `lvlError' and `lvlTalkative'. This is
the default for `nix-env', so without any `-v' flags users should get useful
output, e.g.,
$ nix-env -u foo.nix strategoxt
upgrading `strategoxt-0.9.2' to `strategoxt-0.9.3'
2003-12-22 18:04:00 +02:00
|
|
|
}
|
2006-02-08 15:21:16 +02:00
|
|
|
if (!found) newElems.push_back(*i);
|
2003-11-20 15:48:48 +02:00
|
|
|
}
|
|
|
|
|
2005-02-14 15:07:09 +02:00
|
|
|
if (globals.dryRun) return;
|
2004-02-09 13:59:39 +02:00
|
|
|
|
2005-09-01 21:14:04 +03:00
|
|
|
createUserEnv(globals.state, newElems,
|
2005-02-14 15:07:09 +02:00
|
|
|
profile, globals.keepDerivations);
|
2003-11-20 15:48:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-22 00:34:41 +02:00
|
|
|
static void opUninstall(Globals & globals,
|
2003-11-20 15:48:48 +02:00
|
|
|
Strings opFlags, Strings opArgs)
|
|
|
|
{
|
2003-12-22 00:34:41 +02:00
|
|
|
if (opFlags.size() > 0)
|
2006-07-25 14:53:22 +03:00
|
|
|
throw UsageError(format("unknown flag `%1%'") % opFlags.front());
|
2003-12-22 00:34:41 +02:00
|
|
|
|
2003-12-22 01:58:56 +02:00
|
|
|
DrvNames drvNames = drvNamesFromArgs(opArgs);
|
|
|
|
|
2005-02-14 15:07:09 +02:00
|
|
|
uninstallDerivations(globals, drvNames,
|
|
|
|
globals.profile);
|
2003-11-20 15:48:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-14 18:09:55 +03:00
|
|
|
static bool cmpChars(char a, char b)
|
|
|
|
{
|
|
|
|
return toupper(a) < toupper(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-08 15:21:16 +02:00
|
|
|
static bool cmpElemByName(const DrvInfo & a, const DrvInfo & b)
|
2004-02-02 12:51:54 +02:00
|
|
|
{
|
2004-10-14 18:09:55 +03:00
|
|
|
return lexicographical_compare(
|
|
|
|
a.name.begin(), a.name.end(),
|
|
|
|
b.name.begin(), b.name.end(), cmpChars);
|
2004-02-02 12:51:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-01 16:35:10 +03:00
|
|
|
typedef list<Strings> Table;
|
|
|
|
|
|
|
|
|
|
|
|
void printTable(Table & table)
|
|
|
|
{
|
2004-10-29 14:22:49 +03:00
|
|
|
unsigned int nrColumns = table.size() > 0 ? table.front().size() : 0;
|
2004-07-01 16:35:10 +03:00
|
|
|
|
2004-10-29 14:22:49 +03:00
|
|
|
vector<unsigned int> widths;
|
2004-07-01 16:35:10 +03:00
|
|
|
widths.resize(nrColumns);
|
|
|
|
|
|
|
|
for (Table::iterator i = table.begin(); i != table.end(); ++i) {
|
|
|
|
assert(i->size() == nrColumns);
|
2004-10-29 14:22:49 +03:00
|
|
|
Strings::iterator j;
|
|
|
|
unsigned int column;
|
2004-07-01 16:35:10 +03:00
|
|
|
for (j = i->begin(), column = 0; j != i->end(); ++j, ++column)
|
|
|
|
if (j->size() > widths[column]) widths[column] = j->size();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Table::iterator i = table.begin(); i != table.end(); ++i) {
|
2004-10-29 14:22:49 +03:00
|
|
|
Strings::iterator j;
|
|
|
|
unsigned int column;
|
2004-07-01 16:35:10 +03:00
|
|
|
for (j = i->begin(), column = 0; j != i->end(); ++j, ++column)
|
|
|
|
{
|
|
|
|
cout << *j;
|
|
|
|
if (column < nrColumns - 1)
|
|
|
|
cout << string(widths[column] - j->size() + 2, ' ');
|
|
|
|
}
|
2006-09-05 00:06:23 +03:00
|
|
|
cout << std::endl;
|
2004-07-01 16:35:10 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
* New query option: `--compare-versions' or `-c' to compare installed
versions to available versions, or vice versa.
For example, the following compares installed versions to available
versions:
$ nix-env -qc
autoconf-2.59 = 2.59
automake-1.9.4 < 1.9.6
f-spot-0.0.10 - ?
firefox-1.0.4 < 1.0.7
...
I.e., there are newer versions available (in the current default Nix
expression) for Automake and Firefox, but not for Autoconf, and
F-Spot is missing altogether.
Conversely, the available versions can be compared to the installed
versions:
$ nix-env -qac
autoconf-2.59 = 2.59
automake-1.9.6 > 1.9.4
bash-3.0 - ?
firefox-1.0.7 > 1.0.4
...
Note that bash is available but no version of it is installed.
If multiple versions are available for comparison, then the highest
is used. E.g., if Subversion 1.2.0 is installed, and Subversion
1.1.4 and 1.2.3 are available, then `nix-env -qc' will print `<
1.2.3', not `> 1.1.4'.
If higher versions are available, the version column is printed in
red (using ANSI escape codes).
2005-10-06 17:44:54 +03:00
|
|
|
/* This function compares the version of a element against the
|
|
|
|
versions in the given set of elements. `cvLess' means that only
|
|
|
|
lower versions are in the set, `cvEqual' means that at most an
|
|
|
|
equal version is in the set, and `cvGreater' means that there is at
|
|
|
|
least one element with a higher version in the set. `cvUnavail'
|
|
|
|
means that there are no elements with the same name in the set. */
|
|
|
|
|
|
|
|
typedef enum { cvLess, cvEqual, cvGreater, cvUnavail } VersionDiff;
|
|
|
|
|
|
|
|
static VersionDiff compareVersionAgainstSet(
|
2006-02-08 15:21:16 +02:00
|
|
|
const DrvInfo & elem, const DrvInfos & elems, string & version)
|
* New query option: `--compare-versions' or `-c' to compare installed
versions to available versions, or vice versa.
For example, the following compares installed versions to available
versions:
$ nix-env -qc
autoconf-2.59 = 2.59
automake-1.9.4 < 1.9.6
f-spot-0.0.10 - ?
firefox-1.0.4 < 1.0.7
...
I.e., there are newer versions available (in the current default Nix
expression) for Automake and Firefox, but not for Autoconf, and
F-Spot is missing altogether.
Conversely, the available versions can be compared to the installed
versions:
$ nix-env -qac
autoconf-2.59 = 2.59
automake-1.9.6 > 1.9.4
bash-3.0 - ?
firefox-1.0.7 > 1.0.4
...
Note that bash is available but no version of it is installed.
If multiple versions are available for comparison, then the highest
is used. E.g., if Subversion 1.2.0 is installed, and Subversion
1.1.4 and 1.2.3 are available, then `nix-env -qc' will print `<
1.2.3', not `> 1.1.4'.
If higher versions are available, the version column is printed in
red (using ANSI escape codes).
2005-10-06 17:44:54 +03:00
|
|
|
{
|
|
|
|
DrvName name(elem.name);
|
|
|
|
|
|
|
|
VersionDiff diff = cvUnavail;
|
|
|
|
version = "?";
|
|
|
|
|
2006-02-08 15:21:16 +02:00
|
|
|
for (DrvInfos::const_iterator i = elems.begin(); i != elems.end(); ++i) {
|
|
|
|
DrvName name2(i->name);
|
* New query option: `--compare-versions' or `-c' to compare installed
versions to available versions, or vice versa.
For example, the following compares installed versions to available
versions:
$ nix-env -qc
autoconf-2.59 = 2.59
automake-1.9.4 < 1.9.6
f-spot-0.0.10 - ?
firefox-1.0.4 < 1.0.7
...
I.e., there are newer versions available (in the current default Nix
expression) for Automake and Firefox, but not for Autoconf, and
F-Spot is missing altogether.
Conversely, the available versions can be compared to the installed
versions:
$ nix-env -qac
autoconf-2.59 = 2.59
automake-1.9.6 > 1.9.4
bash-3.0 - ?
firefox-1.0.7 > 1.0.4
...
Note that bash is available but no version of it is installed.
If multiple versions are available for comparison, then the highest
is used. E.g., if Subversion 1.2.0 is installed, and Subversion
1.1.4 and 1.2.3 are available, then `nix-env -qc' will print `<
1.2.3', not `> 1.1.4'.
If higher versions are available, the version column is printed in
red (using ANSI escape codes).
2005-10-06 17:44:54 +03:00
|
|
|
if (name.name == name2.name) {
|
|
|
|
int d = compareVersions(name.version, name2.version);
|
|
|
|
if (d < 0) {
|
|
|
|
diff = cvGreater;
|
|
|
|
version = name2.version;
|
|
|
|
}
|
|
|
|
else if (diff != cvGreater && d == 0) {
|
|
|
|
diff = cvEqual;
|
|
|
|
version = name2.version;
|
|
|
|
}
|
|
|
|
else if (diff != cvGreater && diff != cvEqual && d > 0) {
|
|
|
|
diff = cvLess;
|
|
|
|
if (version == "" || compareVersions(version, name2.version) < 0)
|
|
|
|
version = name2.version;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return diff;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static string colorString(const string & s)
|
|
|
|
{
|
2005-10-06 18:01:46 +03:00
|
|
|
if (!isatty(STDOUT_FILENO)) return s;
|
* New query option: `--compare-versions' or `-c' to compare installed
versions to available versions, or vice versa.
For example, the following compares installed versions to available
versions:
$ nix-env -qc
autoconf-2.59 = 2.59
automake-1.9.4 < 1.9.6
f-spot-0.0.10 - ?
firefox-1.0.4 < 1.0.7
...
I.e., there are newer versions available (in the current default Nix
expression) for Automake and Firefox, but not for Autoconf, and
F-Spot is missing altogether.
Conversely, the available versions can be compared to the installed
versions:
$ nix-env -qac
autoconf-2.59 = 2.59
automake-1.9.6 > 1.9.4
bash-3.0 - ?
firefox-1.0.7 > 1.0.4
...
Note that bash is available but no version of it is installed.
If multiple versions are available for comparison, then the highest
is used. E.g., if Subversion 1.2.0 is installed, and Subversion
1.1.4 and 1.2.3 are available, then `nix-env -qc' will print `<
1.2.3', not `> 1.1.4'.
If higher versions are available, the version column is printed in
red (using ANSI escape codes).
2005-10-06 17:44:54 +03:00
|
|
|
return "\e[1;31m" + s + "\e[0m";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-22 00:34:41 +02:00
|
|
|
static void opQuery(Globals & globals,
|
2003-11-19 19:27:16 +02:00
|
|
|
Strings opFlags, Strings opArgs)
|
|
|
|
{
|
2006-08-03 18:52:09 +03:00
|
|
|
typedef vector< map<string, string> > ResultSet;
|
|
|
|
|
2004-07-01 16:13:37 +03:00
|
|
|
bool printStatus = false;
|
|
|
|
bool printName = true;
|
2006-07-25 19:40:38 +03:00
|
|
|
bool printAttrPath = false;
|
2004-07-01 16:13:37 +03:00
|
|
|
bool printSystem = false;
|
|
|
|
bool printDrvPath = false;
|
2005-02-11 18:56:45 +02:00
|
|
|
bool printOutPath = false;
|
2006-03-10 18:20:42 +02:00
|
|
|
bool printDescription = false;
|
* New query option: `--compare-versions' or `-c' to compare installed
versions to available versions, or vice versa.
For example, the following compares installed versions to available
versions:
$ nix-env -qc
autoconf-2.59 = 2.59
automake-1.9.4 < 1.9.6
f-spot-0.0.10 - ?
firefox-1.0.4 < 1.0.7
...
I.e., there are newer versions available (in the current default Nix
expression) for Automake and Firefox, but not for Autoconf, and
F-Spot is missing altogether.
Conversely, the available versions can be compared to the installed
versions:
$ nix-env -qac
autoconf-2.59 = 2.59
automake-1.9.6 > 1.9.4
bash-3.0 - ?
firefox-1.0.7 > 1.0.4
...
Note that bash is available but no version of it is installed.
If multiple versions are available for comparison, then the highest
is used. E.g., if Subversion 1.2.0 is installed, and Subversion
1.1.4 and 1.2.3 are available, then `nix-env -qc' will print `<
1.2.3', not `> 1.1.4'.
If higher versions are available, the version column is printed in
red (using ANSI escape codes).
2005-10-06 17:44:54 +03:00
|
|
|
bool compareVersions = false;
|
2006-08-03 18:52:09 +03:00
|
|
|
bool xmlOutput = false;
|
2004-07-01 16:13:37 +03:00
|
|
|
|
2003-11-19 19:27:16 +02:00
|
|
|
enum { sInstalled, sAvailable } source = sInstalled;
|
|
|
|
|
2004-10-27 13:24:44 +03:00
|
|
|
readOnlyMode = true; /* makes evaluation a bit faster */
|
|
|
|
|
2003-11-19 19:27:16 +02:00
|
|
|
for (Strings::iterator i = opFlags.begin();
|
|
|
|
i != opFlags.end(); ++i)
|
2004-07-01 16:13:37 +03:00
|
|
|
if (*i == "--status" || *i == "-s") printStatus = true;
|
|
|
|
else if (*i == "--no-name") printName = false;
|
|
|
|
else if (*i == "--system") printSystem = true;
|
2006-03-10 18:20:42 +02:00
|
|
|
else if (*i == "--description") printDescription = true;
|
* New query option: `--compare-versions' or `-c' to compare installed
versions to available versions, or vice versa.
For example, the following compares installed versions to available
versions:
$ nix-env -qc
autoconf-2.59 = 2.59
automake-1.9.4 < 1.9.6
f-spot-0.0.10 - ?
firefox-1.0.4 < 1.0.7
...
I.e., there are newer versions available (in the current default Nix
expression) for Automake and Firefox, but not for Autoconf, and
F-Spot is missing altogether.
Conversely, the available versions can be compared to the installed
versions:
$ nix-env -qac
autoconf-2.59 = 2.59
automake-1.9.6 > 1.9.4
bash-3.0 - ?
firefox-1.0.7 > 1.0.4
...
Note that bash is available but no version of it is installed.
If multiple versions are available for comparison, then the highest
is used. E.g., if Subversion 1.2.0 is installed, and Subversion
1.1.4 and 1.2.3 are available, then `nix-env -qc' will print `<
1.2.3', not `> 1.1.4'.
If higher versions are available, the version column is printed in
red (using ANSI escape codes).
2005-10-06 17:44:54 +03:00
|
|
|
else if (*i == "--compare-versions" || *i == "-c") compareVersions = true;
|
2005-02-11 18:56:45 +02:00
|
|
|
else if (*i == "--drv-path") printDrvPath = true;
|
|
|
|
else if (*i == "--out-path") printOutPath = true;
|
2003-11-19 19:27:16 +02:00
|
|
|
else if (*i == "--installed") source = sInstalled;
|
2004-01-05 18:26:43 +02:00
|
|
|
else if (*i == "--available" || *i == "-a") source = sAvailable;
|
2006-08-03 18:52:09 +03:00
|
|
|
else if (*i == "--xml") xmlOutput = true;
|
2003-11-19 19:27:16 +02:00
|
|
|
else throw UsageError(format("unknown flag `%1%'") % *i);
|
|
|
|
|
2006-07-25 19:40:38 +03:00
|
|
|
if (globals.instSource.type == srcAttrPath) printAttrPath = true; /* hack */
|
|
|
|
|
2006-03-10 12:24:46 +02:00
|
|
|
if (opArgs.size() == 0) {
|
|
|
|
printMsg(lvlInfo, "warning: you probably meant to specify the argument '*' to show all packages");
|
|
|
|
}
|
2003-11-19 19:27:16 +02:00
|
|
|
|
* New query option: `--compare-versions' or `-c' to compare installed
versions to available versions, or vice versa.
For example, the following compares installed versions to available
versions:
$ nix-env -qc
autoconf-2.59 = 2.59
automake-1.9.4 < 1.9.6
f-spot-0.0.10 - ?
firefox-1.0.4 < 1.0.7
...
I.e., there are newer versions available (in the current default Nix
expression) for Automake and Firefox, but not for Autoconf, and
F-Spot is missing altogether.
Conversely, the available versions can be compared to the installed
versions:
$ nix-env -qac
autoconf-2.59 = 2.59
automake-1.9.6 > 1.9.4
bash-3.0 - ?
firefox-1.0.7 > 1.0.4
...
Note that bash is available but no version of it is installed.
If multiple versions are available for comparison, then the highest
is used. E.g., if Subversion 1.2.0 is installed, and Subversion
1.1.4 and 1.2.3 are available, then `nix-env -qc' will print `<
1.2.3', not `> 1.1.4'.
If higher versions are available, the version column is printed in
red (using ANSI escape codes).
2005-10-06 17:44:54 +03:00
|
|
|
|
|
|
|
/* Obtain derivation information from the specified source. */
|
2006-02-08 15:21:16 +02:00
|
|
|
DrvInfos availElems, installedElems;
|
2003-11-19 19:27:16 +02:00
|
|
|
|
2006-01-27 01:18:26 +02:00
|
|
|
if (source == sInstalled || compareVersions || printStatus) {
|
* New query option: `--compare-versions' or `-c' to compare installed
versions to available versions, or vice versa.
For example, the following compares installed versions to available
versions:
$ nix-env -qc
autoconf-2.59 = 2.59
automake-1.9.4 < 1.9.6
f-spot-0.0.10 - ?
firefox-1.0.4 < 1.0.7
...
I.e., there are newer versions available (in the current default Nix
expression) for Automake and Firefox, but not for Autoconf, and
F-Spot is missing altogether.
Conversely, the available versions can be compared to the installed
versions:
$ nix-env -qac
autoconf-2.59 = 2.59
automake-1.9.6 > 1.9.4
bash-3.0 - ?
firefox-1.0.7 > 1.0.4
...
Note that bash is available but no version of it is installed.
If multiple versions are available for comparison, then the highest
is used. E.g., if Subversion 1.2.0 is installed, and Subversion
1.1.4 and 1.2.3 are available, then `nix-env -qc' will print `<
1.2.3', not `> 1.1.4'.
If higher versions are available, the version column is printed in
red (using ANSI escape codes).
2005-10-06 17:44:54 +03:00
|
|
|
installedElems = queryInstalled(globals.state, globals.profile);
|
|
|
|
}
|
2003-11-19 19:27:16 +02:00
|
|
|
|
* New query option: `--compare-versions' or `-c' to compare installed
versions to available versions, or vice versa.
For example, the following compares installed versions to available
versions:
$ nix-env -qc
autoconf-2.59 = 2.59
automake-1.9.4 < 1.9.6
f-spot-0.0.10 - ?
firefox-1.0.4 < 1.0.7
...
I.e., there are newer versions available (in the current default Nix
expression) for Automake and Firefox, but not for Autoconf, and
F-Spot is missing altogether.
Conversely, the available versions can be compared to the installed
versions:
$ nix-env -qac
autoconf-2.59 = 2.59
automake-1.9.6 > 1.9.4
bash-3.0 - ?
firefox-1.0.7 > 1.0.4
...
Note that bash is available but no version of it is installed.
If multiple versions are available for comparison, then the highest
is used. E.g., if Subversion 1.2.0 is installed, and Subversion
1.1.4 and 1.2.3 are available, then `nix-env -qc' will print `<
1.2.3', not `> 1.1.4'.
If higher versions are available, the version column is printed in
red (using ANSI escape codes).
2005-10-06 17:44:54 +03:00
|
|
|
if (source == sAvailable || compareVersions) {
|
|
|
|
loadDerivations(globals.state, globals.instSource.nixExprPath,
|
2006-08-23 19:33:21 +03:00
|
|
|
globals.instSource.systemFilter, globals.instSource.autoArgs,
|
|
|
|
availElems);
|
2003-11-19 19:27:16 +02:00
|
|
|
}
|
|
|
|
|
2006-03-10 12:24:46 +02:00
|
|
|
DrvInfos elems = filterBySelector(globals.state,
|
|
|
|
source == sInstalled ? installedElems : availElems,
|
|
|
|
opArgs, false);
|
|
|
|
|
2006-02-08 15:21:16 +02:00
|
|
|
DrvInfos & otherElems(source == sInstalled ? availElems : installedElems);
|
2004-02-02 12:51:54 +02:00
|
|
|
|
* New query option: `--compare-versions' or `-c' to compare installed
versions to available versions, or vice versa.
For example, the following compares installed versions to available
versions:
$ nix-env -qc
autoconf-2.59 = 2.59
automake-1.9.4 < 1.9.6
f-spot-0.0.10 - ?
firefox-1.0.4 < 1.0.7
...
I.e., there are newer versions available (in the current default Nix
expression) for Automake and Firefox, but not for Autoconf, and
F-Spot is missing altogether.
Conversely, the available versions can be compared to the installed
versions:
$ nix-env -qac
autoconf-2.59 = 2.59
automake-1.9.6 > 1.9.4
bash-3.0 - ?
firefox-1.0.7 > 1.0.4
...
Note that bash is available but no version of it is installed.
If multiple versions are available for comparison, then the highest
is used. E.g., if Subversion 1.2.0 is installed, and Subversion
1.1.4 and 1.2.3 are available, then `nix-env -qc' will print `<
1.2.3', not `> 1.1.4'.
If higher versions are available, the version column is printed in
red (using ANSI escape codes).
2005-10-06 17:44:54 +03:00
|
|
|
|
2004-02-02 12:51:54 +02:00
|
|
|
/* Sort them by name. */
|
2006-02-08 15:21:16 +02:00
|
|
|
/* !!! */
|
|
|
|
vector<DrvInfo> elems2;
|
|
|
|
for (DrvInfos::iterator i = elems.begin(); i != elems.end(); ++i)
|
|
|
|
elems2.push_back(*i);
|
2005-02-14 18:16:02 +02:00
|
|
|
sort(elems2.begin(), elems2.end(), cmpElemByName);
|
2003-11-19 19:27:16 +02:00
|
|
|
|
* New query option: `--compare-versions' or `-c' to compare installed
versions to available versions, or vice versa.
For example, the following compares installed versions to available
versions:
$ nix-env -qc
autoconf-2.59 = 2.59
automake-1.9.4 < 1.9.6
f-spot-0.0.10 - ?
firefox-1.0.4 < 1.0.7
...
I.e., there are newer versions available (in the current default Nix
expression) for Automake and Firefox, but not for Autoconf, and
F-Spot is missing altogether.
Conversely, the available versions can be compared to the installed
versions:
$ nix-env -qac
autoconf-2.59 = 2.59
automake-1.9.6 > 1.9.4
bash-3.0 - ?
firefox-1.0.7 > 1.0.4
...
Note that bash is available but no version of it is installed.
If multiple versions are available for comparison, then the highest
is used. E.g., if Subversion 1.2.0 is installed, and Subversion
1.1.4 and 1.2.3 are available, then `nix-env -qc' will print `<
1.2.3', not `> 1.1.4'.
If higher versions are available, the version column is printed in
red (using ANSI escape codes).
2005-10-06 17:44:54 +03:00
|
|
|
|
2004-07-01 16:13:37 +03:00
|
|
|
/* We only need to know the installed paths when we are querying
|
|
|
|
the status of the derivation. */
|
2005-05-08 13:32:09 +03:00
|
|
|
PathSet installed; /* installed paths */
|
2004-07-01 16:13:37 +03:00
|
|
|
|
2005-05-08 13:32:09 +03:00
|
|
|
if (printStatus) {
|
2006-02-08 15:21:16 +02:00
|
|
|
for (DrvInfos::iterator i = installedElems.begin();
|
2005-05-08 13:32:09 +03:00
|
|
|
i != installedElems.end(); ++i)
|
2006-02-08 15:21:16 +02:00
|
|
|
installed.insert(i->queryOutPath(globals.state));
|
2005-05-08 13:32:09 +03:00
|
|
|
}
|
* New query option: `--compare-versions' or `-c' to compare installed
versions to available versions, or vice versa.
For example, the following compares installed versions to available
versions:
$ nix-env -qc
autoconf-2.59 = 2.59
automake-1.9.4 < 1.9.6
f-spot-0.0.10 - ?
firefox-1.0.4 < 1.0.7
...
I.e., there are newer versions available (in the current default Nix
expression) for Automake and Firefox, but not for Autoconf, and
F-Spot is missing altogether.
Conversely, the available versions can be compared to the installed
versions:
$ nix-env -qac
autoconf-2.59 = 2.59
automake-1.9.6 > 1.9.4
bash-3.0 - ?
firefox-1.0.7 > 1.0.4
...
Note that bash is available but no version of it is installed.
If multiple versions are available for comparison, then the highest
is used. E.g., if Subversion 1.2.0 is installed, and Subversion
1.1.4 and 1.2.3 are available, then `nix-env -qc' will print `<
1.2.3', not `> 1.1.4'.
If higher versions are available, the version column is printed in
red (using ANSI escape codes).
2005-10-06 17:44:54 +03:00
|
|
|
|
|
|
|
|
2006-08-03 18:52:09 +03:00
|
|
|
/* Print the desired columns, or XML output. */
|
2004-07-01 16:35:10 +03:00
|
|
|
Table table;
|
2006-09-05 00:06:23 +03:00
|
|
|
std::ostringstream dummy;
|
2006-08-16 13:32:30 +03:00
|
|
|
XMLWriter xml(true, *(xmlOutput ? &cout : &dummy));
|
2006-08-03 18:52:09 +03:00
|
|
|
XMLOpenElement xmlRoot(xml, "items");
|
2004-07-01 16:35:10 +03:00
|
|
|
|
2006-02-08 15:21:16 +02:00
|
|
|
for (vector<DrvInfo>::iterator i = elems2.begin();
|
2005-02-14 18:16:02 +02:00
|
|
|
i != elems2.end(); ++i)
|
|
|
|
{
|
2006-03-08 18:03:58 +02:00
|
|
|
try {
|
2006-08-03 18:52:09 +03:00
|
|
|
|
|
|
|
/* For table output. */
|
2006-03-08 18:03:58 +02:00
|
|
|
Strings columns;
|
2006-08-03 18:52:09 +03:00
|
|
|
|
|
|
|
/* For XML output. */
|
|
|
|
XMLAttrs attrs;
|
2004-07-01 16:13:37 +03:00
|
|
|
|
2006-03-08 18:03:58 +02:00
|
|
|
if (printStatus) {
|
|
|
|
Substitutes subs = querySubstitutes(noTxn, i->queryOutPath(globals.state));
|
2006-08-03 18:52:09 +03:00
|
|
|
bool isInstalled = installed.find(i->queryOutPath(globals.state)) != installed.end();
|
|
|
|
bool isValid = isValidPath(i->queryOutPath(globals.state));
|
|
|
|
if (xmlOutput) {
|
|
|
|
attrs["installed"] = isInstalled ? "1" : "0";
|
|
|
|
attrs["valid"] = isValid ? "1" : "0";
|
|
|
|
attrs["substitutable"] = !subs.empty() ? "1" : "0";
|
|
|
|
} else
|
|
|
|
columns.push_back(
|
|
|
|
(string) (isInstalled ? "I" : "-")
|
|
|
|
+ (isValid ? "P" : "-")
|
|
|
|
+ (!subs.empty() ? "S" : "-"));
|
2006-03-08 18:03:58 +02:00
|
|
|
}
|
2004-07-01 16:13:37 +03:00
|
|
|
|
2006-08-03 18:52:09 +03:00
|
|
|
if (xmlOutput)
|
|
|
|
attrs["attrPath"] = i->attrPath;
|
|
|
|
else if (printAttrPath)
|
|
|
|
columns.push_back(i->attrPath);
|
2006-07-25 19:40:38 +03:00
|
|
|
|
2006-08-03 18:52:09 +03:00
|
|
|
if (xmlOutput)
|
|
|
|
attrs["name"] = i->name;
|
|
|
|
else if (printName)
|
|
|
|
columns.push_back(i->name);
|
2006-03-08 18:03:58 +02:00
|
|
|
|
|
|
|
if (compareVersions) {
|
|
|
|
/* Compare this element against the versions of the
|
|
|
|
same named packages in either the set of available
|
|
|
|
elements, or the set of installed elements. !!!
|
|
|
|
This is O(N * M), should be O(N * lg M). */
|
|
|
|
string version;
|
|
|
|
VersionDiff diff = compareVersionAgainstSet(*i, otherElems, version);
|
2006-08-03 18:52:09 +03:00
|
|
|
|
2006-03-08 18:03:58 +02:00
|
|
|
char ch;
|
|
|
|
switch (diff) {
|
|
|
|
case cvLess: ch = '>'; break;
|
|
|
|
case cvEqual: ch = '='; break;
|
|
|
|
case cvGreater: ch = '<'; break;
|
|
|
|
case cvUnavail: ch = '-'; break;
|
|
|
|
default: abort();
|
|
|
|
}
|
2006-08-03 18:52:09 +03:00
|
|
|
|
|
|
|
if (xmlOutput) {
|
|
|
|
if (diff != cvUnavail) {
|
|
|
|
attrs["versionDiff"] = ch;
|
|
|
|
attrs["maxComparedVersion"] = version;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
string column = (string) "" + ch + " " + version;
|
|
|
|
if (diff == cvGreater) column = colorString(column);
|
|
|
|
columns.push_back(column);
|
|
|
|
}
|
* New query option: `--compare-versions' or `-c' to compare installed
versions to available versions, or vice versa.
For example, the following compares installed versions to available
versions:
$ nix-env -qc
autoconf-2.59 = 2.59
automake-1.9.4 < 1.9.6
f-spot-0.0.10 - ?
firefox-1.0.4 < 1.0.7
...
I.e., there are newer versions available (in the current default Nix
expression) for Automake and Firefox, but not for Autoconf, and
F-Spot is missing altogether.
Conversely, the available versions can be compared to the installed
versions:
$ nix-env -qac
autoconf-2.59 = 2.59
automake-1.9.6 > 1.9.4
bash-3.0 - ?
firefox-1.0.7 > 1.0.4
...
Note that bash is available but no version of it is installed.
If multiple versions are available for comparison, then the highest
is used. E.g., if Subversion 1.2.0 is installed, and Subversion
1.1.4 and 1.2.3 are available, then `nix-env -qc' will print `<
1.2.3', not `> 1.1.4'.
If higher versions are available, the version column is printed in
red (using ANSI escape codes).
2005-10-06 17:44:54 +03:00
|
|
|
}
|
|
|
|
|
2006-08-03 18:52:09 +03:00
|
|
|
if (xmlOutput) {
|
|
|
|
if (i->system != "") attrs["system"] = i->system;
|
|
|
|
}
|
|
|
|
else if (printSystem)
|
|
|
|
columns.push_back(i->system);
|
2005-10-06 18:51:59 +03:00
|
|
|
|
2006-08-03 18:52:09 +03:00
|
|
|
if (printDrvPath) {
|
|
|
|
string drvPath = i->queryDrvPath(globals.state);
|
|
|
|
if (xmlOutput) {
|
|
|
|
if (drvPath != "") attrs["drvPath"] = drvPath;
|
|
|
|
} else
|
|
|
|
columns.push_back(drvPath == "" ? "-" : drvPath);
|
|
|
|
}
|
2005-02-11 18:56:45 +02:00
|
|
|
|
2006-08-03 18:52:09 +03:00
|
|
|
if (printOutPath) {
|
|
|
|
string outPath = i->queryOutPath(globals.state);
|
|
|
|
if (xmlOutput) {
|
|
|
|
if (outPath != "") attrs["outPath"] = outPath;
|
|
|
|
} else
|
|
|
|
columns.push_back(outPath);
|
|
|
|
}
|
2006-03-10 18:20:42 +02:00
|
|
|
|
|
|
|
if (printDescription) {
|
|
|
|
MetaInfo meta = i->queryMetaInfo(globals.state);
|
2006-08-03 18:52:09 +03:00
|
|
|
string descr = meta["description"];
|
|
|
|
if (xmlOutput) {
|
|
|
|
if (descr != "") attrs["description"] = descr;
|
|
|
|
} else
|
|
|
|
columns.push_back(descr);
|
2006-03-10 18:20:42 +02:00
|
|
|
}
|
2006-08-03 18:52:09 +03:00
|
|
|
|
2006-08-16 13:32:30 +03:00
|
|
|
if (xmlOutput)
|
2006-08-03 18:52:09 +03:00
|
|
|
xml.writeEmptyElement("item", attrs);
|
2006-08-16 13:32:30 +03:00
|
|
|
else
|
2006-08-03 18:52:09 +03:00
|
|
|
table.push_back(columns);
|
|
|
|
|
|
|
|
} catch (AssertionError & e) {
|
|
|
|
/* !!! hm, maybe we should give some sort of warning here? */
|
2006-03-08 18:03:58 +02:00
|
|
|
}
|
2003-11-19 19:27:16 +02:00
|
|
|
}
|
2004-07-01 16:35:10 +03:00
|
|
|
|
2006-08-03 18:52:09 +03:00
|
|
|
if (!xmlOutput) printTable(table);
|
2003-11-19 19:27:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-01-05 13:18:59 +02:00
|
|
|
static void opSwitchProfile(Globals & globals,
|
|
|
|
Strings opFlags, Strings opArgs)
|
|
|
|
{
|
|
|
|
if (opFlags.size() > 0)
|
2004-02-06 18:03:27 +02:00
|
|
|
throw UsageError(format("unknown flag `%1%'") % opFlags.front());
|
2004-02-06 12:59:06 +02:00
|
|
|
if (opArgs.size() != 1)
|
2004-02-06 18:03:27 +02:00
|
|
|
throw UsageError(format("exactly one argument expected"));
|
2004-01-05 13:18:59 +02:00
|
|
|
|
2004-02-06 12:59:06 +02:00
|
|
|
Path profile = opArgs.front();
|
|
|
|
Path profileLink = getHomeDir() + "/.nix-profile";
|
2004-01-05 13:18:59 +02:00
|
|
|
|
2004-09-10 00:12:53 +03:00
|
|
|
SwitchToOriginalUser sw;
|
2004-02-06 12:30:20 +02:00
|
|
|
switchLink(profileLink, profile);
|
2004-01-05 18:26:43 +02:00
|
|
|
}
|
2004-01-05 13:18:59 +02:00
|
|
|
|
2004-01-05 18:26:43 +02:00
|
|
|
|
2004-02-08 16:07:43 +02:00
|
|
|
static const int prevGen = -2;
|
|
|
|
|
|
|
|
|
|
|
|
static void switchGeneration(Globals & globals, int dstGen)
|
|
|
|
{
|
2006-09-15 01:33:53 +03:00
|
|
|
PathLocks lock;
|
|
|
|
lockProfile(lock, globals.profile);
|
|
|
|
|
2004-02-08 16:07:43 +02:00
|
|
|
int curGen;
|
|
|
|
Generations gens = findGenerations(globals.profile, curGen);
|
|
|
|
|
|
|
|
Generation dst;
|
|
|
|
for (Generations::iterator i = gens.begin(); i != gens.end(); ++i)
|
|
|
|
if ((dstGen == prevGen && i->number < curGen) ||
|
|
|
|
(dstGen >= 0 && i->number == dstGen))
|
|
|
|
dst = *i;
|
|
|
|
|
|
|
|
if (!dst)
|
|
|
|
if (dstGen == prevGen)
|
|
|
|
throw Error(format("no generation older than the current (%1%) exists")
|
|
|
|
% curGen);
|
|
|
|
else
|
|
|
|
throw Error(format("generation %1% does not exist") % dstGen);
|
|
|
|
|
2004-02-10 15:42:58 +02:00
|
|
|
printMsg(lvlInfo, format("switching from generation %1% to %2%")
|
|
|
|
% curGen % dst.number);
|
|
|
|
|
|
|
|
if (globals.dryRun) return;
|
|
|
|
|
2004-02-08 16:07:43 +02:00
|
|
|
switchLink(globals.profile, dst.path);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void opSwitchGeneration(Globals & globals,
|
|
|
|
Strings opFlags, Strings opArgs)
|
|
|
|
{
|
|
|
|
if (opFlags.size() > 0)
|
|
|
|
throw UsageError(format("unknown flag `%1%'") % opFlags.front());
|
|
|
|
if (opArgs.size() != 1)
|
|
|
|
throw UsageError(format("exactly one argument expected"));
|
|
|
|
|
|
|
|
int dstGen;
|
2004-09-10 16:32:08 +03:00
|
|
|
if (!string2Int(opArgs.front(), dstGen))
|
2004-02-08 16:07:43 +02:00
|
|
|
throw UsageError(format("expected a generation number"));
|
|
|
|
|
|
|
|
switchGeneration(globals, dstGen);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void opRollback(Globals & globals,
|
|
|
|
Strings opFlags, Strings opArgs)
|
|
|
|
{
|
|
|
|
if (opFlags.size() > 0)
|
|
|
|
throw UsageError(format("unknown flag `%1%'") % opFlags.front());
|
|
|
|
if (opArgs.size() != 0)
|
|
|
|
throw UsageError(format("no arguments expected"));
|
|
|
|
|
|
|
|
switchGeneration(globals, prevGen);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-06 18:03:27 +02:00
|
|
|
static void opListGenerations(Globals & globals,
|
|
|
|
Strings opFlags, Strings opArgs)
|
|
|
|
{
|
|
|
|
if (opFlags.size() > 0)
|
|
|
|
throw UsageError(format("unknown flag `%1%'") % opFlags.front());
|
|
|
|
if (opArgs.size() != 0)
|
|
|
|
throw UsageError(format("no arguments expected"));
|
|
|
|
|
2006-09-15 01:33:53 +03:00
|
|
|
PathLocks lock;
|
|
|
|
lockProfile(lock, globals.profile);
|
|
|
|
|
2004-02-06 18:16:55 +02:00
|
|
|
int curGen;
|
|
|
|
Generations gens = findGenerations(globals.profile, curGen);
|
2004-02-06 18:03:27 +02:00
|
|
|
|
|
|
|
for (Generations::iterator i = gens.begin(); i != gens.end(); ++i) {
|
|
|
|
tm t;
|
|
|
|
if (!localtime_r(&i->creationTime, &t)) throw Error("cannot convert time");
|
2004-02-06 18:16:55 +02:00
|
|
|
cout << format("%|4| %|4|-%|02|-%|02| %|02|:%|02|:%|02| %||\n")
|
2004-02-06 18:03:27 +02:00
|
|
|
% i->number
|
|
|
|
% (t.tm_year + 1900) % (t.tm_mon + 1) % t.tm_mday
|
2004-02-06 18:16:55 +02:00
|
|
|
% t.tm_hour % t.tm_min % t.tm_sec
|
|
|
|
% (i->number == curGen ? "(current)" : "");
|
2004-02-06 18:03:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-09-10 16:32:08 +03:00
|
|
|
static void deleteGeneration2(const Path & profile, unsigned int gen)
|
|
|
|
{
|
|
|
|
printMsg(lvlInfo, format("removing generation %1%") % gen);
|
|
|
|
deleteGeneration(profile, gen);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void opDeleteGenerations(Globals & globals,
|
|
|
|
Strings opFlags, Strings opArgs)
|
|
|
|
{
|
|
|
|
if (opFlags.size() > 0)
|
|
|
|
throw UsageError(format("unknown flag `%1%'") % opFlags.front());
|
|
|
|
|
2006-09-15 01:33:53 +03:00
|
|
|
PathLocks lock;
|
|
|
|
lockProfile(lock, globals.profile);
|
|
|
|
|
2004-09-10 16:32:08 +03:00
|
|
|
int curGen;
|
|
|
|
Generations gens = findGenerations(globals.profile, curGen);
|
|
|
|
|
|
|
|
for (Strings::iterator i = opArgs.begin(); i != opArgs.end(); ++i) {
|
|
|
|
|
|
|
|
if (*i == "old") {
|
|
|
|
for (Generations::iterator j = gens.begin(); j != gens.end(); ++j)
|
|
|
|
if (j->number != curGen)
|
|
|
|
deleteGeneration2(globals.profile, j->number);
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
int n;
|
|
|
|
if (!string2Int(*i, n) || n < 0)
|
|
|
|
throw UsageError(format("invalid generation specifier `%1%'") % *i);
|
|
|
|
bool found = false;
|
|
|
|
for (Generations::iterator j = gens.begin(); j != gens.end(); ++j) {
|
|
|
|
if (j->number == n) {
|
|
|
|
deleteGeneration2(globals.profile, j->number);
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found)
|
|
|
|
printMsg(lvlError, format("generation %1% does not exist") % n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-01-05 18:26:43 +02:00
|
|
|
static void opDefaultExpr(Globals & globals,
|
|
|
|
Strings opFlags, Strings opArgs)
|
|
|
|
{
|
|
|
|
if (opFlags.size() > 0)
|
2006-07-25 14:53:22 +03:00
|
|
|
throw UsageError(format("unknown flag `%1%'") % opFlags.front());
|
2004-01-05 18:26:43 +02:00
|
|
|
if (opArgs.size() != 1)
|
2004-02-06 18:03:27 +02:00
|
|
|
throw UsageError(format("exactly one argument expected"));
|
2004-01-05 18:26:43 +02:00
|
|
|
|
2004-01-20 22:36:58 +02:00
|
|
|
Path defNixExpr = absPath(opArgs.front());
|
2004-01-05 18:26:43 +02:00
|
|
|
Path defNixExprLink = getDefNixExprPath();
|
2004-01-05 13:18:59 +02:00
|
|
|
|
2004-09-10 00:12:53 +03:00
|
|
|
SwitchToOriginalUser sw;
|
2004-01-05 18:26:43 +02:00
|
|
|
switchLink(defNixExprLink, defNixExpr);
|
2004-01-05 13:18:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-14 18:16:02 +02:00
|
|
|
static string needArg(Strings::iterator & i,
|
2005-05-04 19:33:20 +03:00
|
|
|
Strings & args, const string & arg)
|
2005-02-14 18:16:02 +02:00
|
|
|
{
|
|
|
|
++i;
|
|
|
|
if (i == args.end()) throw UsageError(
|
|
|
|
format("`%1%' requires an argument") % arg);
|
|
|
|
return *i;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-19 19:27:16 +02:00
|
|
|
void run(Strings args)
|
|
|
|
{
|
|
|
|
Strings opFlags, opArgs;
|
|
|
|
Operation op = 0;
|
2003-12-22 00:34:41 +02:00
|
|
|
|
|
|
|
Globals globals;
|
2005-02-14 15:07:09 +02:00
|
|
|
|
2005-02-11 18:56:45 +02:00
|
|
|
globals.instSource.type = srcUnknown;
|
|
|
|
globals.instSource.nixExprPath = getDefNixExprPath();
|
|
|
|
globals.instSource.systemFilter = thisSystem;
|
|
|
|
|
2004-02-09 13:59:39 +02:00
|
|
|
globals.dryRun = false;
|
2004-06-28 17:40:26 +03:00
|
|
|
globals.preserveInstalled = false;
|
2003-11-19 19:27:16 +02:00
|
|
|
|
2005-02-14 15:07:09 +02:00
|
|
|
globals.keepDerivations =
|
|
|
|
queryBoolSetting("env-keep-derivations", false);
|
|
|
|
|
2003-11-19 19:27:16 +02:00
|
|
|
for (Strings::iterator i = args.begin(); i != args.end(); ++i) {
|
|
|
|
string arg = *i;
|
|
|
|
|
|
|
|
Operation oldOp = op;
|
|
|
|
|
|
|
|
if (arg == "--install" || arg == "-i")
|
|
|
|
op = opInstall;
|
2005-02-14 18:16:02 +02:00
|
|
|
else if (arg == "--from-expression" || arg == "-E")
|
|
|
|
globals.instSource.type = srcNixExprs;
|
|
|
|
else if (arg == "--from-profile") {
|
|
|
|
globals.instSource.type = srcProfile;
|
|
|
|
globals.instSource.profile = needArg(i, args, arg);
|
|
|
|
}
|
2006-07-25 14:53:22 +03:00
|
|
|
else if (arg == "--attr" || arg == "-A")
|
|
|
|
globals.instSource.type = srcAttrPath;
|
2006-08-23 19:33:21 +03:00
|
|
|
else if (arg == "--arg") { /* !!! code duplication from nix-instantiate */
|
|
|
|
i++;
|
|
|
|
if (i == args.end())
|
|
|
|
throw UsageError("`--arg' requires two arguments");
|
|
|
|
string name = *i++;
|
|
|
|
if (i == args.end())
|
|
|
|
throw UsageError("`--arg' requires two arguments");
|
|
|
|
Expr value = parseExprFromString(globals.state, *i, absPath("."));
|
|
|
|
globals.instSource.autoArgs.set(toATerm(name), value);
|
|
|
|
}
|
2006-09-25 17:00:59 +03:00
|
|
|
else if (arg == "--force-name") // undocumented flag for nix-install-package
|
|
|
|
globals.forceName = needArg(i, args, arg);
|
2003-12-22 00:34:41 +02:00
|
|
|
else if (arg == "--uninstall" || arg == "-e")
|
2003-11-20 15:48:48 +02:00
|
|
|
op = opUninstall;
|
2003-12-22 01:58:56 +02:00
|
|
|
else if (arg == "--upgrade" || arg == "-u")
|
|
|
|
op = opUpgrade;
|
2003-11-20 15:48:48 +02:00
|
|
|
else if (arg == "--query" || arg == "-q")
|
2003-11-19 19:27:16 +02:00
|
|
|
op = opQuery;
|
2004-01-05 18:26:43 +02:00
|
|
|
else if (arg == "--import" || arg == "-I") /* !!! bad name */
|
|
|
|
op = opDefaultExpr;
|
2004-02-06 12:30:20 +02:00
|
|
|
else if (arg == "--profile" || arg == "-p") {
|
2005-02-14 18:16:02 +02:00
|
|
|
globals.profile = absPath(needArg(i, args, arg));
|
2003-12-22 00:34:41 +02:00
|
|
|
}
|
2004-01-05 18:26:43 +02:00
|
|
|
else if (arg == "--file" || arg == "-f") {
|
2005-02-14 18:16:02 +02:00
|
|
|
globals.instSource.nixExprPath = absPath(needArg(i, args, arg));
|
2004-01-05 18:26:43 +02:00
|
|
|
}
|
2004-02-06 12:30:20 +02:00
|
|
|
else if (arg == "--switch-profile" || arg == "-S")
|
2004-01-05 13:18:59 +02:00
|
|
|
op = opSwitchProfile;
|
2004-02-08 16:07:43 +02:00
|
|
|
else if (arg == "--switch-generation" || arg == "-G")
|
|
|
|
op = opSwitchGeneration;
|
|
|
|
else if (arg == "--rollback")
|
|
|
|
op = opRollback;
|
2004-02-06 18:03:27 +02:00
|
|
|
else if (arg == "--list-generations")
|
|
|
|
op = opListGenerations;
|
2004-09-10 16:32:08 +03:00
|
|
|
else if (arg == "--delete-generations")
|
|
|
|
op = opDeleteGenerations;
|
2004-02-09 13:59:39 +02:00
|
|
|
else if (arg == "--dry-run") {
|
|
|
|
printMsg(lvlInfo, "(dry run; not doing anything)");
|
|
|
|
globals.dryRun = true;
|
|
|
|
}
|
2004-06-28 17:40:26 +03:00
|
|
|
else if (arg == "--preserve-installed" || arg == "-P")
|
|
|
|
globals.preserveInstalled = true;
|
2004-07-01 16:56:56 +03:00
|
|
|
else if (arg == "--system-filter") {
|
2005-02-14 18:16:02 +02:00
|
|
|
globals.instSource.systemFilter = needArg(i, args, arg);
|
2004-07-01 16:56:56 +03:00
|
|
|
}
|
2003-12-02 12:21:40 +02:00
|
|
|
else if (arg[0] == '-')
|
|
|
|
opFlags.push_back(arg);
|
2003-11-19 19:27:16 +02:00
|
|
|
else
|
|
|
|
opArgs.push_back(arg);
|
|
|
|
|
|
|
|
if (oldOp && oldOp != op)
|
|
|
|
throw UsageError("only one operation may be specified");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!op) throw UsageError("no operation specified");
|
|
|
|
|
2004-02-06 12:59:06 +02:00
|
|
|
if (globals.profile == "") {
|
2004-09-10 00:12:53 +03:00
|
|
|
SwitchToOriginalUser sw;
|
2004-02-06 12:59:06 +02:00
|
|
|
Path profileLink = getHomeDir() + "/.nix-profile";
|
|
|
|
globals.profile = pathExists(profileLink)
|
|
|
|
? absPath(readLink(profileLink), dirOf(profileLink))
|
|
|
|
: canonPath(nixStateDir + "/profiles/default");
|
|
|
|
}
|
|
|
|
|
2003-11-19 19:27:16 +02:00
|
|
|
openDB();
|
|
|
|
|
2003-12-22 00:34:41 +02:00
|
|
|
op(globals, opFlags, opArgs);
|
2003-11-19 19:27:16 +02:00
|
|
|
|
2003-12-22 00:34:41 +02:00
|
|
|
printEvalStats(globals.state);
|
2003-11-19 19:27:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string programId = "nix-env";
|