2003-11-19 17:27:16 +00:00
|
|
|
#include "globals.hh"
|
|
|
|
#include "normalise.hh"
|
|
|
|
#include "shared.hh"
|
|
|
|
#include "parser.hh"
|
|
|
|
#include "eval.hh"
|
2003-12-01 15:55:05 +00:00
|
|
|
#include "help.txt.hh"
|
2003-11-19 17:27:16 +00:00
|
|
|
|
|
|
|
|
2003-12-21 22:34:41 +00:00
|
|
|
struct Globals
|
|
|
|
{
|
|
|
|
Path linkPath;
|
|
|
|
EvalState state;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
typedef void (* Operation) (Globals & globals,
|
2003-11-19 17:27:16 +00:00
|
|
|
Strings opFlags, Strings opArgs);
|
|
|
|
|
|
|
|
|
|
|
|
struct DrvInfo
|
|
|
|
{
|
|
|
|
string name;
|
|
|
|
Path drvPath;
|
|
|
|
Path outPath;
|
2003-11-21 14:23:18 +00:00
|
|
|
Hash drvHash;
|
2003-11-19 17:27:16 +00:00
|
|
|
};
|
|
|
|
|
2003-11-19 21:32:03 +00:00
|
|
|
typedef map<Path, DrvInfo> DrvInfos;
|
2003-11-19 17:27:16 +00:00
|
|
|
|
|
|
|
|
2003-12-01 15:55:05 +00:00
|
|
|
void printHelp()
|
|
|
|
{
|
|
|
|
cout << string((char *) helpText, sizeof helpText);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-19 17:27:16 +00:00
|
|
|
bool parseDerivation(EvalState & state, Expr e, DrvInfo & drv)
|
|
|
|
{
|
|
|
|
ATMatcher m;
|
|
|
|
|
|
|
|
e = evalExpr(state, e);
|
|
|
|
if (!(atMatch(m, e) >> "Attrs")) return false;
|
|
|
|
Expr a = queryAttr(e, "type");
|
|
|
|
if (!a || evalString(state, a) != "derivation") return false;
|
|
|
|
|
|
|
|
a = queryAttr(e, "name");
|
|
|
|
if (!a) throw badTerm("derivation name missing", e);
|
|
|
|
drv.name = evalString(state, a);
|
|
|
|
|
|
|
|
a = queryAttr(e, "drvPath");
|
|
|
|
if (!a) throw badTerm("derivation path missing", e);
|
|
|
|
drv.drvPath = evalPath(state, a);
|
|
|
|
|
2003-11-21 14:23:18 +00:00
|
|
|
a = queryAttr(e, "drvHash");
|
|
|
|
if (!a) throw badTerm("derivation hash missing", e);
|
|
|
|
drv.drvHash = parseHash(evalString(state, a));
|
|
|
|
|
2003-11-19 17:27:16 +00:00
|
|
|
a = queryAttr(e, "outPath");
|
|
|
|
if (!a) throw badTerm("output path missing", e);
|
|
|
|
drv.outPath = evalPath(state, a);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool parseDerivations(EvalState & state, Expr e, DrvInfos & drvs)
|
|
|
|
{
|
2003-11-19 21:32:03 +00:00
|
|
|
ATMatcher m;
|
|
|
|
ATermList es;
|
2003-11-24 11:01:19 +00:00
|
|
|
DrvInfo drv;
|
2003-11-19 21:32:03 +00:00
|
|
|
|
2003-11-19 17:27:16 +00:00
|
|
|
e = evalExpr(state, e);
|
2003-11-24 11:01:19 +00:00
|
|
|
|
|
|
|
if (parseDerivation(state, e, drv))
|
|
|
|
drvs[drv.drvPath] = drv;
|
|
|
|
|
|
|
|
else if (atMatch(m, e) >> "Attrs") {
|
2003-11-19 21:32:03 +00:00
|
|
|
ATermMap drvMap;
|
|
|
|
queryAllAttrs(e, drvMap);
|
|
|
|
for (ATermIterator i(drvMap.keys()); i; ++i) {
|
|
|
|
debug(format("evaluating attribute `%1%'") % *i);
|
|
|
|
if (parseDerivation(state, drvMap.get(*i), drv))
|
|
|
|
drvs[drv.drvPath] = drv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (atMatch(m, e) >> "List" >> es) {
|
|
|
|
for (ATermIterator i(es); i; ++i) {
|
2003-11-20 13:48:48 +00:00
|
|
|
debug(format("evaluating list element"));
|
2003-11-19 21:32:03 +00:00
|
|
|
if (parseDerivation(state, *i, drv))
|
|
|
|
drvs[drv.drvPath] = drv;
|
|
|
|
}
|
2003-11-19 17:27:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void loadDerivations(EvalState & state, Path nePath, DrvInfos & drvs)
|
|
|
|
{
|
|
|
|
Expr e = parseExprFromFile(absPath(nePath));
|
|
|
|
if (!parseDerivations(state, e, drvs))
|
|
|
|
throw badTerm("expected set of derivations", e);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Path getLinksDir()
|
|
|
|
{
|
|
|
|
return canonPath(nixStateDir + "/links");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-21 22:34:41 +00:00
|
|
|
void queryInstalled(EvalState & state, DrvInfos & drvs,
|
|
|
|
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
|
|
|
|
|
|
|
if (!pathExists(path)) return; /* not an error, assume nothing installed */
|
|
|
|
|
|
|
|
Expr e = ATreadFromNamedFile(path.c_str());
|
|
|
|
if (!e) throw Error(format("cannot read Nix expression from `%1%'") % path);
|
|
|
|
|
|
|
|
if (!parseDerivations(state, e, drvs))
|
|
|
|
throw badTerm(format("expected set of derivations in `%1%'") % path, e);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-21 22:34:41 +00:00
|
|
|
Path createGeneration(Path outPath, Path drvPath)
|
2003-11-19 17:27:16 +00:00
|
|
|
{
|
|
|
|
Path linksDir = getLinksDir();
|
|
|
|
|
|
|
|
unsigned int num = 0;
|
|
|
|
|
|
|
|
Strings names = readDirectory(linksDir);
|
|
|
|
for (Strings::iterator i = names.begin(); i != names.end(); ++i) {
|
|
|
|
istringstream s(*i);
|
|
|
|
unsigned int n;
|
2003-11-19 21:32:03 +00:00
|
|
|
if (s >> n && s.eof() && n >= num) num = n + 1;
|
2003-11-19 17:27:16 +00:00
|
|
|
}
|
|
|
|
|
2003-12-21 22:34:41 +00:00
|
|
|
Path generation;
|
2003-11-19 17:27:16 +00:00
|
|
|
|
2003-11-19 21:32:03 +00:00
|
|
|
while (1) {
|
2003-12-21 22:34:41 +00:00
|
|
|
generation = (format("%1%/%2%") % linksDir % num).str();
|
|
|
|
if (symlink(outPath.c_str(), generation.c_str()) == 0) break;
|
2003-11-19 21:32:03 +00:00
|
|
|
if (errno != EEXIST)
|
2003-12-21 22:34:41 +00:00
|
|
|
throw SysError(format("creating symlink `%1%'") % generation);
|
2003-11-19 21:32:03 +00:00
|
|
|
/* Somebody beat us to it, retry with a higher number. */
|
|
|
|
num++;
|
|
|
|
}
|
2003-11-19 17:27:16 +00:00
|
|
|
|
2003-12-21 22:34:41 +00:00
|
|
|
writeStringToFile(generation + "-src.id", drvPath);
|
2003-11-22 15:58:34 +00:00
|
|
|
|
2003-12-21 22:34:41 +00:00
|
|
|
return generation;
|
2003-11-19 17:27:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-19 21:32:03 +00:00
|
|
|
void switchLink(Path link, Path target)
|
|
|
|
{
|
|
|
|
Path tmp = canonPath(dirOf(link) + "/.new_" + baseNameOf(link));
|
|
|
|
if (symlink(target.c_str(), tmp.c_str()) != 0)
|
|
|
|
throw SysError(format("creating symlink `%1%'") % tmp);
|
|
|
|
/* The rename() system call is supposed to be essentially atomic
|
|
|
|
on Unix. That is, if we have links `current -> X' and
|
|
|
|
`new_current -> Y', and we rename new_current to current, a
|
|
|
|
process accessing current will see X or Y, but never a
|
|
|
|
file-not-found or other error condition. This is sufficient to
|
|
|
|
atomically switch user environments. */
|
|
|
|
if (rename(tmp.c_str(), link.c_str()) != 0)
|
|
|
|
throw SysError(format("renaming `%1%' to `%2%'") % tmp % link);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-21 22:34:41 +00:00
|
|
|
void createUserEnv(EvalState & state, const DrvInfos & drvs,
|
|
|
|
const Path & linkPath)
|
2003-11-19 17:27:16 +00:00
|
|
|
{
|
|
|
|
/* Get the environment builder expression. */
|
2003-11-22 21:12:36 +00:00
|
|
|
Expr envBuilder = parseExprFromFile(nixDataDir + "/nix/corepkgs/buildenv"); /* !!! */
|
2003-11-19 17:27:16 +00:00
|
|
|
|
|
|
|
/* Construct the whole top level derivation. */
|
|
|
|
ATermList inputs = ATempty;
|
2003-11-20 13:48:48 +00:00
|
|
|
for (DrvInfos::const_iterator i = drvs.begin();
|
|
|
|
i != drvs.end(); ++i)
|
2003-11-19 17:27:16 +00:00
|
|
|
{
|
|
|
|
ATerm t = ATmake(
|
|
|
|
"Attrs(["
|
|
|
|
"Bind(\"type\", Str(\"derivation\")), "
|
|
|
|
"Bind(\"name\", Str(<str>)), "
|
|
|
|
"Bind(\"drvPath\", Path(<str>)), "
|
2003-11-21 14:23:18 +00:00
|
|
|
"Bind(\"drvHash\", Str(<str>)), "
|
2003-11-19 17:27:16 +00:00
|
|
|
"Bind(\"outPath\", Path(<str>))"
|
|
|
|
"])",
|
|
|
|
i->second.name.c_str(),
|
|
|
|
i->second.drvPath.c_str(),
|
2003-11-21 14:23:18 +00:00
|
|
|
((string) i->second.drvHash).c_str(),
|
2003-11-19 17:27:16 +00:00
|
|
|
i->second.outPath.c_str());
|
|
|
|
inputs = ATinsert(inputs, t);
|
|
|
|
}
|
|
|
|
|
|
|
|
ATerm inputs2 = ATmake("List(<term>)", ATreverse(inputs));
|
|
|
|
|
|
|
|
/* Also write a copy of the list of inputs to the store; we need
|
|
|
|
it for future modifications of the environment. */
|
|
|
|
Path inputsFile = writeTerm(inputs2, "-env-inputs");
|
|
|
|
|
|
|
|
Expr topLevel = ATmake(
|
|
|
|
"Call(<term>, Attrs(["
|
|
|
|
"Bind(\"system\", Str(<str>)), "
|
|
|
|
"Bind(\"derivations\", <term>), " // !!! redundant
|
|
|
|
"Bind(\"manifest\", Path(<str>))"
|
|
|
|
"]))",
|
|
|
|
envBuilder, thisSystem.c_str(), inputs2, inputsFile.c_str());
|
|
|
|
|
|
|
|
/* Instantiate it. */
|
|
|
|
debug(format("evaluating builder expression `%1%'") % topLevel);
|
|
|
|
DrvInfo topLevelDrv;
|
|
|
|
if (!parseDerivation(state, topLevel, topLevelDrv))
|
|
|
|
abort();
|
|
|
|
|
|
|
|
/* Realise the resulting store expression. */
|
|
|
|
debug(format("realising user environment"));
|
|
|
|
Path nfPath = normaliseStoreExpr(topLevelDrv.drvPath);
|
|
|
|
realiseClosure(nfPath);
|
|
|
|
|
|
|
|
/* Switch the current user environment to the output path. */
|
|
|
|
debug(format("switching to new user environment"));
|
2003-12-21 22:34:41 +00:00
|
|
|
Path generation = createGeneration(
|
|
|
|
topLevelDrv.outPath, topLevelDrv.drvPath);
|
|
|
|
switchLink(linkPath, generation);
|
2003-11-19 17:27:16 +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
|
|
|
struct DrvName
|
2003-12-21 23:58:56 +00:00
|
|
|
{
|
|
|
|
string fullName;
|
|
|
|
string name;
|
|
|
|
string version;
|
|
|
|
unsigned int hits;
|
|
|
|
|
|
|
|
/* Parse a derivation name. The `name' part of a derivation name
|
|
|
|
is everything up to but not including the first dash *not*
|
|
|
|
followed by a letter. The `version' part is the rest
|
|
|
|
(excluding the separating dash). E.g., `apache-httpd-2.0.48'
|
|
|
|
is parsed to (`apache-httpd', '2.0.48'). */
|
|
|
|
DrvName(const string & s) : hits(0)
|
|
|
|
{
|
|
|
|
name = fullName = s;
|
|
|
|
for (unsigned int i = 0; i < s.size(); ++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
|
|
|
/* !!! isalpha/isdigit are affected by the locale. */
|
2003-12-21 23:58:56 +00:00
|
|
|
if (s[i] == '-' && i + 1 < s.size() && !isalpha(s[i + 1])) {
|
|
|
|
name = string(s, 0, i);
|
|
|
|
version = string(s, i + 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool matches(DrvName & n)
|
|
|
|
{
|
|
|
|
if (name != "*" && name != n.name) return false;
|
|
|
|
if (version != "" && version != n.version) return false;
|
|
|
|
return true;
|
|
|
|
}
|
* 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
|
|
|
|
|
|
|
|
* 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
|
|
|
string nextComponent(string::const_iterator & p,
|
|
|
|
const string::const_iterator end)
|
|
|
|
{
|
|
|
|
/* Skip any dots and dashes (component separators). */
|
|
|
|
while (p != end && (*p == '.' || *p == '-')) ++p;
|
|
|
|
|
|
|
|
if (p == end) return "";
|
|
|
|
|
|
|
|
/* If the first character is a digit, consume the longest sequence
|
|
|
|
of digits. Otherwise, consume the longest sequence of
|
|
|
|
non-digit, non-separator characters. */
|
|
|
|
string s;
|
|
|
|
if (isdigit(*p))
|
|
|
|
while (p != end && isdigit(*p)) s += *p++;
|
|
|
|
else
|
|
|
|
while (p != end && (!isdigit(*p) && *p != '.' && *p != '-'))
|
|
|
|
s += *p++;
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
2003-12-21 23:58:56 +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
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
bool parseInt(const string & s, int & n)
|
|
|
|
{
|
|
|
|
istringstream st(s);
|
|
|
|
st >> n;
|
|
|
|
return !st.fail();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool componentsLT(const string & c1, const string & c2)
|
|
|
|
{
|
|
|
|
int n1, n2;
|
|
|
|
bool c1Num = parseInt(c1, n1), c2Num = parseInt(c2, n2);
|
|
|
|
|
|
|
|
if (c1Num && c2Num) return n1 < n2;
|
|
|
|
else if (c1 == "" && c2Num) return true;
|
|
|
|
else if (c1 == "pre" && c2 != "pre") return true;
|
|
|
|
else if (c2 == "pre") return false;
|
|
|
|
/* Assume that `2.3a' < `2.3.1'. */
|
|
|
|
else if (c2Num) return true;
|
|
|
|
else if (c1Num) return false;
|
|
|
|
else return c1 < c2;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int compareVersions(const string & v1, const string & v2)
|
|
|
|
{
|
|
|
|
string::const_iterator p1 = v1.begin();
|
|
|
|
string::const_iterator p2 = v2.begin();
|
|
|
|
|
|
|
|
while (p1 != v1.end() || p2 != v2.end()) {
|
|
|
|
string c1 = nextComponent(p1, v1.end());
|
|
|
|
string c2 = nextComponent(p2, v2.end());
|
|
|
|
if (componentsLT(c1, c2)) return -1;
|
|
|
|
else if (componentsLT(c2, c1)) return 1;
|
2003-12-21 23:58:56 +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
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void testCompareVersions()
|
|
|
|
{
|
|
|
|
#define TEST(v1, v2, n) assert( \
|
|
|
|
compareVersions(v1, v2) == n && compareVersions(v2, v1) == -n)
|
|
|
|
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);
|
|
|
|
}
|
2003-11-20 13:48:48 +00:00
|
|
|
|
|
|
|
|
2003-12-21 23:58:56 +00:00
|
|
|
typedef list<DrvName> DrvNames;
|
|
|
|
|
|
|
|
|
|
|
|
static DrvNames drvNamesFromArgs(const Strings & opArgs)
|
2003-11-20 13:48:48 +00:00
|
|
|
{
|
2003-12-21 23:58:56 +00:00
|
|
|
DrvNames result;
|
|
|
|
for (Strings::const_iterator i = opArgs.begin();
|
|
|
|
i != opArgs.end(); ++i)
|
|
|
|
result.push_back(DrvName(*i));
|
|
|
|
return result;
|
2003-11-20 13:48:48 +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
|
|
|
static void installDerivations(EvalState & state,
|
2003-12-21 23:58:56 +00:00
|
|
|
Path nePath, DrvNames & selectors, const Path & linkPath)
|
2003-11-20 13:48:48 +00:00
|
|
|
{
|
|
|
|
debug(format("installing derivations from `%1%'") % nePath);
|
|
|
|
|
|
|
|
/* Fetch all derivations from the input file. */
|
|
|
|
DrvInfos availDrvs;
|
|
|
|
loadDerivations(state, nePath, availDrvs);
|
|
|
|
|
|
|
|
/* Filter out the ones we're not interested in. */
|
|
|
|
DrvInfos selectedDrvs;
|
2003-12-21 23:58:56 +00:00
|
|
|
for (DrvInfos::iterator i = availDrvs.begin();
|
|
|
|
i != availDrvs.end(); ++i)
|
|
|
|
{
|
|
|
|
DrvName drvName(i->second.name);
|
|
|
|
for (DrvNames::iterator j = selectors.begin();
|
|
|
|
j != selectors.end(); ++j)
|
2003-11-24 11:01:19 +00:00
|
|
|
{
|
2003-12-21 23:58:56 +00:00
|
|
|
if (j->matches(drvName)) {
|
* 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("installing `%1%'") % i->second.name);
|
|
|
|
j->hits++;
|
2003-12-21 23:58:56 +00:00
|
|
|
selectedDrvs.insert(*i);
|
|
|
|
}
|
2003-11-24 11:01:19 +00:00
|
|
|
}
|
2003-11-20 13:48:48 +00:00
|
|
|
}
|
|
|
|
|
2003-12-21 23:58:56 +00:00
|
|
|
/* Check that all selectors have been used. */
|
|
|
|
for (DrvNames::iterator i = selectors.begin();
|
|
|
|
i != selectors.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
|
|
|
if (i->hits == 0)
|
2003-12-21 23:58:56 +00:00
|
|
|
throw Error(format("selector `%1%' matches no 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
|
|
|
% i->fullName);
|
2003-12-21 23:58:56 +00:00
|
|
|
|
2003-11-20 13:48:48 +00:00
|
|
|
/* Add in the already installed derivations. */
|
|
|
|
DrvInfos installedDrvs;
|
2003-12-21 22:34:41 +00:00
|
|
|
queryInstalled(state, installedDrvs, linkPath);
|
2003-11-20 13:48:48 +00:00
|
|
|
selectedDrvs.insert(installedDrvs.begin(), installedDrvs.end());
|
|
|
|
|
2003-12-21 22:34:41 +00:00
|
|
|
createUserEnv(state, selectedDrvs, linkPath);
|
2003-11-20 13:48:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-21 22:34:41 +00:00
|
|
|
static void opInstall(Globals & globals,
|
2003-11-19 17:27:16 +00:00
|
|
|
Strings opFlags, Strings opArgs)
|
|
|
|
{
|
2003-12-21 22:34:41 +00:00
|
|
|
if (opFlags.size() > 0)
|
|
|
|
throw UsageError(format("unknown flags `%1%'") % opFlags.front());
|
2003-11-19 21:32:03 +00:00
|
|
|
if (opArgs.size() < 1) throw UsageError("Nix file expected");
|
2003-11-19 17:27:16 +00:00
|
|
|
|
2003-12-21 23:58:56 +00:00
|
|
|
Path nePath = opArgs.front();
|
|
|
|
DrvNames drvNames = drvNamesFromArgs(
|
|
|
|
Strings(++opArgs.begin(), opArgs.end()));
|
|
|
|
|
|
|
|
installDerivations(globals.state, nePath, drvNames, globals.linkPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
* 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
|
|
|
static void upgradeDerivations(EvalState & state,
|
|
|
|
Path nePath, DrvNames & selectors, const Path & linkPath)
|
|
|
|
{
|
|
|
|
debug(format("upgrading derivations from `%1%'") % nePath);
|
|
|
|
|
|
|
|
/* 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. */
|
|
|
|
DrvInfos installedDrvs;
|
|
|
|
queryInstalled(state, installedDrvs, linkPath);
|
|
|
|
|
|
|
|
/* Fetch all derivations from the input file. */
|
|
|
|
DrvInfos availDrvs;
|
|
|
|
loadDerivations(state, nePath, availDrvs);
|
|
|
|
|
|
|
|
/* Go through all installed derivations. */
|
|
|
|
for (DrvInfos::iterator i = installedDrvs.begin();
|
|
|
|
i != installedDrvs.end(); ++i)
|
|
|
|
{
|
|
|
|
DrvName drvName(i->second.name);
|
|
|
|
|
|
|
|
/* Do we want to upgrade this derivation? */
|
|
|
|
bool upgrade = false;
|
|
|
|
for (DrvNames::iterator j = selectors.begin();
|
|
|
|
j != selectors.end(); ++j)
|
|
|
|
{
|
|
|
|
if (j->matches(drvName)) {
|
|
|
|
j->hits++;
|
|
|
|
upgrade = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!upgrade) continue;
|
|
|
|
|
|
|
|
/* If yes, find the derivation in the input Nix expression
|
|
|
|
with the same name and the highest version number. */
|
|
|
|
DrvInfos::iterator bestDrv = i;
|
|
|
|
DrvName bestName = drvName;
|
|
|
|
for (DrvInfos::iterator j = availDrvs.begin();
|
|
|
|
j != availDrvs.end(); ++j)
|
|
|
|
{
|
|
|
|
DrvName newName(j->second.name);
|
|
|
|
if (newName.name == bestName.name &&
|
|
|
|
compareVersions(newName.version, bestName.version) > 0)
|
|
|
|
bestDrv = j;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bestDrv != i) {
|
|
|
|
printMsg(lvlInfo,
|
|
|
|
format("upgrading `%1%' to `%2%'")
|
|
|
|
% i->second.name % bestDrv->second.name);
|
|
|
|
installedDrvs.erase(i);
|
|
|
|
installedDrvs.insert(*bestDrv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
createUserEnv(state, installedDrvs, linkPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-21 23:58:56 +00:00
|
|
|
static void opUpgrade(Globals & globals,
|
|
|
|
Strings opFlags, Strings opArgs)
|
|
|
|
{
|
|
|
|
if (opFlags.size() > 0)
|
|
|
|
throw UsageError(format("unknown flags `%1%'") % opFlags.front());
|
|
|
|
if (opArgs.size() < 1) throw UsageError("Nix file expected");
|
|
|
|
|
2003-11-19 17:27:16 +00:00
|
|
|
Path nePath = opArgs.front();
|
* 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
|
|
|
DrvNames drvNames = drvNamesFromArgs(
|
|
|
|
Strings(++opArgs.begin(), opArgs.end()));
|
|
|
|
|
|
|
|
upgradeDerivations(globals.state, nePath, drvNames, globals.linkPath);
|
2003-11-19 17:27:16 +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
|
|
|
static void uninstallDerivations(EvalState & state, DrvNames & selectors,
|
2003-12-21 22:34:41 +00:00
|
|
|
Path & linkPath)
|
2003-11-20 13:48:48 +00:00
|
|
|
{
|
|
|
|
DrvInfos installedDrvs;
|
2003-12-21 22:34:41 +00:00
|
|
|
queryInstalled(state, installedDrvs, linkPath);
|
2003-11-20 13:48:48 +00:00
|
|
|
|
2003-12-21 23:58:56 +00:00
|
|
|
for (DrvInfos::iterator i = installedDrvs.begin();
|
|
|
|
i != installedDrvs.end(); ++i)
|
2003-11-20 13:48:48 +00:00
|
|
|
{
|
2003-12-21 23:58:56 +00:00
|
|
|
DrvName drvName(i->second.name);
|
|
|
|
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 16:04:00 +00:00
|
|
|
if (j->matches(drvName)) {
|
|
|
|
printMsg(lvlInfo,
|
|
|
|
format("uninstalling `%1%'") % i->second.name);
|
2003-12-21 23:58:56 +00:00
|
|
|
installedDrvs.erase(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
|
|
|
}
|
2003-11-20 13:48:48 +00:00
|
|
|
}
|
|
|
|
|
2003-12-21 22:34:41 +00:00
|
|
|
createUserEnv(state, installedDrvs, linkPath);
|
2003-11-20 13:48:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-21 22:34:41 +00:00
|
|
|
static void opUninstall(Globals & globals,
|
2003-11-20 13:48:48 +00:00
|
|
|
Strings opFlags, Strings opArgs)
|
|
|
|
{
|
2003-12-21 22:34:41 +00:00
|
|
|
if (opFlags.size() > 0)
|
|
|
|
throw UsageError(format("unknown flags `%1%'") % opFlags.front());
|
|
|
|
|
2003-12-21 23:58:56 +00:00
|
|
|
DrvNames drvNames = drvNamesFromArgs(opArgs);
|
|
|
|
|
|
|
|
uninstallDerivations(globals.state, drvNames, globals.linkPath);
|
2003-11-20 13:48:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-21 22:34:41 +00:00
|
|
|
static void opQuery(Globals & globals,
|
2003-11-19 17:27:16 +00:00
|
|
|
Strings opFlags, Strings opArgs)
|
|
|
|
{
|
2003-11-19 21:32:03 +00:00
|
|
|
enum { qName, qDrvPath, qStatus } query = qName;
|
2003-11-19 17:27:16 +00:00
|
|
|
enum { sInstalled, sAvailable } source = sInstalled;
|
|
|
|
|
|
|
|
for (Strings::iterator i = opFlags.begin();
|
|
|
|
i != opFlags.end(); ++i)
|
|
|
|
if (*i == "--name") query = qName;
|
2003-11-19 21:32:03 +00:00
|
|
|
else if (*i == "--expr" || *i == "-e") query = qDrvPath;
|
|
|
|
else if (*i == "--status" || *i == "-s") query = qStatus;
|
2003-11-19 17:27:16 +00:00
|
|
|
else if (*i == "--installed") source = sInstalled;
|
|
|
|
else if (*i == "--available" || *i == "-f") source = sAvailable;
|
|
|
|
else throw UsageError(format("unknown flag `%1%'") % *i);
|
|
|
|
|
|
|
|
/* Obtain derivation information from the specified source. */
|
|
|
|
DrvInfos drvs;
|
|
|
|
|
|
|
|
switch (source) {
|
|
|
|
|
|
|
|
case sInstalled:
|
2003-12-21 22:34:41 +00:00
|
|
|
queryInstalled(globals.state, drvs, globals.linkPath);
|
2003-11-19 17:27:16 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case sAvailable: {
|
2003-11-19 21:32:03 +00:00
|
|
|
if (opArgs.size() < 1) throw UsageError("Nix file expected");
|
2003-11-19 17:27:16 +00:00
|
|
|
Path nePath = opArgs.front();
|
|
|
|
opArgs.pop_front();
|
2003-12-21 22:34:41 +00:00
|
|
|
loadDerivations(globals.state, nePath, drvs);
|
2003-11-19 17:27:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default: abort();
|
|
|
|
}
|
|
|
|
|
2003-11-19 21:32:03 +00:00
|
|
|
if (opArgs.size() != 0) throw UsageError("no arguments expected");
|
|
|
|
|
2003-11-19 17:27:16 +00:00
|
|
|
/* Perform the specified query on the derivations. */
|
|
|
|
switch (query) {
|
|
|
|
|
|
|
|
case qName: {
|
|
|
|
for (DrvInfos::iterator i = drvs.begin(); i != drvs.end(); ++i)
|
|
|
|
cout << format("%1%\n") % i->second.name;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-11-19 21:32:03 +00:00
|
|
|
case qDrvPath: {
|
|
|
|
for (DrvInfos::iterator i = drvs.begin(); i != drvs.end(); ++i)
|
|
|
|
cout << format("%1%\n") % i->second.drvPath;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case qStatus: {
|
|
|
|
DrvInfos installed;
|
2003-12-21 22:34:41 +00:00
|
|
|
queryInstalled(globals.state, installed, globals.linkPath);
|
2003-11-19 21:32:03 +00:00
|
|
|
|
|
|
|
for (DrvInfos::iterator i = drvs.begin(); i != drvs.end(); ++i) {
|
|
|
|
cout << format("%1%%2% %3%\n")
|
|
|
|
% (installed.find(i->first) != installed.end() ? 'I' : '-')
|
|
|
|
% (isValidPath(i->second.outPath) ? 'P' : '-')
|
|
|
|
% i->second.name;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-11-19 17:27:16 +00:00
|
|
|
default: abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void run(Strings args)
|
|
|
|
{
|
* 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
|
|
|
/* Use a higher default verbosity (lvlInfo). */
|
|
|
|
verbosity = (Verbosity) ((int) verbosity + 1);
|
|
|
|
|
2003-11-19 17:27:16 +00:00
|
|
|
Strings opFlags, opArgs;
|
|
|
|
Operation op = 0;
|
2003-12-21 22:34:41 +00:00
|
|
|
|
|
|
|
Globals globals;
|
|
|
|
globals.linkPath = getLinksDir() + "/current";
|
2003-11-19 17:27:16 +00:00
|
|
|
|
|
|
|
for (Strings::iterator i = args.begin(); i != args.end(); ++i) {
|
|
|
|
string arg = *i;
|
|
|
|
|
|
|
|
Operation oldOp = op;
|
|
|
|
|
|
|
|
if (arg == "--install" || arg == "-i")
|
|
|
|
op = opInstall;
|
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;
|
2003-11-20 13:48:48 +00:00
|
|
|
else if (arg == "--query" || arg == "-q")
|
2003-11-19 17:27:16 +00:00
|
|
|
op = opQuery;
|
2003-12-21 22:34:41 +00:00
|
|
|
else if (arg == "--link" || arg == "-l") {
|
|
|
|
++i;
|
|
|
|
if (i == args.end()) throw UsageError(
|
|
|
|
format("`%1%' requires an argument") % arg);
|
|
|
|
globals.linkPath = absPath(*i);
|
|
|
|
}
|
2003-12-02 10:21:40 +00:00
|
|
|
else if (arg[0] == '-')
|
|
|
|
opFlags.push_back(arg);
|
2003-11-19 17:27:16 +00: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");
|
|
|
|
|
|
|
|
openDB();
|
|
|
|
|
2003-12-21 22:34:41 +00:00
|
|
|
op(globals, 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";
|