2004-02-06 14:57:10 +00:00
|
|
|
#include "profiles.hh"
|
2004-02-06 14:49:41 +00:00
|
|
|
#include "names.hh"
|
2003-11-19 17:27:16 +00:00
|
|
|
#include "globals.hh"
|
2006-03-06 11:21:15 +00:00
|
|
|
#include "misc.hh"
|
2003-11-19 17:27:16 +00:00
|
|
|
#include "shared.hh"
|
|
|
|
#include "parser.hh"
|
|
|
|
#include "eval.hh"
|
2003-12-01 15:55:05 +00:00
|
|
|
#include "help.txt.hh"
|
2004-10-29 11:22:49 +00:00
|
|
|
#include "nixexpr-ast.hh"
|
2006-02-08 13:21:16 +00:00
|
|
|
#include "get-drvs.hh"
|
2006-07-26 15:05:15 +00:00
|
|
|
#include "attr-path.hh"
|
2006-06-15 11:56:49 +00:00
|
|
|
#include "pathlocks.hh"
|
2007-01-14 12:32:44 +00:00
|
|
|
#include "common-opts.hh"
|
2006-08-03 15:52:09 +00:00
|
|
|
#include "xml-writer.hh"
|
2006-11-30 17:43:04 +00:00
|
|
|
#include "store-api.hh"
|
2006-09-04 21:06:23 +00:00
|
|
|
#include "db.hh"
|
|
|
|
#include "util.hh"
|
2003-11-19 17:27:16 +00:00
|
|
|
|
2004-02-06 16:03:27 +00:00
|
|
|
#include <cerrno>
|
|
|
|
#include <ctime>
|
2005-05-04 16:33:20 +00:00
|
|
|
#include <algorithm>
|
2006-03-01 17:44:28 +00:00
|
|
|
#include <iostream>
|
2006-08-03 15:52:09 +00:00
|
|
|
#include <sstream>
|
2004-02-06 16:03:27 +00:00
|
|
|
|
2007-09-17 16:08:24 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2005-10-06 15:01:46 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2003-11-19 17:27:16 +00:00
|
|
|
|
2006-09-04 21:06:23 +00:00
|
|
|
using namespace nix;
|
|
|
|
using std::cout;
|
|
|
|
|
|
|
|
|
2005-02-11 16:56:45 +00:00
|
|
|
typedef enum {
|
|
|
|
srcNixExprDrvs,
|
|
|
|
srcNixExprs,
|
|
|
|
srcStorePaths,
|
|
|
|
srcProfile,
|
2006-07-25 11:53:22 +00:00
|
|
|
srcAttrPath,
|
2005-02-11 16:56:45 +00:00
|
|
|
srcUnknown
|
|
|
|
} InstallSourceType;
|
|
|
|
|
|
|
|
|
|
|
|
struct InstallSourceInfo
|
|
|
|
{
|
|
|
|
InstallSourceType type;
|
|
|
|
Path nixExprPath; /* for srcNixExprDrvs, srcNixExprs */
|
|
|
|
Path profile; /* for srcProfile */
|
|
|
|
string systemFilter; /* for srcNixExprDrvs */
|
2007-10-29 14:31:45 +00:00
|
|
|
bool prebuiltOnly;
|
2006-08-23 16:33:21 +00:00
|
|
|
ATermMap autoArgs;
|
2007-10-29 14:31:45 +00:00
|
|
|
InstallSourceInfo() : prebuiltOnly(false) { };
|
2005-02-11 16:56:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-12-21 22:34:41 +00:00
|
|
|
struct Globals
|
|
|
|
{
|
2005-02-11 16:56:45 +00:00
|
|
|
InstallSourceInfo instSource;
|
2004-02-06 10:30:20 +00:00
|
|
|
Path profile;
|
2003-12-21 22:34:41 +00:00
|
|
|
EvalState state;
|
2004-02-09 11:59:39 +00:00
|
|
|
bool dryRun;
|
2004-06-28 14:40:26 +00:00
|
|
|
bool preserveInstalled;
|
2005-02-14 13:07:09 +00:00
|
|
|
bool keepDerivations;
|
2006-09-25 14:00:59 +00:00
|
|
|
string forceName;
|
2003-12-21 22:34:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
typedef void (* Operation) (Globals & globals,
|
2007-09-17 19:24:07 +00:00
|
|
|
Strings args, Strings opFlags, Strings opArgs);
|
2003-11-19 17:27:16 +00:00
|
|
|
|
|
|
|
|
2003-12-01 15:55:05 +00:00
|
|
|
void printHelp()
|
|
|
|
{
|
|
|
|
cout << string((char *) helpText, sizeof helpText);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-17 19:24:07 +00:00
|
|
|
static string needArg(Strings::iterator & i,
|
|
|
|
Strings & args, const string & arg)
|
|
|
|
{
|
|
|
|
if (i == args.end()) throw UsageError(
|
|
|
|
format("`%1%' requires an argument") % arg);
|
|
|
|
return *i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool parseInstallSourceOptions(Globals & globals,
|
|
|
|
Strings::iterator & i, Strings & args, const string & arg)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
else if (arg == "--attr" || arg == "-A")
|
|
|
|
globals.instSource.type = srcAttrPath;
|
2007-10-29 14:31:45 +00:00
|
|
|
else if (arg == "--prebuilt-only" || arg == "-b")
|
|
|
|
globals.instSource.prebuiltOnly = true;
|
2007-09-17 19:24:07 +00:00
|
|
|
else return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-17 16:08:24 +00:00
|
|
|
static bool isNixExpr(const Path & path)
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
if (stat(path.c_str(), &st) == -1)
|
|
|
|
throw SysError(format("getting information about `%1%'") % path);
|
|
|
|
|
|
|
|
return !S_ISDIR(st.st_mode) || pathExists(path + "/default.nix");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void getAllExprs(EvalState & state,
|
|
|
|
const Path & path, ATermMap & attrs)
|
|
|
|
{
|
|
|
|
Strings names = readDirectory(path);
|
|
|
|
|
|
|
|
for (Strings::iterator i = names.begin(); i != names.end(); ++i) {
|
|
|
|
Path path2 = path + "/" + *i;
|
2007-09-18 14:01:14 +00:00
|
|
|
|
|
|
|
struct stat st;
|
|
|
|
if (stat(path2.c_str(), &st) == -1)
|
|
|
|
continue; // ignore dangling symlinks in ~/.nix-defexpr
|
|
|
|
|
2007-09-17 16:08:24 +00:00
|
|
|
if (isNixExpr(path2))
|
|
|
|
attrs.set(toATerm(*i), makeAttrRHS(
|
2007-09-18 14:01:14 +00:00
|
|
|
parseExprFromFile(state, absPath(path2)), makeNoPos()));
|
2007-09-17 16:08:24 +00:00
|
|
|
else
|
|
|
|
getAllExprs(state, path2, attrs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Expr loadSourceExpr(EvalState & state, const Path & path)
|
|
|
|
{
|
|
|
|
if (isNixExpr(path)) return parseExprFromFile(state, absPath(path));
|
|
|
|
|
|
|
|
/* The path is a directory. Put the Nix expressions in the
|
|
|
|
directory in an attribute set, with the file name of each
|
|
|
|
expression as the attribute name. Recurse into subdirectories
|
|
|
|
(but keep the attribute set flat, not nested, to make it easier
|
|
|
|
for a user to have a ~/.nix-defexpr directory that includes
|
|
|
|
some system-wide directory). */
|
|
|
|
ATermMap attrs;
|
|
|
|
attrs.set(toATerm("_combineChannels"), makeAttrRHS(eTrue, makeNoPos()));
|
|
|
|
getAllExprs(state, path, attrs);
|
|
|
|
return makeAttrs(attrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-11 16:56:45 +00:00
|
|
|
static void loadDerivations(EvalState & state, Path nixExprPath,
|
2007-09-17 19:24:07 +00:00
|
|
|
string systemFilter, const ATermMap & autoArgs,
|
|
|
|
const string & pathPrefix, DrvInfos & elems)
|
2003-11-19 17:27:16 +00:00
|
|
|
{
|
2007-09-17 19:24:07 +00:00
|
|
|
getDerivations(state,
|
|
|
|
findAlongAttrPath(state, pathPrefix, autoArgs, loadSourceExpr(state, nixExprPath)),
|
|
|
|
pathPrefix, autoArgs, elems);
|
2004-07-01 13:56:56 +00:00
|
|
|
|
|
|
|
/* Filter out all derivations not applicable to the current
|
|
|
|
system. */
|
2006-02-08 13:21:16 +00:00
|
|
|
for (DrvInfos::iterator i = elems.begin(), j; i != elems.end(); i = j) {
|
2004-07-01 13:56:56 +00:00
|
|
|
j = i; j++;
|
2006-02-08 13:21:16 +00:00
|
|
|
if (systemFilter != "*" && i->system != systemFilter)
|
2005-02-14 16:16:02 +00:00
|
|
|
elems.erase(i);
|
2005-02-11 16:56:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-01-05 16:26:43 +00:00
|
|
|
static Path getHomeDir()
|
|
|
|
{
|
2004-05-12 09:35:51 +00:00
|
|
|
Path homeDir(getEnv("HOME", ""));
|
2004-01-05 16:26:43 +00:00
|
|
|
if (homeDir == "") throw Error("HOME environment variable not set");
|
|
|
|
return homeDir;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Path getDefNixExprPath()
|
|
|
|
{
|
|
|
|
return getHomeDir() + "/.nix-defexpr";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-04-05 22:27:41 +00:00
|
|
|
struct AddPos : TermFun
|
|
|
|
{
|
|
|
|
ATerm operator () (ATerm e)
|
|
|
|
{
|
2006-10-17 14:01:45 +00:00
|
|
|
ATerm x, y;
|
|
|
|
if (matchObsoleteBind(e, x, y))
|
2004-10-26 22:54:26 +00:00
|
|
|
return makeBind(x, y, makeNoPos());
|
2006-10-17 14:01:45 +00:00
|
|
|
if (matchObsoleteStr(e, x))
|
|
|
|
return makeStr(x, ATempty);
|
2004-04-05 22:27:41 +00:00
|
|
|
return e;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-02-08 13:21:16 +00:00
|
|
|
static DrvInfos queryInstalled(EvalState & state, const Path & userEnv)
|
2003-11-19 21:32:03 +00:00
|
|
|
{
|
2003-12-21 22:34:41 +00:00
|
|
|
Path path = userEnv + "/manifest";
|
2003-11-19 21:32:03 +00:00
|
|
|
|
2005-02-15 10:49:31 +00:00
|
|
|
if (!pathExists(path))
|
2006-02-08 13:21:16 +00:00
|
|
|
return DrvInfos(); /* not an error, assume nothing installed */
|
2003-11-19 21:32:03 +00:00
|
|
|
|
|
|
|
Expr e = ATreadFromNamedFile(path.c_str());
|
|
|
|
if (!e) throw Error(format("cannot read Nix expression from `%1%'") % path);
|
|
|
|
|
2004-04-05 22:27:41 +00:00
|
|
|
/* Compatibility: Bind(x, y) -> Bind(x, y, NoPos). */
|
|
|
|
AddPos addPos;
|
|
|
|
e = bottomupRewrite(addPos, e);
|
|
|
|
|
2006-02-08 13:21:16 +00:00
|
|
|
DrvInfos elems;
|
2006-07-28 16:03:28 +00:00
|
|
|
getDerivations(state, e, "", ATermMap(1), elems);
|
2005-02-15 10:49:31 +00:00
|
|
|
return elems;
|
2003-11-19 21:32:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-08 13:21:16 +00:00
|
|
|
static void createUserEnv(EvalState & state, const DrvInfos & elems,
|
2005-02-14 13:07:09 +00:00
|
|
|
const Path & profile, bool keepDerivations)
|
2003-11-19 17:27:16 +00:00
|
|
|
{
|
2005-02-11 16:56:45 +00:00
|
|
|
/* Build the components in the user environment, if they don't
|
|
|
|
exist already. */
|
|
|
|
PathSet drvsToBuild;
|
2006-02-08 13:21:16 +00:00
|
|
|
for (DrvInfos::const_iterator i = elems.begin();
|
2005-02-14 16:16:02 +00:00
|
|
|
i != elems.end(); ++i)
|
2005-02-17 15:48:50 +00:00
|
|
|
/* Call to `isDerivation' is for compatibility with Nix <= 0.7
|
|
|
|
user environments. */
|
2006-02-08 13:21:16 +00:00
|
|
|
if (i->queryDrvPath(state) != "" &&
|
|
|
|
isDerivation(i->queryDrvPath(state)))
|
|
|
|
drvsToBuild.insert(i->queryDrvPath(state));
|
2005-02-11 16:56:45 +00:00
|
|
|
|
|
|
|
debug(format("building user environment dependencies"));
|
2006-11-30 18:02:04 +00:00
|
|
|
store->buildDerivations(drvsToBuild);
|
2005-02-11 16:56:45 +00:00
|
|
|
|
2003-11-19 17:27:16 +00:00
|
|
|
/* Get the environment builder expression. */
|
2004-02-04 16:03:29 +00:00
|
|
|
Expr envBuilder = parseExprFromFile(state,
|
|
|
|
nixDataDir + "/nix/corepkgs/buildenv"); /* !!! */
|
2003-11-19 17:27:16 +00:00
|
|
|
|
|
|
|
/* Construct the whole top level derivation. */
|
2005-02-11 16:56:45 +00:00
|
|
|
PathSet references;
|
|
|
|
ATermList manifest = ATempty;
|
2003-11-19 17:27:16 +00:00
|
|
|
ATermList inputs = ATempty;
|
2006-02-08 13:21:16 +00:00
|
|
|
for (DrvInfos::const_iterator i = elems.begin();
|
2005-02-14 16:16:02 +00:00
|
|
|
i != elems.end(); ++i)
|
2003-11-19 17:27:16 +00:00
|
|
|
{
|
2007-02-02 01:52:42 +00:00
|
|
|
/* Create a pseudo-derivation containing the name, system,
|
|
|
|
output path, and optionally the derivation path, as well as
|
|
|
|
the meta attributes. */
|
2006-02-08 13:21:16 +00:00
|
|
|
Path drvPath = keepDerivations ? i->queryDrvPath(state) : "";
|
2007-02-02 01:52:42 +00:00
|
|
|
|
2006-10-17 10:15:42 +00:00
|
|
|
ATermList as = ATmakeList4(
|
2004-11-03 18:12:03 +00:00
|
|
|
makeBind(toATerm("type"),
|
2006-10-16 15:55:34 +00:00
|
|
|
makeStr("derivation"), makeNoPos()),
|
2004-11-03 18:12:03 +00:00
|
|
|
makeBind(toATerm("name"),
|
2006-10-16 15:55:34 +00:00
|
|
|
makeStr(i->name), makeNoPos()),
|
2004-11-03 18:12:03 +00:00
|
|
|
makeBind(toATerm("system"),
|
2006-10-16 15:55:34 +00:00
|
|
|
makeStr(i->system), makeNoPos()),
|
2004-11-03 18:12:03 +00:00
|
|
|
makeBind(toATerm("outPath"),
|
2006-10-17 10:15:42 +00:00
|
|
|
makeStr(i->queryOutPath(state)), makeNoPos()));
|
2007-02-02 01:52:42 +00:00
|
|
|
|
2006-10-17 10:15:42 +00:00
|
|
|
if (drvPath != "") as = ATinsert(as,
|
|
|
|
makeBind(toATerm("drvPath"),
|
|
|
|
makeStr(drvPath), makeNoPos()));
|
2007-02-02 01:52:42 +00:00
|
|
|
|
|
|
|
if (i->attrs->get(toATerm("meta"))) as = ATinsert(as,
|
|
|
|
makeBind(toATerm("meta"),
|
|
|
|
strictEvalExpr(state, i->attrs->get(toATerm("meta"))),
|
|
|
|
makeNoPos()));
|
|
|
|
|
2006-10-17 10:15:42 +00:00
|
|
|
manifest = ATinsert(manifest, makeAttrs(as));
|
2007-02-02 01:52:42 +00:00
|
|
|
|
2006-10-16 15:55:34 +00:00
|
|
|
inputs = ATinsert(inputs, makeStr(i->queryOutPath(state)));
|
2005-02-14 17:35:10 +00:00
|
|
|
|
|
|
|
/* This is only necessary when installing store paths, e.g.,
|
|
|
|
`nix-env -i /nix/store/abcd...-foo'. */
|
2006-12-02 16:41:36 +00:00
|
|
|
store->addTempRoot(i->queryOutPath(state));
|
2006-11-30 18:02:04 +00:00
|
|
|
store->ensurePath(i->queryOutPath(state));
|
2005-02-14 17:35:10 +00:00
|
|
|
|
2006-02-08 13:21:16 +00:00
|
|
|
references.insert(i->queryOutPath(state));
|
2005-02-14 13:07:09 +00:00
|
|
|
if (drvPath != "") references.insert(drvPath);
|
2003-11-19 17:27:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Also write a copy of the list of inputs to the store; we need
|
|
|
|
it for future modifications of the environment. */
|
2006-11-30 17:43:04 +00:00
|
|
|
Path manifestFile = store->addTextToStore("env-manifest",
|
2007-02-02 01:52:42 +00:00
|
|
|
atPrint(canonicaliseExpr(makeList(ATreverse(manifest)))), references);
|
2005-02-11 16:56:45 +00:00
|
|
|
|
2004-10-26 22:54:26 +00:00
|
|
|
Expr topLevel = makeCall(envBuilder, makeAttrs(ATmakeList3(
|
2004-11-03 18:12:03 +00:00
|
|
|
makeBind(toATerm("system"),
|
2006-10-16 15:55:34 +00:00
|
|
|
makeStr(thisSystem), makeNoPos()),
|
2005-02-11 16:56:45 +00:00
|
|
|
makeBind(toATerm("derivations"),
|
2007-02-02 01:52:42 +00:00
|
|
|
makeList(ATreverse(manifest)), makeNoPos()),
|
2004-11-03 18:12:03 +00:00
|
|
|
makeBind(toATerm("manifest"),
|
2006-10-17 12:15:15 +00:00
|
|
|
makeStr(manifestFile, singleton<PathSet>(manifestFile)), makeNoPos())
|
2004-10-26 22:54:26 +00:00
|
|
|
)));
|
2003-11-19 17:27:16 +00:00
|
|
|
|
|
|
|
/* Instantiate it. */
|
|
|
|
debug(format("evaluating builder expression `%1%'") % topLevel);
|
2006-02-08 13:21:16 +00:00
|
|
|
DrvInfo topLevelDrv;
|
|
|
|
if (!getDerivation(state, topLevel, topLevelDrv))
|
2003-11-19 17:27:16 +00:00
|
|
|
abort();
|
|
|
|
|
|
|
|
/* Realise the resulting store expression. */
|
2005-01-19 11:16:11 +00:00
|
|
|
debug(format("building user environment"));
|
2006-11-30 18:02:04 +00:00
|
|
|
store->buildDerivations(singleton<PathSet>(topLevelDrv.queryDrvPath(state)));
|
2003-11-19 17:27:16 +00:00
|
|
|
|
|
|
|
/* Switch the current user environment to the output path. */
|
|
|
|
debug(format("switching to new user environment"));
|
2005-05-08 10:32:09 +00:00
|
|
|
Path generation = createGeneration(profile, topLevelDrv.queryOutPath(state));
|
2004-02-06 10:30:20 +00:00
|
|
|
switchLink(profile, generation);
|
2003-11-19 17:27:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-01 20:33:18 +00:00
|
|
|
static int comparePriorities(EvalState & state,
|
|
|
|
const DrvInfo & drv1, const DrvInfo & drv2)
|
|
|
|
{
|
|
|
|
int prio1, prio2;
|
|
|
|
if (!string2Int(drv1.queryMetaInfo(state, "priority"), prio1)) prio1 = 0;
|
|
|
|
if (!string2Int(drv2.queryMetaInfo(state, "priority"), prio2)) prio2 = 0;
|
|
|
|
return prio2 - prio1; /* higher number = lower priority, so negate */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-29 14:31:45 +00:00
|
|
|
static bool isPrebuilt(EvalState & state, const DrvInfo & elem)
|
|
|
|
{
|
|
|
|
return
|
|
|
|
store->isValidPath(elem.queryOutPath(state)) ||
|
|
|
|
store->hasSubstitutes(elem.queryOutPath(state));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static DrvInfos filterBySelector(EvalState & state, const DrvInfos & allElems,
|
|
|
|
const Strings & args, bool newestOnly, bool prebuiltOnly)
|
2005-02-15 10:49:31 +00:00
|
|
|
{
|
|
|
|
DrvNames selectors = drvNamesFromArgs(args);
|
|
|
|
|
2006-02-08 13:21:16 +00:00
|
|
|
DrvInfos elems;
|
2006-03-10 10:24:46 +00:00
|
|
|
set<unsigned int> done;
|
2005-02-15 10:49:31 +00:00
|
|
|
|
2006-02-17 17:47:54 +00:00
|
|
|
for (DrvNames::iterator i = selectors.begin();
|
|
|
|
i != selectors.end(); ++i)
|
|
|
|
{
|
2006-09-04 21:06:23 +00:00
|
|
|
typedef list<std::pair<DrvInfo, unsigned int> > Matches;
|
2006-03-10 10:24:46 +00:00
|
|
|
Matches matches;
|
|
|
|
unsigned int n = 0;
|
2006-02-17 17:47:54 +00:00
|
|
|
for (DrvInfos::const_iterator j = allElems.begin();
|
2006-03-10 10:24:46 +00:00
|
|
|
j != allElems.end(); ++j, ++n)
|
2006-02-17 17:47:54 +00:00
|
|
|
{
|
|
|
|
DrvName drvName(j->name);
|
|
|
|
if (i->matches(drvName)) {
|
|
|
|
i->hits++;
|
2007-10-29 14:31:45 +00:00
|
|
|
if (!prebuiltOnly || isPrebuilt(state, *j))
|
|
|
|
matches.push_back(std::pair<DrvInfo, unsigned int>(*j, n));
|
2006-02-17 17:47:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-17 18:11:45 +00:00
|
|
|
/* If `newestOnly', if a selector matches multiple derivations
|
2007-05-01 20:33:18 +00:00
|
|
|
with the same name, pick the one with the highest priority.
|
|
|
|
If there are multiple derivations with the same priority,
|
|
|
|
pick the one with the highest version. If there are
|
|
|
|
multiple derivations with the same priority and name and
|
2006-02-17 18:11:45 +00:00
|
|
|
version, then pick the first one. */
|
2006-02-17 17:47:54 +00:00
|
|
|
if (newestOnly) {
|
|
|
|
|
|
|
|
/* Map from package names to derivations. */
|
2006-09-04 21:06:23 +00:00
|
|
|
typedef map<string, std::pair<DrvInfo, unsigned int> > Newest;
|
2006-03-10 10:24:46 +00:00
|
|
|
Newest newest;
|
2006-02-17 18:11:45 +00:00
|
|
|
StringSet multiple;
|
2006-02-17 17:47:54 +00:00
|
|
|
|
2006-03-10 10:24:46 +00:00
|
|
|
for (Matches::iterator j = matches.begin(); j != matches.end(); ++j) {
|
|
|
|
DrvName drvName(j->first.name);
|
2007-05-01 20:33:18 +00:00
|
|
|
int d = 1;
|
|
|
|
|
2006-03-10 10:24:46 +00:00
|
|
|
Newest::iterator k = newest.find(drvName.name);
|
2007-05-01 20:33:18 +00:00
|
|
|
|
2006-02-17 18:11:45 +00:00
|
|
|
if (k != newest.end()) {
|
2007-05-01 20:33:18 +00:00
|
|
|
d = comparePriorities(state, j->first, k->second.first);
|
|
|
|
if (d == 0)
|
|
|
|
d = compareVersions(drvName.version, DrvName(k->second.first.name).version);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d > 0) {
|
2006-02-17 17:47:54 +00:00
|
|
|
newest[drvName.name] = *j;
|
2007-05-01 20:33:18 +00:00
|
|
|
multiple.erase(j->first.name);
|
|
|
|
} else if (d == 0) {
|
|
|
|
multiple.insert(j->first.name);
|
|
|
|
}
|
2006-02-17 17:47:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
matches.clear();
|
2006-03-10 10:24:46 +00:00
|
|
|
for (Newest::iterator j = newest.begin(); j != newest.end(); ++j) {
|
|
|
|
if (multiple.find(j->second.first.name) != multiple.end())
|
2006-02-17 18:11:45 +00:00
|
|
|
printMsg(lvlInfo,
|
|
|
|
format("warning: there are multiple derivations named `%1%'; using the first one")
|
2006-03-10 10:24:46 +00:00
|
|
|
% j->second.first.name);
|
2006-02-17 17:47:54 +00:00
|
|
|
matches.push_back(j->second);
|
2006-02-17 18:11:45 +00:00
|
|
|
}
|
2006-02-17 17:47:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Insert only those elements in the final list that we
|
|
|
|
haven't inserted before. */
|
2006-03-10 10:24:46 +00: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 17:47:54 +00:00
|
|
|
}
|
|
|
|
}
|
2005-02-15 10:49:31 +00:00
|
|
|
|
|
|
|
/* Check that all selectors have been used. */
|
|
|
|
for (DrvNames::iterator i = selectors.begin();
|
|
|
|
i != selectors.end(); ++i)
|
2007-11-29 16:18:24 +00:00
|
|
|
if (i->hits == 0 && i->fullName != "*")
|
2005-02-15 10:49:31 +00:00
|
|
|
throw Error(format("selector `%1%' matches no derivations")
|
|
|
|
% i->fullName);
|
|
|
|
|
|
|
|
return elems;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-29 16:18:24 +00:00
|
|
|
static bool isPath(const string & s)
|
|
|
|
{
|
|
|
|
return s.find('/') != string::npos;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-14 16:16:02 +00:00
|
|
|
static void queryInstSources(EvalState & state,
|
|
|
|
const InstallSourceInfo & instSource, const Strings & args,
|
2006-02-17 17:47:54 +00:00
|
|
|
DrvInfos & elems, bool newestOnly)
|
2003-11-20 13:48:48 +00:00
|
|
|
{
|
2005-02-14 17:35:10 +00:00
|
|
|
InstallSourceType type = instSource.type;
|
2007-11-29 16:18:24 +00:00
|
|
|
if (type == srcUnknown && args.size() > 0 && isPath(args.front()))
|
2005-02-14 17:35:10 +00:00
|
|
|
type = srcStorePaths;
|
|
|
|
|
|
|
|
switch (type) {
|
2003-11-20 13:48:48 +00:00
|
|
|
|
2005-02-14 16:16:02 +00: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 13:21:16 +00:00
|
|
|
DrvInfos allElems;
|
2005-02-14 16:16:02 +00:00
|
|
|
loadDerivations(state, instSource.nixExprPath,
|
2007-09-17 19:24:07 +00:00
|
|
|
instSource.systemFilter, instSource.autoArgs, "", allElems);
|
2005-02-14 16:16:02 +00:00
|
|
|
|
2007-10-29 14:31:45 +00:00
|
|
|
elems = filterBySelector(state, allElems, args,
|
|
|
|
newestOnly, instSource.prebuiltOnly);
|
2005-02-14 16:16:02 +00:00
|
|
|
|
|
|
|
break;
|
2003-11-24 11:01:19 +00:00
|
|
|
}
|
2005-02-14 16:16:02 +00:00
|
|
|
|
2005-02-14 17:07:43 +00: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 12:05:47 +00:00
|
|
|
case srcNixExprs: {
|
|
|
|
|
2007-09-17 16:08:24 +00:00
|
|
|
Expr e1 = loadSourceExpr(state, instSource.nixExprPath);
|
2005-02-14 17:07:43 +00:00
|
|
|
|
|
|
|
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 16:33:21 +00:00
|
|
|
getDerivations(state, call, "", instSource.autoArgs, elems);
|
2005-02-14 17:07:43 +00:00
|
|
|
}
|
|
|
|
|
2005-02-14 16:16:02 +00:00
|
|
|
break;
|
2005-02-15 12:05:47 +00: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 17:35:10 +00:00
|
|
|
|
|
|
|
for (Strings::const_iterator i = args.begin();
|
|
|
|
i != args.end(); ++i)
|
|
|
|
{
|
2007-11-29 16:18:24 +00:00
|
|
|
Path path = followLinksToStorePath(*i);
|
2005-02-14 17:35:10 +00:00
|
|
|
|
2006-02-08 13:21:16 +00:00
|
|
|
DrvInfo elem;
|
2006-09-04 21:06:23 +00:00
|
|
|
elem.attrs = boost::shared_ptr<ATermMap>(new ATermMap(0)); /* ugh... */
|
2007-11-29 16:18:24 +00:00
|
|
|
string name = baseNameOf(path);
|
2006-05-11 02:19:43 +00:00
|
|
|
string::size_type dash = name.find('-');
|
2005-02-14 17:35:10 +00:00
|
|
|
if (dash != string::npos)
|
|
|
|
name = string(name, dash + 1);
|
|
|
|
|
2007-11-29 16:18:24 +00:00
|
|
|
if (isDerivation(path)) {
|
|
|
|
elem.setDrvPath(path);
|
|
|
|
elem.setOutPath(findOutput(derivationFromPath(path), "out"));
|
2005-02-14 17:35:10 +00:00
|
|
|
if (name.size() >= drvExtension.size() &&
|
|
|
|
string(name, name.size() - drvExtension.size()) == drvExtension)
|
|
|
|
name = string(name, 0, name.size() - drvExtension.size());
|
|
|
|
}
|
2007-11-29 16:18:24 +00:00
|
|
|
else elem.setOutPath(path);
|
2005-02-14 17:35:10 +00:00
|
|
|
|
|
|
|
elem.name = name;
|
2006-02-08 14:32:33 +00:00
|
|
|
|
|
|
|
elems.push_back(elem);
|
2005-02-14 17:35:10 +00:00
|
|
|
}
|
|
|
|
|
2005-02-14 16:16:02 +00:00
|
|
|
break;
|
2005-02-15 12:05:47 +00: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 17:47:54 +00:00
|
|
|
elems = filterBySelector(state,
|
|
|
|
queryInstalled(state, instSource.profile),
|
2007-10-29 14:31:45 +00:00
|
|
|
args, newestOnly, instSource.prebuiltOnly);
|
2005-02-14 16:16:02 +00:00
|
|
|
break;
|
2005-02-15 12:05:47 +00:00
|
|
|
}
|
2006-07-25 11:53:22 +00:00
|
|
|
|
|
|
|
case srcAttrPath: {
|
|
|
|
for (Strings::const_iterator i = args.begin();
|
|
|
|
i != args.end(); ++i)
|
|
|
|
getDerivations(state,
|
2006-08-23 16:33:21 +00:00
|
|
|
findAlongAttrPath(state, *i, instSource.autoArgs,
|
2007-09-17 16:08:24 +00:00
|
|
|
loadSourceExpr(state, instSource.nixExprPath)),
|
2006-08-23 16:33:21 +00:00
|
|
|
"", instSource.autoArgs, elems);
|
2006-07-25 11:53:22 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-11-20 13:48:48 +00:00
|
|
|
}
|
2005-02-14 16:16:02 +00:00
|
|
|
}
|
2003-11-20 13:48:48 +00:00
|
|
|
|
2004-06-28 14:40:26 +00:00
|
|
|
|
2006-03-06 11:21:15 +00: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 11:56:49 +00: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 16:16:02 +00: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 13:21:16 +00:00
|
|
|
DrvInfos newElems;
|
2006-02-17 17:47:54 +00:00
|
|
|
queryInstSources(globals.state, globals.instSource, args, newElems, true);
|
2005-02-14 16:16:02 +00:00
|
|
|
|
|
|
|
StringSet newNames;
|
2006-09-25 14:00:59 +00: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 13:21:16 +00:00
|
|
|
newNames.insert(DrvName(i->name).name);
|
2006-09-25 14:00:59 +00:00
|
|
|
}
|
2005-02-14 16:16:02 +00:00
|
|
|
|
|
|
|
/* Add in the already installed derivations, unless they have the
|
|
|
|
same name as a to-be-installed element. */
|
2006-06-15 11:56:49 +00:00
|
|
|
PathLocks lock;
|
|
|
|
lockProfile(lock, profile);
|
2006-02-08 13:21:16 +00:00
|
|
|
DrvInfos installedElems = queryInstalled(globals.state, profile);
|
2005-02-14 16:16:02 +00:00
|
|
|
|
2006-02-17 16:26:28 +00:00
|
|
|
DrvInfos allElems(newElems);
|
2006-02-08 13:21:16 +00:00
|
|
|
for (DrvInfos::iterator i = installedElems.begin();
|
2005-02-14 16:16:02 +00:00
|
|
|
i != installedElems.end(); ++i)
|
2004-06-28 14:40:26 +00:00
|
|
|
{
|
2006-02-08 13:21:16 +00:00
|
|
|
DrvName drvName(i->name);
|
2007-04-27 23:48:14 +00:00
|
|
|
MetaInfo meta = i->queryMetaInfo(globals.state);
|
2005-02-14 13:07:09 +00:00
|
|
|
if (!globals.preserveInstalled &&
|
2007-04-27 23:48:14 +00:00
|
|
|
newNames.find(drvName.name) != newNames.end() &&
|
2007-04-30 18:41:27 +00:00
|
|
|
meta["keep"] != "true")
|
2004-06-28 14:40:26 +00:00
|
|
|
printMsg(lvlInfo,
|
2006-02-17 16:26:28 +00:00
|
|
|
format("replacing old `%1%'") % i->name);
|
2004-06-28 14:40:26 +00:00
|
|
|
else
|
2006-02-17 16:26:28 +00:00
|
|
|
allElems.push_back(*i);
|
2004-06-28 14:40:26 +00:00
|
|
|
}
|
2003-11-20 13:48:48 +00:00
|
|
|
|
2006-02-17 16:26:28 +00:00
|
|
|
for (DrvInfos::iterator i = newElems.begin(); i != newElems.end(); ++i)
|
|
|
|
printMsg(lvlInfo,
|
|
|
|
format("installing `%1%'") % i->name);
|
|
|
|
|
2006-03-06 11:21:15 +00:00
|
|
|
if (globals.dryRun) {
|
|
|
|
printMissing(globals.state, newElems);
|
|
|
|
return;
|
|
|
|
}
|
2004-02-09 11:59:39 +00:00
|
|
|
|
2006-02-17 16:26:28 +00:00
|
|
|
createUserEnv(globals.state, allElems,
|
2005-02-14 13:07:09 +00:00
|
|
|
profile, globals.keepDerivations);
|
2003-11-20 13:48:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-21 22:34:41 +00:00
|
|
|
static void opInstall(Globals & globals,
|
2007-09-17 19:24:07 +00:00
|
|
|
Strings args, Strings opFlags, Strings opArgs)
|
2003-11-19 17:27:16 +00:00
|
|
|
{
|
2007-09-17 19:24:07 +00:00
|
|
|
for (Strings::iterator i = opFlags.begin(); i != opFlags.end(); ) {
|
|
|
|
string arg = *i++;
|
|
|
|
if (parseInstallSourceOptions(globals, i, opFlags, arg)) ;
|
|
|
|
else if (arg == "--preserve-installed" || arg == "-P")
|
|
|
|
globals.preserveInstalled = true;
|
|
|
|
else throw UsageError(format("unknown flag `%1%'") % arg);
|
|
|
|
}
|
2003-11-19 17:27:16 +00:00
|
|
|
|
2005-02-14 16:16:02 +00:00
|
|
|
installDerivations(globals, opArgs, globals.profile);
|
2003-12-21 23:58:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-27 12:17:25 +00:00
|
|
|
typedef enum { utLt, utLeq, utEq, utAlways } UpgradeType;
|
2004-02-09 11:59:39 +00:00
|
|
|
|
|
|
|
|
2005-02-14 13:07:09 +00:00
|
|
|
static void upgradeDerivations(Globals & globals,
|
2007-02-02 01:52:42 +00:00
|
|
|
const Strings & args, 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 16:04:00 +00:00
|
|
|
{
|
2005-02-11 16:56:45 +00: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 16:04:00 +00: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 11:56:49 +00:00
|
|
|
PathLocks lock;
|
2007-02-02 01:52:42 +00:00
|
|
|
lockProfile(lock, globals.profile);
|
|
|
|
DrvInfos installedElems = queryInstalled(globals.state, globals.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 16:04:00 +00:00
|
|
|
|
|
|
|
/* Fetch all derivations from the input file. */
|
2006-02-08 13:21:16 +00:00
|
|
|
DrvInfos availElems;
|
2006-02-17 17:47:54 +00: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 16:04:00 +00:00
|
|
|
|
|
|
|
/* Go through all installed derivations. */
|
2006-02-08 13:21:16 +00:00
|
|
|
DrvInfos newElems;
|
|
|
|
for (DrvInfos::iterator i = installedElems.begin();
|
2005-02-14 16:16:02 +00: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 16:04:00 +00:00
|
|
|
{
|
2006-02-08 13:21:16 +00: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 16:04:00 +00:00
|
|
|
|
2007-04-27 23:48:14 +00:00
|
|
|
MetaInfo meta = i->queryMetaInfo(globals.state);
|
2007-07-05 20:33:04 +00:00
|
|
|
if (meta["keep"] == "true") {
|
|
|
|
newElems.push_back(*i);
|
|
|
|
continue;
|
|
|
|
}
|
2007-04-27 23:48:14 +00:00
|
|
|
|
2005-02-14 16:16:02 +00:00
|
|
|
/* Find the derivation in the input Nix expression with the
|
2007-05-01 20:33:18 +00:00
|
|
|
same name that satisfies the version constraints specified
|
2005-02-14 16:16:02 +00:00
|
|
|
by upgradeType. If there are multiple matches, take the
|
2007-05-01 20:33:18 +00:00
|
|
|
one with the highest priority. If there are still multiple
|
|
|
|
matches, take the one with the highest version. */
|
2006-02-08 13:21:16 +00:00
|
|
|
DrvInfos::iterator bestElem = availElems.end();
|
2004-02-09 11:59:39 +00:00
|
|
|
DrvName bestName;
|
2006-02-08 13:21:16 +00:00
|
|
|
for (DrvInfos::iterator j = availElems.begin();
|
2005-02-14 16:16:02 +00:00
|
|
|
j != availElems.end(); ++j)
|
2004-02-09 11:59:39 +00:00
|
|
|
{
|
2006-02-08 13:21:16 +00:00
|
|
|
DrvName newName(j->name);
|
2004-02-09 11:59:39 +00:00
|
|
|
if (newName.name == drvName.name) {
|
2007-05-01 20:33:18 +00:00
|
|
|
int d = comparePriorities(globals.state, *i, *j);
|
|
|
|
if (d == 0) d = compareVersions(drvName.version, newName.version);
|
2004-02-09 11:59:39 +00:00
|
|
|
if (upgradeType == utLt && d < 0 ||
|
|
|
|
upgradeType == utLeq && d <= 0 ||
|
2006-06-27 12:17:25 +00:00
|
|
|
upgradeType == utEq && d == 0 ||
|
2004-02-09 11:59:39 +00:00
|
|
|
upgradeType == utAlways)
|
|
|
|
{
|
2007-05-01 20:33:18 +00:00
|
|
|
int d2 = -1;
|
|
|
|
if (bestElem != availElems.end()) {
|
|
|
|
d2 = comparePriorities(globals.state, *bestElem, *j);
|
|
|
|
if (d2 == 0) d2 = compareVersions(bestName.version, newName.version);
|
|
|
|
}
|
|
|
|
if (d2 < 0) {
|
2005-02-14 16:16:02 +00:00
|
|
|
bestElem = j;
|
2004-02-09 11:59:39 +00:00
|
|
|
bestName = newName;
|
|
|
|
}
|
|
|
|
}
|
2003-12-23 22:13:36 +00: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 16:04:00 +00:00
|
|
|
}
|
|
|
|
|
2005-02-14 16:16:02 +00:00
|
|
|
if (bestElem != availElems.end() &&
|
2006-02-08 13:21:16 +00:00
|
|
|
i->queryOutPath(globals.state) !=
|
|
|
|
bestElem->queryOutPath(globals.state))
|
2004-02-09 11:59:39 +00: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 16:04:00 +00:00
|
|
|
printMsg(lvlInfo,
|
|
|
|
format("upgrading `%1%' to `%2%'")
|
2006-02-08 13:21:16 +00: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 16:04:00 +00:00
|
|
|
}
|
|
|
|
|
2006-03-06 11:21:15 +00:00
|
|
|
if (globals.dryRun) {
|
|
|
|
printMissing(globals.state, newElems);
|
|
|
|
return;
|
|
|
|
}
|
2004-02-09 11:59:39 +00:00
|
|
|
|
2005-02-14 16:16:02 +00:00
|
|
|
createUserEnv(globals.state, newElems,
|
2007-02-02 01:52:42 +00:00
|
|
|
globals.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 16:04:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-21 23:58:56 +00:00
|
|
|
static void opUpgrade(Globals & globals,
|
2007-09-17 19:24:07 +00:00
|
|
|
Strings args, Strings opFlags, Strings opArgs)
|
2003-12-21 23:58:56 +00:00
|
|
|
{
|
2004-02-09 11:59:39 +00:00
|
|
|
UpgradeType upgradeType = utLt;
|
2007-09-17 19:24:07 +00:00
|
|
|
for (Strings::iterator i = opFlags.begin(); i != opFlags.end(); ) {
|
|
|
|
string arg = *i++;
|
|
|
|
if (parseInstallSourceOptions(globals, i, opFlags, arg)) ;
|
|
|
|
else if (arg == "--lt") upgradeType = utLt;
|
|
|
|
else if (arg == "--leq") upgradeType = utLeq;
|
|
|
|
else if (arg == "--eq") upgradeType = utEq;
|
|
|
|
else if (arg == "--always") upgradeType = utAlways;
|
|
|
|
else throw UsageError(format("unknown flag `%1%'") % arg);
|
|
|
|
}
|
2003-12-21 23:58:56 +00:00
|
|
|
|
2007-02-02 01:52:42 +00:00
|
|
|
upgradeDerivations(globals, opArgs, upgradeType);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void setMetaFlag(EvalState & state, DrvInfo & drv,
|
|
|
|
const string & name, const string & value)
|
|
|
|
{
|
|
|
|
MetaInfo meta = drv.queryMetaInfo(state);
|
|
|
|
meta[name] = value;
|
|
|
|
drv.setMetaInfo(meta);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void opSetFlag(Globals & globals,
|
2007-09-17 19:24:07 +00:00
|
|
|
Strings args, Strings opFlags, Strings opArgs)
|
2007-02-02 01:52:42 +00:00
|
|
|
{
|
|
|
|
if (opFlags.size() > 0)
|
|
|
|
throw UsageError(format("unknown flag `%1%'") % opFlags.front());
|
|
|
|
if (opArgs.size() < 2)
|
|
|
|
throw UsageError("not enough arguments to `--set-flag'");
|
|
|
|
|
|
|
|
Strings::iterator arg = opArgs.begin();
|
|
|
|
string flagName = *arg++;
|
|
|
|
string flagValue = *arg++;
|
|
|
|
DrvNames selectors = drvNamesFromArgs(Strings(arg, opArgs.end()));
|
|
|
|
|
|
|
|
/* Load the currently installed derivations. */
|
|
|
|
PathLocks lock;
|
|
|
|
lockProfile(lock, globals.profile);
|
|
|
|
DrvInfos installedElems = queryInstalled(globals.state, globals.profile);
|
|
|
|
|
|
|
|
/* Update all matching derivations. */
|
|
|
|
for (DrvInfos::iterator i = installedElems.begin();
|
|
|
|
i != installedElems.end(); ++i)
|
|
|
|
{
|
|
|
|
DrvName drvName(i->name);
|
|
|
|
for (DrvNames::iterator j = selectors.begin();
|
|
|
|
j != selectors.end(); ++j)
|
|
|
|
if (j->matches(drvName)) {
|
|
|
|
printMsg(lvlInfo,
|
|
|
|
format("setting flag on `%1%'") % i->name);
|
|
|
|
setMetaFlag(globals.state, *i, flagName, flagValue);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write the new user environment. */
|
|
|
|
createUserEnv(globals.state, installedElems,
|
|
|
|
globals.profile, globals.keepDerivations);
|
2003-11-19 17:27:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-12 19:06:02 +00:00
|
|
|
static void opSet(Globals & globals,
|
2007-09-17 19:24:07 +00:00
|
|
|
Strings args, Strings opFlags, Strings opArgs)
|
2006-12-12 19:06:02 +00:00
|
|
|
{
|
2007-09-17 19:24:07 +00:00
|
|
|
for (Strings::iterator i = opFlags.begin(); i != opFlags.end(); ) {
|
|
|
|
string arg = *i++;
|
|
|
|
if (parseInstallSourceOptions(globals, i, opFlags, arg)) ;
|
|
|
|
else throw UsageError(format("unknown flag `%1%'") % arg);
|
|
|
|
}
|
2006-12-12 19:06:02 +00:00
|
|
|
|
|
|
|
DrvInfos elems;
|
|
|
|
queryInstSources(globals.state, globals.instSource, opArgs, elems, true);
|
|
|
|
|
|
|
|
if (elems.size() != 1)
|
|
|
|
throw Error("--set requires exactly one derivation");
|
|
|
|
|
|
|
|
DrvInfo & drv(elems.front());
|
|
|
|
|
|
|
|
if (drv.queryDrvPath(globals.state) != "")
|
|
|
|
store->buildDerivations(singleton<PathSet>(drv.queryDrvPath(globals.state)));
|
|
|
|
else
|
|
|
|
store->ensurePath(drv.queryOutPath(globals.state));
|
|
|
|
|
|
|
|
debug(format("switching to new user environment"));
|
|
|
|
Path generation = createGeneration(globals.profile, drv.queryOutPath(globals.state));
|
|
|
|
switchLink(globals.profile, generation);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-29 16:18:24 +00:00
|
|
|
static void uninstallDerivations(Globals & globals, Strings & selectors,
|
2005-02-14 13:07:09 +00:00
|
|
|
Path & profile)
|
2003-11-20 13:48:48 +00:00
|
|
|
{
|
2006-06-15 11:56:49 +00:00
|
|
|
PathLocks lock;
|
|
|
|
lockProfile(lock, profile);
|
2006-02-08 13:21:16 +00:00
|
|
|
DrvInfos installedElems = queryInstalled(globals.state, profile);
|
|
|
|
DrvInfos newElems;
|
2003-11-20 13:48:48 +00:00
|
|
|
|
2006-02-08 13:21:16 +00:00
|
|
|
for (DrvInfos::iterator i = installedElems.begin();
|
2005-02-14 16:16:02 +00:00
|
|
|
i != installedElems.end(); ++i)
|
2003-11-20 13:48:48 +00:00
|
|
|
{
|
2006-02-08 13:21:16 +00:00
|
|
|
DrvName drvName(i->name);
|
2005-09-01 18:14:04 +00:00
|
|
|
bool found = false;
|
2007-11-29 16:18:24 +00:00
|
|
|
for (Strings::iterator j = selectors.begin(); j != selectors.end(); ++j)
|
|
|
|
/* !!! the repeated calls to followLinksToStorePath() are
|
|
|
|
expensive, should pre-compute them. */
|
|
|
|
if ((isPath(*j) && i->queryOutPath(globals.state) == followLinksToStorePath(*j))
|
|
|
|
|| DrvName(*j).matches(drvName))
|
|
|
|
{
|
|
|
|
printMsg(lvlInfo, format("uninstalling `%1%'") % i->name);
|
2005-09-01 18:14:04 +00: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 16:04:00 +00:00
|
|
|
}
|
2006-02-08 13:21:16 +00:00
|
|
|
if (!found) newElems.push_back(*i);
|
2003-11-20 13:48:48 +00:00
|
|
|
}
|
|
|
|
|
2005-02-14 13:07:09 +00:00
|
|
|
if (globals.dryRun) return;
|
2004-02-09 11:59:39 +00:00
|
|
|
|
2005-09-01 18:14:04 +00:00
|
|
|
createUserEnv(globals.state, newElems,
|
2005-02-14 13:07:09 +00:00
|
|
|
profile, globals.keepDerivations);
|
2003-11-20 13:48:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-21 22:34:41 +00:00
|
|
|
static void opUninstall(Globals & globals,
|
2007-09-17 19:24:07 +00:00
|
|
|
Strings args, Strings opFlags, Strings opArgs)
|
2003-11-20 13:48:48 +00:00
|
|
|
{
|
2003-12-21 22:34:41 +00:00
|
|
|
if (opFlags.size() > 0)
|
2006-07-25 11:53:22 +00:00
|
|
|
throw UsageError(format("unknown flag `%1%'") % opFlags.front());
|
2007-11-29 16:18:24 +00:00
|
|
|
uninstallDerivations(globals, opArgs, globals.profile);
|
2003-11-20 13:48:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-14 15:09:55 +00:00
|
|
|
static bool cmpChars(char a, char b)
|
|
|
|
{
|
|
|
|
return toupper(a) < toupper(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-08 13:21:16 +00:00
|
|
|
static bool cmpElemByName(const DrvInfo & a, const DrvInfo & b)
|
2004-02-02 10:51:54 +00:00
|
|
|
{
|
2004-10-14 15:09:55 +00:00
|
|
|
return lexicographical_compare(
|
|
|
|
a.name.begin(), a.name.end(),
|
|
|
|
b.name.begin(), b.name.end(), cmpChars);
|
2004-02-02 10:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-01 13:35:10 +00:00
|
|
|
typedef list<Strings> Table;
|
|
|
|
|
|
|
|
|
|
|
|
void printTable(Table & table)
|
|
|
|
{
|
2004-10-29 11:22:49 +00:00
|
|
|
unsigned int nrColumns = table.size() > 0 ? table.front().size() : 0;
|
2004-07-01 13:35:10 +00:00
|
|
|
|
2004-10-29 11:22:49 +00:00
|
|
|
vector<unsigned int> widths;
|
2004-07-01 13:35:10 +00:00
|
|
|
widths.resize(nrColumns);
|
|
|
|
|
|
|
|
for (Table::iterator i = table.begin(); i != table.end(); ++i) {
|
|
|
|
assert(i->size() == nrColumns);
|
2004-10-29 11:22:49 +00:00
|
|
|
Strings::iterator j;
|
|
|
|
unsigned int column;
|
2004-07-01 13:35:10 +00: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 11:22:49 +00:00
|
|
|
Strings::iterator j;
|
|
|
|
unsigned int column;
|
2004-07-01 13:35:10 +00: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-04 21:06:23 +00:00
|
|
|
cout << std::endl;
|
2004-07-01 13:35:10 +00: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 14:44:54 +00: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 13:21:16 +00: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 14:44:54 +00:00
|
|
|
{
|
|
|
|
DrvName name(elem.name);
|
|
|
|
|
|
|
|
VersionDiff diff = cvUnavail;
|
|
|
|
version = "?";
|
|
|
|
|
2006-02-08 13:21:16 +00: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 14:44:54 +00: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 15:01:46 +00: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 14:44:54 +00:00
|
|
|
return "\e[1;31m" + s + "\e[0m";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-21 22:34:41 +00:00
|
|
|
static void opQuery(Globals & globals,
|
2007-09-17 19:24:07 +00:00
|
|
|
Strings args, Strings opFlags, Strings opArgs)
|
2003-11-19 17:27:16 +00:00
|
|
|
{
|
2006-08-03 15:52:09 +00:00
|
|
|
typedef vector< map<string, string> > ResultSet;
|
2007-09-17 19:24:07 +00:00
|
|
|
Strings remaining;
|
|
|
|
string attrPath;
|
2006-08-03 15:52:09 +00:00
|
|
|
|
2004-07-01 13:13:37 +00:00
|
|
|
bool printStatus = false;
|
|
|
|
bool printName = true;
|
2006-07-25 16:40:38 +00:00
|
|
|
bool printAttrPath = false;
|
2004-07-01 13:13:37 +00:00
|
|
|
bool printSystem = false;
|
|
|
|
bool printDrvPath = false;
|
2005-02-11 16:56:45 +00:00
|
|
|
bool printOutPath = false;
|
2006-03-10 16:20:42 +00:00
|
|
|
bool printDescription = false;
|
2007-05-01 11:30:52 +00:00
|
|
|
bool printMeta = false;
|
2007-04-26 14:20:31 +00:00
|
|
|
bool prebuiltOnly = 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 14:44:54 +00:00
|
|
|
bool compareVersions = false;
|
2006-08-03 15:52:09 +00:00
|
|
|
bool xmlOutput = false;
|
2004-07-01 13:13:37 +00:00
|
|
|
|
2003-11-19 17:27:16 +00:00
|
|
|
enum { sInstalled, sAvailable } source = sInstalled;
|
|
|
|
|
2004-10-27 10:24:44 +00:00
|
|
|
readOnlyMode = true; /* makes evaluation a bit faster */
|
|
|
|
|
2007-09-17 19:24:07 +00:00
|
|
|
for (Strings::iterator i = args.begin(); i != args.end(); ) {
|
|
|
|
string arg = *i++;
|
|
|
|
if (arg == "--status" || arg == "-s") printStatus = true;
|
|
|
|
else if (arg == "--no-name") printName = false;
|
|
|
|
else if (arg == "--system") printSystem = true;
|
|
|
|
else if (arg == "--description") printDescription = true;
|
|
|
|
else if (arg == "--compare-versions" || arg == "-c") compareVersions = true;
|
|
|
|
else if (arg == "--drv-path") printDrvPath = true;
|
|
|
|
else if (arg == "--out-path") printOutPath = true;
|
|
|
|
else if (arg == "--meta") printMeta = true;
|
|
|
|
else if (arg == "--installed") source = sInstalled;
|
|
|
|
else if (arg == "--available" || arg == "-a") source = sAvailable;
|
|
|
|
else if (arg == "--prebuilt-only" || arg == "-b") prebuiltOnly = true;
|
|
|
|
else if (arg == "--xml") xmlOutput = true;
|
|
|
|
else if (arg == "--attr-path" || arg == "-P") printAttrPath = true;
|
|
|
|
else if (arg == "--attr" || arg == "-A")
|
|
|
|
attrPath = needArg(i, args, arg);
|
|
|
|
else if (arg[0] == '-')
|
|
|
|
throw UsageError(format("unknown flag `%1%'") % arg);
|
|
|
|
else remaining.push_back(arg);
|
2006-03-10 10:24:46 +00:00
|
|
|
}
|
2003-11-19 17:27:16 +00:00
|
|
|
|
2007-09-17 19:24:07 +00:00
|
|
|
if (remaining.size() == 0)
|
|
|
|
printMsg(lvlInfo, "warning: you probably meant to specify the argument '*' to show all packages");
|
|
|
|
|
* 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 14:44:54 +00:00
|
|
|
|
|
|
|
/* Obtain derivation information from the specified source. */
|
2006-02-08 13:21:16 +00:00
|
|
|
DrvInfos availElems, installedElems;
|
2003-11-19 17:27:16 +00:00
|
|
|
|
2007-09-17 19:24:07 +00: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 14:44:54 +00:00
|
|
|
installedElems = queryInstalled(globals.state, globals.profile);
|
2003-11-19 17:27:16 +00:00
|
|
|
|
2007-09-17 19:24:07 +00:00
|
|
|
if (source == sAvailable || compareVersions)
|
* 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 14:44:54 +00:00
|
|
|
loadDerivations(globals.state, globals.instSource.nixExprPath,
|
2006-08-23 16:33:21 +00:00
|
|
|
globals.instSource.systemFilter, globals.instSource.autoArgs,
|
2007-09-17 19:24:07 +00:00
|
|
|
attrPath, availElems);
|
2003-11-19 17:27:16 +00:00
|
|
|
|
2006-03-10 10:24:46 +00:00
|
|
|
DrvInfos elems = filterBySelector(globals.state,
|
|
|
|
source == sInstalled ? installedElems : availElems,
|
2007-10-29 14:31:45 +00:00
|
|
|
remaining, false, prebuiltOnly);
|
2006-03-10 10:24:46 +00:00
|
|
|
|
2006-02-08 13:21:16 +00:00
|
|
|
DrvInfos & otherElems(source == sInstalled ? availElems : installedElems);
|
2004-02-02 10:51:54 +00: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 14:44:54 +00:00
|
|
|
|
2004-02-02 10:51:54 +00:00
|
|
|
/* Sort them by name. */
|
2006-02-08 13:21:16 +00:00
|
|
|
/* !!! */
|
|
|
|
vector<DrvInfo> elems2;
|
|
|
|
for (DrvInfos::iterator i = elems.begin(); i != elems.end(); ++i)
|
|
|
|
elems2.push_back(*i);
|
2005-02-14 16:16:02 +00:00
|
|
|
sort(elems2.begin(), elems2.end(), cmpElemByName);
|
2003-11-19 17:27:16 +00: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 14:44:54 +00:00
|
|
|
|
2004-07-01 13:13:37 +00:00
|
|
|
/* We only need to know the installed paths when we are querying
|
|
|
|
the status of the derivation. */
|
2005-05-08 10:32:09 +00:00
|
|
|
PathSet installed; /* installed paths */
|
2004-07-01 13:13:37 +00:00
|
|
|
|
2005-05-08 10:32:09 +00:00
|
|
|
if (printStatus) {
|
2006-02-08 13:21:16 +00:00
|
|
|
for (DrvInfos::iterator i = installedElems.begin();
|
2005-05-08 10:32:09 +00:00
|
|
|
i != installedElems.end(); ++i)
|
2006-02-08 13:21:16 +00:00
|
|
|
installed.insert(i->queryOutPath(globals.state));
|
2005-05-08 10:32:09 +00: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 14:44:54 +00:00
|
|
|
|
|
|
|
|
2006-08-03 15:52:09 +00:00
|
|
|
/* Print the desired columns, or XML output. */
|
2004-07-01 13:35:10 +00:00
|
|
|
Table table;
|
2006-09-04 21:06:23 +00:00
|
|
|
std::ostringstream dummy;
|
2006-08-16 10:32:30 +00:00
|
|
|
XMLWriter xml(true, *(xmlOutput ? &cout : &dummy));
|
2006-08-03 15:52:09 +00:00
|
|
|
XMLOpenElement xmlRoot(xml, "items");
|
2004-07-01 13:35:10 +00:00
|
|
|
|
2006-02-08 13:21:16 +00:00
|
|
|
for (vector<DrvInfo>::iterator i = elems2.begin();
|
2005-02-14 16:16:02 +00:00
|
|
|
i != elems2.end(); ++i)
|
|
|
|
{
|
2006-03-08 16:03:58 +00:00
|
|
|
try {
|
2006-08-03 15:52:09 +00:00
|
|
|
|
|
|
|
/* For table output. */
|
2006-03-08 16:03:58 +00:00
|
|
|
Strings columns;
|
2006-08-03 15:52:09 +00:00
|
|
|
|
|
|
|
/* For XML output. */
|
|
|
|
XMLAttrs attrs;
|
2007-04-26 14:20:31 +00:00
|
|
|
|
2006-03-08 16:03:58 +00:00
|
|
|
if (printStatus) {
|
2006-11-30 22:43:55 +00:00
|
|
|
bool hasSubs = store->hasSubstitutes(i->queryOutPath(globals.state));
|
2006-08-03 15:52:09 +00:00
|
|
|
bool isInstalled = installed.find(i->queryOutPath(globals.state)) != installed.end();
|
2006-11-30 17:43:04 +00:00
|
|
|
bool isValid = store->isValidPath(i->queryOutPath(globals.state));
|
2006-08-03 15:52:09 +00:00
|
|
|
if (xmlOutput) {
|
|
|
|
attrs["installed"] = isInstalled ? "1" : "0";
|
|
|
|
attrs["valid"] = isValid ? "1" : "0";
|
2006-11-30 22:43:55 +00:00
|
|
|
attrs["substitutable"] = hasSubs ? "1" : "0";
|
2006-08-03 15:52:09 +00:00
|
|
|
} else
|
|
|
|
columns.push_back(
|
|
|
|
(string) (isInstalled ? "I" : "-")
|
|
|
|
+ (isValid ? "P" : "-")
|
2006-11-30 22:43:55 +00:00
|
|
|
+ (hasSubs ? "S" : "-"));
|
2006-03-08 16:03:58 +00:00
|
|
|
}
|
2004-07-01 13:13:37 +00:00
|
|
|
|
2006-08-03 15:52:09 +00:00
|
|
|
if (xmlOutput)
|
|
|
|
attrs["attrPath"] = i->attrPath;
|
|
|
|
else if (printAttrPath)
|
|
|
|
columns.push_back(i->attrPath);
|
2006-07-25 16:40:38 +00:00
|
|
|
|
2006-08-03 15:52:09 +00:00
|
|
|
if (xmlOutput)
|
|
|
|
attrs["name"] = i->name;
|
|
|
|
else if (printName)
|
|
|
|
columns.push_back(i->name);
|
2006-03-08 16:03:58 +00: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 15:52:09 +00:00
|
|
|
|
2006-03-08 16:03:58 +00: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 15:52:09 +00: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 14:44:54 +00:00
|
|
|
}
|
|
|
|
|
2006-08-03 15:52:09 +00:00
|
|
|
if (xmlOutput) {
|
|
|
|
if (i->system != "") attrs["system"] = i->system;
|
|
|
|
}
|
|
|
|
else if (printSystem)
|
|
|
|
columns.push_back(i->system);
|
2005-10-06 15:51:59 +00:00
|
|
|
|
2006-08-03 15:52:09 +00: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 16:56:45 +00:00
|
|
|
|
2006-08-03 15:52:09 +00:00
|
|
|
if (printOutPath) {
|
|
|
|
string outPath = i->queryOutPath(globals.state);
|
|
|
|
if (xmlOutput) {
|
|
|
|
if (outPath != "") attrs["outPath"] = outPath;
|
|
|
|
} else
|
|
|
|
columns.push_back(outPath);
|
|
|
|
}
|
2006-03-10 16:20:42 +00:00
|
|
|
|
|
|
|
if (printDescription) {
|
|
|
|
MetaInfo meta = i->queryMetaInfo(globals.state);
|
2006-08-03 15:52:09 +00:00
|
|
|
string descr = meta["description"];
|
|
|
|
if (xmlOutput) {
|
|
|
|
if (descr != "") attrs["description"] = descr;
|
|
|
|
} else
|
|
|
|
columns.push_back(descr);
|
2006-03-10 16:20:42 +00:00
|
|
|
}
|
2006-08-03 15:52:09 +00:00
|
|
|
|
2006-08-16 10:32:30 +00:00
|
|
|
if (xmlOutput)
|
2007-05-01 11:30:52 +00:00
|
|
|
if (printMeta) {
|
|
|
|
XMLOpenElement item(xml, "item", attrs);
|
|
|
|
MetaInfo meta = i->queryMetaInfo(globals.state);
|
|
|
|
for (MetaInfo::iterator j = meta.begin(); j != meta.end(); ++j) {
|
|
|
|
XMLAttrs attrs2;
|
|
|
|
attrs2["name"] = j->first;
|
|
|
|
attrs2["value"] = j->second;
|
|
|
|
xml.writeEmptyElement("meta", attrs2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
xml.writeEmptyElement("item", attrs);
|
2006-08-16 10:32:30 +00:00
|
|
|
else
|
2006-08-03 15:52:09 +00:00
|
|
|
table.push_back(columns);
|
|
|
|
|
2006-10-17 14:01:45 +00:00
|
|
|
cout.flush();
|
|
|
|
|
2006-08-03 15:52:09 +00:00
|
|
|
} catch (AssertionError & e) {
|
2007-08-06 16:08:09 +00:00
|
|
|
printMsg(lvlTalkative, format("skipping derivation named `%1%' which gives an assertion failure") % i->name);
|
2006-03-08 16:03:58 +00:00
|
|
|
}
|
2003-11-19 17:27:16 +00:00
|
|
|
}
|
2004-07-01 13:35:10 +00:00
|
|
|
|
2006-08-03 15:52:09 +00:00
|
|
|
if (!xmlOutput) printTable(table);
|
2003-11-19 17:27:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-01-05 11:18:59 +00:00
|
|
|
static void opSwitchProfile(Globals & globals,
|
2007-09-17 19:24:07 +00:00
|
|
|
Strings args, Strings opFlags, Strings opArgs)
|
2004-01-05 11:18:59 +00:00
|
|
|
{
|
|
|
|
if (opFlags.size() > 0)
|
2004-02-06 16:03:27 +00:00
|
|
|
throw UsageError(format("unknown flag `%1%'") % opFlags.front());
|
2004-02-06 10:59:06 +00:00
|
|
|
if (opArgs.size() != 1)
|
2004-02-06 16:03:27 +00:00
|
|
|
throw UsageError(format("exactly one argument expected"));
|
2004-01-05 11:18:59 +00:00
|
|
|
|
2006-12-02 16:41:36 +00:00
|
|
|
Path profile = absPath(opArgs.front());
|
2004-02-06 10:59:06 +00:00
|
|
|
Path profileLink = getHomeDir() + "/.nix-profile";
|
2004-01-05 11:18:59 +00:00
|
|
|
|
2004-02-06 10:30:20 +00:00
|
|
|
switchLink(profileLink, profile);
|
2004-01-05 16:26:43 +00:00
|
|
|
}
|
2004-01-05 11:18:59 +00:00
|
|
|
|
2004-01-05 16:26:43 +00:00
|
|
|
|
2004-02-08 14:07:43 +00:00
|
|
|
static const int prevGen = -2;
|
|
|
|
|
|
|
|
|
|
|
|
static void switchGeneration(Globals & globals, int dstGen)
|
|
|
|
{
|
2006-09-14 22:33:53 +00:00
|
|
|
PathLocks lock;
|
|
|
|
lockProfile(lock, globals.profile);
|
|
|
|
|
2004-02-08 14:07:43 +00: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 13:42:58 +00:00
|
|
|
printMsg(lvlInfo, format("switching from generation %1% to %2%")
|
|
|
|
% curGen % dst.number);
|
|
|
|
|
|
|
|
if (globals.dryRun) return;
|
|
|
|
|
2004-02-08 14:07:43 +00:00
|
|
|
switchLink(globals.profile, dst.path);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void opSwitchGeneration(Globals & globals,
|
2007-09-17 19:24:07 +00:00
|
|
|
Strings args, Strings opFlags, Strings opArgs)
|
2004-02-08 14:07:43 +00:00
|
|
|
{
|
|
|
|
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 13:32:08 +00:00
|
|
|
if (!string2Int(opArgs.front(), dstGen))
|
2004-02-08 14:07:43 +00:00
|
|
|
throw UsageError(format("expected a generation number"));
|
|
|
|
|
|
|
|
switchGeneration(globals, dstGen);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void opRollback(Globals & globals,
|
2007-09-17 19:24:07 +00:00
|
|
|
Strings args, Strings opFlags, Strings opArgs)
|
2004-02-08 14:07:43 +00:00
|
|
|
{
|
|
|
|
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 16:03:27 +00:00
|
|
|
static void opListGenerations(Globals & globals,
|
2007-09-17 19:24:07 +00:00
|
|
|
Strings args, Strings opFlags, Strings opArgs)
|
2004-02-06 16:03:27 +00:00
|
|
|
{
|
|
|
|
if (opFlags.size() > 0)
|
|
|
|
throw UsageError(format("unknown flag `%1%'") % opFlags.front());
|
|
|
|
if (opArgs.size() != 0)
|
|
|
|
throw UsageError(format("no arguments expected"));
|
|
|
|
|
2006-09-14 22:33:53 +00:00
|
|
|
PathLocks lock;
|
|
|
|
lockProfile(lock, globals.profile);
|
|
|
|
|
2004-02-06 16:16:55 +00:00
|
|
|
int curGen;
|
|
|
|
Generations gens = findGenerations(globals.profile, curGen);
|
2004-02-06 16:03:27 +00: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 16:16:55 +00:00
|
|
|
cout << format("%|4| %|4|-%|02|-%|02| %|02|:%|02|:%|02| %||\n")
|
2004-02-06 16:03:27 +00:00
|
|
|
% i->number
|
|
|
|
% (t.tm_year + 1900) % (t.tm_mon + 1) % t.tm_mday
|
2004-02-06 16:16:55 +00:00
|
|
|
% t.tm_hour % t.tm_min % t.tm_sec
|
|
|
|
% (i->number == curGen ? "(current)" : "");
|
2004-02-06 16:03:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-09-10 13:32:08 +00: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,
|
2007-09-17 19:24:07 +00:00
|
|
|
Strings args, Strings opFlags, Strings opArgs)
|
2004-09-10 13:32:08 +00:00
|
|
|
{
|
|
|
|
if (opFlags.size() > 0)
|
|
|
|
throw UsageError(format("unknown flag `%1%'") % opFlags.front());
|
|
|
|
|
2006-09-14 22:33:53 +00:00
|
|
|
PathLocks lock;
|
|
|
|
lockProfile(lock, globals.profile);
|
|
|
|
|
2004-09-10 13:32:08 +00: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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-19 17:27:16 +00:00
|
|
|
void run(Strings args)
|
|
|
|
{
|
2007-09-17 19:24:07 +00:00
|
|
|
Strings opFlags, opArgs, remaining;
|
2003-11-19 17:27:16 +00:00
|
|
|
Operation op = 0;
|
2003-12-21 22:34:41 +00:00
|
|
|
|
|
|
|
Globals globals;
|
2005-02-14 13:07:09 +00:00
|
|
|
|
2005-02-11 16:56:45 +00:00
|
|
|
globals.instSource.type = srcUnknown;
|
|
|
|
globals.instSource.nixExprPath = getDefNixExprPath();
|
|
|
|
globals.instSource.systemFilter = thisSystem;
|
|
|
|
|
2004-02-09 11:59:39 +00:00
|
|
|
globals.dryRun = false;
|
2004-06-28 14:40:26 +00:00
|
|
|
globals.preserveInstalled = false;
|
2003-11-19 17:27:16 +00:00
|
|
|
|
2005-02-14 13:07:09 +00:00
|
|
|
globals.keepDerivations =
|
|
|
|
queryBoolSetting("env-keep-derivations", false);
|
|
|
|
|
2007-01-14 12:32:44 +00:00
|
|
|
for (Strings::iterator i = args.begin(); i != args.end(); ) {
|
|
|
|
string arg = *i++;
|
2003-11-19 17:27:16 +00:00
|
|
|
|
|
|
|
Operation oldOp = op;
|
|
|
|
|
|
|
|
if (arg == "--install" || arg == "-i")
|
|
|
|
op = opInstall;
|
2007-01-14 12:32:44 +00:00
|
|
|
else if (parseOptionArg(arg, i, args.end(),
|
|
|
|
globals.state, globals.instSource.autoArgs))
|
|
|
|
;
|
2006-09-25 14:00:59 +00:00
|
|
|
else if (arg == "--force-name") // undocumented flag for nix-install-package
|
|
|
|
globals.forceName = needArg(i, args, arg);
|
2003-12-21 22:34:41 +00:00
|
|
|
else if (arg == "--uninstall" || arg == "-e")
|
2003-11-20 13:48:48 +00:00
|
|
|
op = opUninstall;
|
2003-12-21 23:58:56 +00:00
|
|
|
else if (arg == "--upgrade" || arg == "-u")
|
|
|
|
op = opUpgrade;
|
2007-02-02 01:52:42 +00:00
|
|
|
else if (arg == "--set-flag")
|
|
|
|
op = opSetFlag;
|
2006-12-12 19:06:02 +00:00
|
|
|
else if (arg == "--set")
|
|
|
|
op = opSet;
|
2003-11-20 13:48:48 +00:00
|
|
|
else if (arg == "--query" || arg == "-q")
|
2003-11-19 17:27:16 +00:00
|
|
|
op = opQuery;
|
2007-02-02 01:52:42 +00:00
|
|
|
else if (arg == "--profile" || arg == "-p")
|
2005-02-14 16:16:02 +00:00
|
|
|
globals.profile = absPath(needArg(i, args, arg));
|
2007-02-02 01:52:42 +00:00
|
|
|
else if (arg == "--file" || arg == "-f")
|
2005-02-14 16:16:02 +00:00
|
|
|
globals.instSource.nixExprPath = absPath(needArg(i, args, arg));
|
2004-02-06 10:30:20 +00:00
|
|
|
else if (arg == "--switch-profile" || arg == "-S")
|
2004-01-05 11:18:59 +00:00
|
|
|
op = opSwitchProfile;
|
2004-02-08 14:07:43 +00:00
|
|
|
else if (arg == "--switch-generation" || arg == "-G")
|
|
|
|
op = opSwitchGeneration;
|
|
|
|
else if (arg == "--rollback")
|
|
|
|
op = opRollback;
|
2004-02-06 16:03:27 +00:00
|
|
|
else if (arg == "--list-generations")
|
|
|
|
op = opListGenerations;
|
2004-09-10 13:32:08 +00:00
|
|
|
else if (arg == "--delete-generations")
|
|
|
|
op = opDeleteGenerations;
|
2004-02-09 11:59:39 +00:00
|
|
|
else if (arg == "--dry-run") {
|
|
|
|
printMsg(lvlInfo, "(dry run; not doing anything)");
|
|
|
|
globals.dryRun = true;
|
|
|
|
}
|
2007-02-02 01:52:42 +00:00
|
|
|
else if (arg == "--system-filter")
|
2005-02-14 16:16:02 +00:00
|
|
|
globals.instSource.systemFilter = needArg(i, args, arg);
|
2007-09-17 19:24:07 +00:00
|
|
|
else {
|
|
|
|
remaining.push_back(arg);
|
|
|
|
if (arg[0] == '-')
|
|
|
|
opFlags.push_back(arg);
|
|
|
|
else
|
|
|
|
opArgs.push_back(arg);
|
|
|
|
}
|
2003-11-19 17:27:16 +00:00
|
|
|
|
|
|
|
if (oldOp && oldOp != op)
|
|
|
|
throw UsageError("only one operation may be specified");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!op) throw UsageError("no operation specified");
|
|
|
|
|
2004-02-06 10:59:06 +00:00
|
|
|
if (globals.profile == "") {
|
|
|
|
Path profileLink = getHomeDir() + "/.nix-profile";
|
|
|
|
globals.profile = pathExists(profileLink)
|
|
|
|
? absPath(readLink(profileLink), dirOf(profileLink))
|
|
|
|
: canonPath(nixStateDir + "/profiles/default");
|
|
|
|
}
|
|
|
|
|
2006-11-30 17:43:04 +00:00
|
|
|
store = openStore();
|
2003-11-19 17:27:16 +00:00
|
|
|
|
2007-09-17 19:24:07 +00:00
|
|
|
op(globals, remaining, opFlags, opArgs);
|
2003-11-19 17:27:16 +00:00
|
|
|
|
2003-12-21 22:34:41 +00:00
|
|
|
printEvalStats(globals.state);
|
2003-11-19 17:27:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string programId = "nix-env";
|