2006-07-26 15:05:15 +00:00
|
|
|
|
#include "attr-path.hh"
|
2017-10-24 10:45:11 +00:00
|
|
|
|
#include "common-eval-args.hh"
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 13:28:26 +00:00
|
|
|
|
#include "derivations.hh"
|
|
|
|
|
#include "eval.hh"
|
|
|
|
|
#include "get-drvs.hh"
|
|
|
|
|
#include "globals.hh"
|
|
|
|
|
#include "names.hh"
|
|
|
|
|
#include "profiles.hh"
|
|
|
|
|
#include "shared.hh"
|
2006-11-30 17:43:04 +00:00
|
|
|
|
#include "store-api.hh"
|
2010-04-19 10:47:56 +00:00
|
|
|
|
#include "user-env.hh"
|
2006-09-04 21:06:23 +00:00
|
|
|
|
#include "util.hh"
|
2016-08-26 16:55:55 +00:00
|
|
|
|
#include "json.hh"
|
2013-11-18 23:41:45 +00:00
|
|
|
|
#include "value-to-json.hh"
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 13:28:26 +00:00
|
|
|
|
#include "xml-writer.hh"
|
2018-10-26 09:35:46 +00:00
|
|
|
|
#include "legacy.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 */
|
2014-09-19 14:49:41 +00:00
|
|
|
|
Bindings * autoArgs;
|
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;
|
2014-08-13 01:50:44 +00:00
|
|
|
|
std::shared_ptr<EvalState> state;
|
2004-02-09 11:59:39 +00:00
|
|
|
|
bool dryRun;
|
2004-06-28 14:40:26 +00:00
|
|
|
|
bool preserveInstalled;
|
2013-09-03 19:15:47 +00:00
|
|
|
|
bool removeAll;
|
2006-09-25 14:00:59 +00:00
|
|
|
|
string forceName;
|
2011-04-11 16:27:05 +00:00
|
|
|
|
bool prebuiltOnly;
|
2003-12-21 22:34:41 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef void (* Operation) (Globals & globals,
|
2014-08-13 01:50:44 +00:00
|
|
|
|
Strings opFlags, Strings opArgs);
|
2003-12-01 15:55:05 +00:00
|
|
|
|
|
|
|
|
|
|
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(
|
2017-07-30 11:27:57 +00:00
|
|
|
|
format("'%1%' requires an argument") % arg);
|
2007-09-17 19:24:07 +00:00
|
|
|
|
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;
|
|
|
|
|
else return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-09-03 13:17:51 +00:00
|
|
|
|
static bool isNixExpr(const Path & path, struct stat & st)
|
2007-09-17 16:08:24 +00:00
|
|
|
|
{
|
2013-09-03 13:17:51 +00:00
|
|
|
|
return S_ISREG(st.st_mode) || (S_ISDIR(st.st_mode) && pathExists(path + "/default.nix"));
|
2007-09-17 16:08:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void getAllExprs(EvalState & state,
|
2013-09-03 13:25:51 +00:00
|
|
|
|
const Path & path, StringSet & attrs, Value & v)
|
2007-09-17 16:08:24 +00:00
|
|
|
|
{
|
2014-08-01 14:37:47 +00:00
|
|
|
|
StringSet namesSorted;
|
|
|
|
|
for (auto & i : readDirectory(path)) namesSorted.insert(i.name);
|
2007-09-17 16:08:24 +00:00
|
|
|
|
|
2014-08-01 14:37:47 +00:00
|
|
|
|
for (auto & i : namesSorted) {
|
2012-08-01 20:43:36 +00:00
|
|
|
|
/* Ignore the manifest.nix used by profiles. This is
|
|
|
|
|
necessary to prevent it from showing up in channels (which
|
|
|
|
|
are implemented using profiles). */
|
2014-08-01 14:37:47 +00:00
|
|
|
|
if (i == "manifest.nix") continue;
|
2012-12-03 17:19:49 +00:00
|
|
|
|
|
2014-08-01 14:37:47 +00:00
|
|
|
|
Path path2 = path + "/" + i;
|
2012-12-03 17:19:49 +00:00
|
|
|
|
|
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
|
2012-12-03 17:19:49 +00:00
|
|
|
|
|
2013-09-03 13:17:51 +00:00
|
|
|
|
if (isNixExpr(path2, st) && (!S_ISREG(st.st_mode) || hasSuffix(path2, ".nix"))) {
|
2008-08-25 13:31:57 +00:00
|
|
|
|
/* Strip off the `.nix' filename suffix (if applicable),
|
|
|
|
|
otherwise the attribute cannot be selected with the
|
|
|
|
|
`-A' option. Useful if you want to stick a Nix
|
|
|
|
|
expression directly in ~/.nix-defexpr. */
|
2014-08-01 14:37:47 +00:00
|
|
|
|
string attrName = i;
|
2008-08-25 13:31:57 +00:00
|
|
|
|
if (hasSuffix(attrName, ".nix"))
|
|
|
|
|
attrName = string(attrName, 0, attrName.size() - 4);
|
2019-10-09 13:51:52 +00:00
|
|
|
|
if (!attrs.insert(attrName).second) {
|
2017-07-30 11:27:57 +00:00
|
|
|
|
printError(format("warning: name collision in input Nix expressions, skipping '%1%'") % path2);
|
2013-09-03 13:25:51 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2013-09-03 13:45:32 +00:00
|
|
|
|
/* Load the expression on demand. */
|
2016-08-23 15:11:19 +00:00
|
|
|
|
Value & vFun = state.getBuiltin("import");
|
2013-09-03 13:45:32 +00:00
|
|
|
|
Value & vArg(*state.allocValue());
|
|
|
|
|
mkString(vArg, path2);
|
2015-01-15 11:15:22 +00:00
|
|
|
|
if (v.attrs->size() == v.attrs->capacity())
|
2017-07-30 11:27:57 +00:00
|
|
|
|
throw Error(format("too many Nix expressions in directory '%1%'") % path);
|
2013-09-03 13:45:32 +00:00
|
|
|
|
mkApp(*state.allocAttr(v, state.symbols.create(attrName)), vFun, vArg);
|
2008-08-25 13:31:57 +00:00
|
|
|
|
}
|
2013-09-03 13:17:51 +00:00
|
|
|
|
else if (S_ISDIR(st.st_mode))
|
2008-08-25 13:31:57 +00:00
|
|
|
|
/* `path2' is a directory (with no default.nix in it);
|
|
|
|
|
recurse into it. */
|
2013-09-03 13:25:51 +00:00
|
|
|
|
getAllExprs(state, path2, attrs, v);
|
2007-09-17 16:08:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-09-03 13:17:51 +00:00
|
|
|
|
static void loadSourceExpr(EvalState & state, const Path & path, Value & v)
|
2007-09-17 16:08:24 +00:00
|
|
|
|
{
|
2013-09-03 13:17:51 +00:00
|
|
|
|
struct stat st;
|
|
|
|
|
if (stat(path.c_str(), &st) == -1)
|
2017-07-30 11:27:57 +00:00
|
|
|
|
throw SysError(format("getting information about '%1%'") % path);
|
2013-09-03 13:17:51 +00:00
|
|
|
|
|
2018-09-17 14:36:30 +00:00
|
|
|
|
if (isNixExpr(path, st))
|
2013-09-03 13:17:51 +00:00
|
|
|
|
state.evalFile(path, v);
|
2007-09-17 16:08:24 +00:00
|
|
|
|
|
|
|
|
|
/* The path is a directory. Put the Nix expressions in the
|
2013-10-24 14:41:04 +00:00
|
|
|
|
directory in a set, with the file name of each expression as
|
|
|
|
|
the attribute name. Recurse into subdirectories (but keep the
|
|
|
|
|
set flat, not nested, to make it easier for a user to have a
|
|
|
|
|
~/.nix-defexpr directory that includes some system-wide
|
|
|
|
|
directory). */
|
2018-09-17 14:36:30 +00:00
|
|
|
|
else if (S_ISDIR(st.st_mode)) {
|
2015-01-15 11:15:22 +00:00
|
|
|
|
state.mkAttrs(v, 1024);
|
2013-09-03 13:17:51 +00:00
|
|
|
|
state.mkList(*state.allocAttr(v, state.symbols.create("_combineChannels")), 0);
|
2013-09-03 13:25:51 +00:00
|
|
|
|
StringSet attrs;
|
|
|
|
|
getAllExprs(state, path, attrs, v);
|
2013-09-03 13:17:51 +00:00
|
|
|
|
v.attrs->sort();
|
|
|
|
|
}
|
2018-09-17 14:36:30 +00:00
|
|
|
|
|
|
|
|
|
else throw Error("path '%s' is not a directory or a Nix expression", path);
|
2007-09-17 16:08:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-02-11 16:56:45 +00:00
|
|
|
|
static void loadDerivations(EvalState & state, Path nixExprPath,
|
2010-10-22 14:47:42 +00:00
|
|
|
|
string systemFilter, Bindings & autoArgs,
|
2007-09-17 19:24:07 +00:00
|
|
|
|
const string & pathPrefix, DrvInfos & elems)
|
2003-11-19 17:27:16 +00:00
|
|
|
|
{
|
2013-09-03 13:17:51 +00:00
|
|
|
|
Value vRoot;
|
|
|
|
|
loadSourceExpr(state, nixExprPath, vRoot);
|
|
|
|
|
|
2020-02-07 13:08:24 +00:00
|
|
|
|
Value & v(*findAlongAttrPath(state, pathPrefix, autoArgs, vRoot).first);
|
2012-12-03 17:19:49 +00:00
|
|
|
|
|
2012-10-04 19:22:25 +00:00
|
|
|
|
getDerivations(state, v, pathPrefix, autoArgs, elems, true);
|
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++;
|
2017-07-17 17:02:56 +00:00
|
|
|
|
if (systemFilter != "*" && i->querySystem() != systemFilter)
|
2005-02-14 16:16:02 +00:00
|
|
|
|
elems.erase(i);
|
2005-02-11 16:56:45 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2018-05-02 11:56:34 +00:00
|
|
|
|
static long getPriority(EvalState & state, DrvInfo & drv)
|
2009-06-30 15:53:39 +00:00
|
|
|
|
{
|
2013-11-19 13:09:03 +00:00
|
|
|
|
return drv.queryMetaInt("priority", 0);
|
2009-06-30 15:53:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2018-05-02 11:56:34 +00:00
|
|
|
|
static long comparePriorities(EvalState & state, DrvInfo & drv1, DrvInfo & drv2)
|
2007-05-01 20:33:18 +00:00
|
|
|
|
{
|
2009-06-30 15:53:39 +00:00
|
|
|
|
return getPriority(state, drv2) - getPriority(state, drv1);
|
2007-05-01 20:33:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-12-03 20:01:41 +00:00
|
|
|
|
// FIXME: this function is rather slow since it checks a single path
|
|
|
|
|
// at a time.
|
2013-11-19 13:09:03 +00:00
|
|
|
|
static bool isPrebuilt(EvalState & state, DrvInfo & elem)
|
2007-10-29 14:31:45 +00:00
|
|
|
|
{
|
2019-12-05 18:11:09 +00:00
|
|
|
|
auto path = state.store->parseStorePath(elem.queryOutPath());
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 13:28:26 +00:00
|
|
|
|
if (state.store->isValidPath(path)) return true;
|
2019-12-05 18:11:09 +00:00
|
|
|
|
StorePathSet paths;
|
|
|
|
|
paths.insert(path.clone()); // FIXME: why doesn't StorePathSet{path.clone()} work?
|
|
|
|
|
return state.store->querySubstitutablePaths(paths).count(path);
|
2007-10-29 14:31:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-12-20 12:56:42 +00:00
|
|
|
|
static void checkSelectorUse(DrvNames & selectors)
|
|
|
|
|
{
|
|
|
|
|
/* Check that all selectors have been used. */
|
2015-07-17 17:24:28 +00:00
|
|
|
|
for (auto & i : selectors)
|
|
|
|
|
if (i.hits == 0 && i.fullName != "*")
|
2017-07-30 11:27:57 +00:00
|
|
|
|
throw Error(format("selector '%1%' matches no derivations") % i.fullName);
|
2013-12-20 12:56:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-10-29 14:31:45 +00:00
|
|
|
|
static DrvInfos filterBySelector(EvalState & state, const DrvInfos & allElems,
|
2011-04-11 16:27:05 +00:00
|
|
|
|
const Strings & args, bool newestOnly)
|
2005-02-15 10:49:31 +00:00
|
|
|
|
{
|
|
|
|
|
DrvNames selectors = drvNamesFromArgs(args);
|
2013-09-03 13:56:33 +00:00
|
|
|
|
if (selectors.empty())
|
|
|
|
|
selectors.push_back(DrvName("*"));
|
2005-02-15 10:49:31 +00:00
|
|
|
|
|
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
|
|
|
|
|
2015-07-17 17:24:28 +00:00
|
|
|
|
for (auto & i : selectors) {
|
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
|
|
|
|
{
|
2017-07-17 17:02:56 +00:00
|
|
|
|
DrvName drvName(j->queryName());
|
2015-07-17 17:24:28 +00:00
|
|
|
|
if (i.matches(drvName)) {
|
|
|
|
|
i.hits++;
|
2011-04-11 16:27:05 +00:00
|
|
|
|
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
|
2010-08-04 09:32:42 +00:00
|
|
|
|
with the same name, pick the one matching the current
|
|
|
|
|
system. If there are still multiple derivations, pick the
|
|
|
|
|
one with the highest priority. If there are still multiple
|
|
|
|
|
derivations, pick the one with the highest version.
|
|
|
|
|
Finally, if there are still multiple derivations,
|
|
|
|
|
arbitrarily 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
|
|
|
|
|
2015-07-17 17:24:28 +00:00
|
|
|
|
for (auto & j : matches) {
|
2017-07-17 17:02:56 +00:00
|
|
|
|
DrvName drvName(j.first.queryName());
|
2018-05-02 11:56:34 +00:00
|
|
|
|
long d = 1;
|
2007-05-01 20:33:18 +00:00
|
|
|
|
|
2006-03-10 10:24:46 +00:00
|
|
|
|
Newest::iterator k = newest.find(drvName.name);
|
2012-12-03 17:19:49 +00:00
|
|
|
|
|
2006-02-17 18:11:45 +00:00
|
|
|
|
if (k != newest.end()) {
|
2017-07-17 17:02:56 +00:00
|
|
|
|
d = j.first.querySystem() == k->second.first.querySystem() ? 0 :
|
|
|
|
|
j.first.querySystem() == settings.thisSystem ? 1 :
|
|
|
|
|
k->second.first.querySystem() == settings.thisSystem ? -1 : 0;
|
2010-08-04 09:32:42 +00:00
|
|
|
|
if (d == 0)
|
2015-07-17 17:24:28 +00:00
|
|
|
|
d = comparePriorities(state, j.first, k->second.first);
|
2007-05-01 20:33:18 +00:00
|
|
|
|
if (d == 0)
|
2017-07-17 17:02:56 +00:00
|
|
|
|
d = compareVersions(drvName.version, DrvName(k->second.first.queryName()).version);
|
2007-05-01 20:33:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (d > 0) {
|
2013-11-19 13:09:03 +00:00
|
|
|
|
newest.erase(drvName.name);
|
2015-07-17 17:24:28 +00:00
|
|
|
|
newest.insert(Newest::value_type(drvName.name, j));
|
2017-07-17 17:02:56 +00:00
|
|
|
|
multiple.erase(j.first.queryName());
|
2007-05-01 20:33:18 +00:00
|
|
|
|
} else if (d == 0) {
|
2017-07-17 17:02:56 +00:00
|
|
|
|
multiple.insert(j.first.queryName());
|
2007-05-01 20:33:18 +00:00
|
|
|
|
}
|
2006-02-17 17:47:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
matches.clear();
|
2015-07-17 17:24:28 +00:00
|
|
|
|
for (auto & j : newest) {
|
2017-07-17 17:02:56 +00:00
|
|
|
|
if (multiple.find(j.second.first.queryName()) != multiple.end())
|
2016-09-21 14:11:01 +00:00
|
|
|
|
printInfo(
|
2017-07-30 11:27:57 +00:00
|
|
|
|
"warning: there are multiple derivations named '%1%'; using the first one",
|
2017-07-17 17:02:56 +00:00
|
|
|
|
j.second.first.queryName());
|
2015-07-17 17:24:28 +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. */
|
2015-07-17 17:24:28 +00:00
|
|
|
|
for (auto & j : matches)
|
2019-10-09 13:51:52 +00:00
|
|
|
|
if (done.insert(j.second).second)
|
2015-07-17 17:24:28 +00:00
|
|
|
|
elems.push_back(j.first);
|
2006-02-17 17:47:54 +00:00
|
|
|
|
}
|
2012-12-03 17:19:49 +00:00
|
|
|
|
|
2013-12-20 12:56:42 +00:00
|
|
|
|
checkSelectorUse(selectors);
|
2005-02-15 10:49:31 +00:00
|
|
|
|
|
|
|
|
|
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,
|
2010-10-22 14:47:42 +00:00
|
|
|
|
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;
|
2012-12-03 17:19:49 +00:00
|
|
|
|
|
2005-02-14 17:35:10 +00:00
|
|
|
|
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,
|
2014-09-19 14:49:41 +00:00
|
|
|
|
instSource.systemFilter, *instSource.autoArgs, "", allElems);
|
2005-02-14 16:16:02 +00:00
|
|
|
|
|
2011-04-11 16:27:05 +00:00
|
|
|
|
elems = filterBySelector(state, allElems, args, newestOnly);
|
2012-12-03 17:19:49 +00:00
|
|
|
|
|
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: {
|
2012-12-03 17:19:49 +00:00
|
|
|
|
|
2013-09-03 13:17:51 +00:00
|
|
|
|
Value vArg;
|
|
|
|
|
loadSourceExpr(state, instSource.nixExprPath, vArg);
|
2005-02-14 17:07:43 +00:00
|
|
|
|
|
2015-07-17 17:24:28 +00:00
|
|
|
|
for (auto & i : args) {
|
|
|
|
|
Expr * eFun = state.parseExprFromString(i, absPath("."));
|
2013-09-03 13:17:51 +00:00
|
|
|
|
Value vFun, vTmp;
|
|
|
|
|
state.eval(eFun, vFun);
|
|
|
|
|
mkApp(vTmp, vFun, vArg);
|
2014-09-19 14:49:41 +00:00
|
|
|
|
getDerivations(state, vTmp, "", *instSource.autoArgs, elems, true);
|
2005-02-14 17:07:43 +00:00
|
|
|
|
}
|
2012-12-03 17:19:49 +00:00
|
|
|
|
|
2005-02-14 16:16:02 +00:00
|
|
|
|
break;
|
2005-02-15 12:05:47 +00:00
|
|
|
|
}
|
2012-12-03 17:19:49 +00:00
|
|
|
|
|
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
|
|
|
|
|
2015-07-17 17:24:28 +00:00
|
|
|
|
for (auto & i : args) {
|
2019-12-05 18:11:09 +00:00
|
|
|
|
auto path = state.store->followLinksToStorePath(i);
|
2005-02-14 17:35:10 +00:00
|
|
|
|
|
2019-12-05 18:11:09 +00:00
|
|
|
|
std::string name(path.name());
|
2005-02-14 17:35:10 +00:00
|
|
|
|
|
2017-07-17 17:02:56 +00:00
|
|
|
|
DrvInfo elem(state, "", nullptr);
|
|
|
|
|
elem.setName(name);
|
2013-11-19 13:09:03 +00:00
|
|
|
|
|
2019-12-05 18:11:09 +00:00
|
|
|
|
if (path.isDerivation()) {
|
|
|
|
|
elem.setDrvPath(state.store->printStorePath(path));
|
|
|
|
|
elem.setOutPath(state.store->printStorePath(state.store->derivationFromPath(path).findOutput("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());
|
|
|
|
|
}
|
2019-12-05 18:11:09 +00:00
|
|
|
|
else elem.setOutPath(state.store->printStorePath(path));
|
2005-02-14 17:35:10 +00:00
|
|
|
|
|
2006-02-08 14:32:33 +00:00
|
|
|
|
elems.push_back(elem);
|
2005-02-14 17:35:10 +00:00
|
|
|
|
}
|
2012-12-03 17:19:49 +00:00
|
|
|
|
|
2005-02-14 16:16:02 +00:00
|
|
|
|
break;
|
2005-02-15 12:05:47 +00:00
|
|
|
|
}
|
2012-12-03 17:19:49 +00:00
|
|
|
|
|
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),
|
2011-04-11 16:27:05 +00:00
|
|
|
|
args, newestOnly);
|
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: {
|
2013-09-03 13:17:51 +00:00
|
|
|
|
Value vRoot;
|
|
|
|
|
loadSourceExpr(state, instSource.nixExprPath, vRoot);
|
2015-07-17 17:24:28 +00:00
|
|
|
|
for (auto & i : args) {
|
2020-02-07 13:08:24 +00:00
|
|
|
|
Value & v(*findAlongAttrPath(state, i, *instSource.autoArgs, vRoot).first);
|
2014-09-19 14:49:41 +00:00
|
|
|
|
getDerivations(state, v, "", *instSource.autoArgs, elems, true);
|
2010-04-07 15:47:06 +00:00
|
|
|
|
}
|
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
|
|
|
|
|
2013-11-19 13:09:03 +00:00
|
|
|
|
static void printMissing(EvalState & state, DrvInfos & elems)
|
2006-03-06 11:21:15 +00:00
|
|
|
|
{
|
2019-12-05 18:11:09 +00:00
|
|
|
|
std::vector<StorePathWithOutputs> targets;
|
2015-07-17 17:24:28 +00:00
|
|
|
|
for (auto & i : elems) {
|
|
|
|
|
Path drvPath = i.queryDrvPath();
|
2006-03-06 11:21:15 +00:00
|
|
|
|
if (drvPath != "")
|
2019-12-05 18:11:09 +00:00
|
|
|
|
targets.emplace_back(state.store->parseStorePath(drvPath));
|
2006-03-06 11:21:15 +00:00
|
|
|
|
else
|
2019-12-05 18:11:09 +00:00
|
|
|
|
targets.emplace_back(state.store->parseStorePath(i.queryOutPath()));
|
2006-03-06 11:21:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 13:28:26 +00:00
|
|
|
|
printMissing(state.store, targets);
|
2006-03-06 11:21:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-11-19 13:09:03 +00:00
|
|
|
|
static bool keep(DrvInfo & drv)
|
2009-06-30 15:53:39 +00:00
|
|
|
|
{
|
2013-11-19 13:09:03 +00:00
|
|
|
|
return drv.queryMetaBool("keep", false);
|
2009-06-30 15:53:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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. */
|
2011-04-11 16:27:05 +00:00
|
|
|
|
DrvInfos newElems, newElemsTmp;
|
2014-08-13 01:50:44 +00:00
|
|
|
|
queryInstSources(*globals.state, globals.instSource, args, newElemsTmp, true);
|
2011-04-11 16:27:05 +00:00
|
|
|
|
|
|
|
|
|
/* If --prebuilt-only is given, filter out source-only packages. */
|
2015-07-17 17:24:28 +00:00
|
|
|
|
for (auto & i : newElemsTmp)
|
|
|
|
|
if (!globals.prebuiltOnly || isPrebuilt(*globals.state, i))
|
|
|
|
|
newElems.push_back(i);
|
2005-02-14 16:16:02 +00:00
|
|
|
|
|
|
|
|
|
StringSet newNames;
|
2015-07-17 17:24:28 +00:00
|
|
|
|
for (auto & i : newElems) {
|
2006-09-25 14:00:59 +00:00
|
|
|
|
/* `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 != "")
|
2017-07-17 17:02:56 +00:00
|
|
|
|
i.setName(globals.forceName);
|
|
|
|
|
newNames.insert(DrvName(i.queryName()).name);
|
2006-09-25 14:00:59 +00:00
|
|
|
|
}
|
2005-02-14 16:16:02 +00:00
|
|
|
|
|
|
|
|
|
|
2008-08-04 16:21:45 +00:00
|
|
|
|
while (true) {
|
|
|
|
|
string lockToken = optimisticLockProfile(profile);
|
2012-12-03 17:19:49 +00:00
|
|
|
|
|
2008-08-04 16:21:45 +00:00
|
|
|
|
DrvInfos allElems(newElems);
|
2003-11-20 13:48:48 +00:00
|
|
|
|
|
2013-09-03 19:15:47 +00:00
|
|
|
|
/* Add in the already installed derivations, unless they have
|
|
|
|
|
the same name as a to-be-installed element. */
|
|
|
|
|
if (!globals.removeAll) {
|
2014-08-13 01:50:44 +00:00
|
|
|
|
DrvInfos installedElems = queryInstalled(*globals.state, profile);
|
2013-09-03 19:15:47 +00:00
|
|
|
|
|
2015-07-17 17:24:28 +00:00
|
|
|
|
for (auto & i : installedElems) {
|
2017-07-17 17:02:56 +00:00
|
|
|
|
DrvName drvName(i.queryName());
|
2013-09-03 19:15:47 +00:00
|
|
|
|
if (!globals.preserveInstalled &&
|
|
|
|
|
newNames.find(drvName.name) != newNames.end() &&
|
2015-07-17 17:24:28 +00:00
|
|
|
|
!keep(i))
|
2017-07-30 11:27:57 +00:00
|
|
|
|
printInfo("replacing old '%s'", i.queryName());
|
2013-09-03 19:15:47 +00:00
|
|
|
|
else
|
2015-07-17 17:24:28 +00:00
|
|
|
|
allElems.push_back(i);
|
2013-09-03 19:15:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-17 17:24:28 +00:00
|
|
|
|
for (auto & i : newElems)
|
2017-07-30 11:27:57 +00:00
|
|
|
|
printInfo("installing '%s'", i.queryName());
|
2013-09-03 19:15:47 +00:00
|
|
|
|
}
|
2012-12-03 17:19:49 +00:00
|
|
|
|
|
2014-08-13 01:50:44 +00:00
|
|
|
|
printMissing(*globals.state, newElems);
|
2012-12-03 17:19:49 +00:00
|
|
|
|
|
2008-08-04 16:21:45 +00:00
|
|
|
|
if (globals.dryRun) return;
|
2004-02-09 11:59:39 +00:00
|
|
|
|
|
2014-08-13 01:50:44 +00:00
|
|
|
|
if (createUserEnv(*globals.state, allElems,
|
2012-07-30 23:55:41 +00:00
|
|
|
|
profile, settings.envKeepDerivations, lockToken)) break;
|
2008-08-04 16:21:45 +00:00
|
|
|
|
}
|
2003-11-20 13:48:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-08-13 01:50:44 +00:00
|
|
|
|
static void opInstall(Globals & globals, 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;
|
2013-09-03 19:15:47 +00:00
|
|
|
|
else if (arg == "--remove-all" || arg == "-r")
|
|
|
|
|
globals.removeAll = true;
|
2017-07-30 11:27:57 +00:00
|
|
|
|
else throw UsageError(format("unknown flag '%1%'") % arg);
|
2007-09-17 19:24:07 +00:00
|
|
|
|
}
|
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. */
|
|
|
|
|
|
2008-08-04 16:21:45 +00:00
|
|
|
|
while (true) {
|
|
|
|
|
string lockToken = optimisticLockProfile(globals.profile);
|
2012-12-03 17:19:49 +00:00
|
|
|
|
|
2014-08-13 01:50:44 +00:00
|
|
|
|
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
|
|
|
|
|
2008-08-04 16:21:45 +00:00
|
|
|
|
/* Fetch all derivations from the input file. */
|
|
|
|
|
DrvInfos availElems;
|
2014-08-13 01:50:44 +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
|
|
|
|
|
2008-08-04 16:21:45 +00:00
|
|
|
|
/* Go through all installed derivations. */
|
|
|
|
|
DrvInfos newElems;
|
2015-07-17 17:24:28 +00:00
|
|
|
|
for (auto & i : installedElems) {
|
2017-07-17 17:02:56 +00:00
|
|
|
|
DrvName drvName(i.queryName());
|
* 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
|
|
|
|
|
2009-10-13 09:30:17 +00:00
|
|
|
|
try {
|
2007-04-27 23:48:14 +00:00
|
|
|
|
|
2015-07-17 17:24:28 +00:00
|
|
|
|
if (keep(i)) {
|
|
|
|
|
newElems.push_back(i);
|
2009-10-13 09:30:17 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Find the derivation in the input Nix expression
|
|
|
|
|
with the same name that satisfies the version
|
|
|
|
|
constraints specified by upgradeType. If there are
|
|
|
|
|
multiple matches, take the one with the highest
|
|
|
|
|
priority. If there are still multiple matches,
|
2015-09-17 08:34:54 +00:00
|
|
|
|
take the one with the highest version.
|
|
|
|
|
Do not upgrade if it would decrease the priority. */
|
2009-10-13 09:30:17 +00:00
|
|
|
|
DrvInfos::iterator bestElem = availElems.end();
|
2015-09-17 08:34:54 +00:00
|
|
|
|
string bestVersion;
|
2015-07-17 17:24:28 +00:00
|
|
|
|
for (auto j = availElems.begin(); j != availElems.end(); ++j) {
|
2015-09-17 08:34:54 +00:00
|
|
|
|
if (comparePriorities(*globals.state, i, *j) > 0)
|
|
|
|
|
continue;
|
2017-07-17 17:02:56 +00:00
|
|
|
|
DrvName newName(j->queryName());
|
2009-10-13 09:30:17 +00:00
|
|
|
|
if (newName.name == drvName.name) {
|
2015-09-17 08:34:54 +00:00
|
|
|
|
int d = compareVersions(drvName.version, newName.version);
|
2009-10-13 09:30:17 +00:00
|
|
|
|
if ((upgradeType == utLt && d < 0) ||
|
|
|
|
|
(upgradeType == utLeq && d <= 0) ||
|
|
|
|
|
(upgradeType == utEq && d == 0) ||
|
|
|
|
|
upgradeType == utAlways)
|
|
|
|
|
{
|
2018-05-02 11:56:34 +00:00
|
|
|
|
long d2 = -1;
|
2009-10-13 09:30:17 +00:00
|
|
|
|
if (bestElem != availElems.end()) {
|
2014-08-13 01:50:44 +00:00
|
|
|
|
d2 = comparePriorities(*globals.state, *bestElem, *j);
|
2015-09-17 08:34:54 +00:00
|
|
|
|
if (d2 == 0) d2 = compareVersions(bestVersion, newName.version);
|
2009-10-13 09:30:17 +00:00
|
|
|
|
}
|
2014-08-13 01:50:44 +00:00
|
|
|
|
if (d2 < 0 && (!globals.prebuiltOnly || isPrebuilt(*globals.state, *j))) {
|
2009-10-13 09:30:17 +00:00
|
|
|
|
bestElem = j;
|
2015-09-17 08:34:54 +00:00
|
|
|
|
bestVersion = newName.version;
|
2009-10-13 09:30:17 +00:00
|
|
|
|
}
|
2008-08-04 16:21:45 +00:00
|
|
|
|
}
|
2004-02-09 11:59:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2012-12-03 17:19:49 +00:00
|
|
|
|
|
2009-10-13 09:30:17 +00:00
|
|
|
|
if (bestElem != availElems.end() &&
|
2015-07-17 17:24:28 +00:00
|
|
|
|
i.queryOutPath() !=
|
2013-11-19 13:09:03 +00:00
|
|
|
|
bestElem->queryOutPath())
|
2009-10-13 09:30:17 +00:00
|
|
|
|
{
|
2015-09-17 10:08:49 +00:00
|
|
|
|
const char * action = compareVersions(drvName.version, bestVersion) <= 0
|
|
|
|
|
? "upgrading" : "downgrading";
|
2017-07-30 11:27:57 +00:00
|
|
|
|
printInfo("%1% '%2%' to '%3%'",
|
2017-07-17 17:02:56 +00:00
|
|
|
|
action, i.queryName(), bestElem->queryName());
|
2009-10-13 09:30:17 +00:00
|
|
|
|
newElems.push_back(*bestElem);
|
2015-07-17 17:24:28 +00:00
|
|
|
|
} else newElems.push_back(i);
|
2009-10-13 09:30:17 +00:00
|
|
|
|
|
|
|
|
|
} catch (Error & e) {
|
2017-07-30 11:27:57 +00:00
|
|
|
|
e.addPrefix(fmt("while trying to find an upgrade for '%s':\n", i.queryName()));
|
2009-10-13 09:30:17 +00:00
|
|
|
|
throw;
|
2003-12-23 22:13:36 +00:00
|
|
|
|
}
|
2008-08-04 16:21:45 +00:00
|
|
|
|
}
|
2012-12-03 17:19:49 +00:00
|
|
|
|
|
2014-08-13 01:50:44 +00:00
|
|
|
|
printMissing(*globals.state, newElems);
|
2012-12-03 17:19:49 +00:00
|
|
|
|
|
2008-08-04 16:21:45 +00:00
|
|
|
|
if (globals.dryRun) return;
|
2004-02-09 11:59:39 +00:00
|
|
|
|
|
2014-08-13 01:50:44 +00:00
|
|
|
|
if (createUserEnv(*globals.state, newElems,
|
2012-07-30 23:55:41 +00:00
|
|
|
|
globals.profile, settings.envKeepDerivations, lockToken)) break;
|
2008-08-04 16:21:45 +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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-08-13 01:50:44 +00:00
|
|
|
|
static void opUpgrade(Globals & globals, 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;
|
2017-07-30 11:27:57 +00:00
|
|
|
|
else throw UsageError(format("unknown flag '%1%'") % arg);
|
2007-09-17 19:24:07 +00:00
|
|
|
|
}
|
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)
|
|
|
|
|
{
|
2013-11-19 13:09:03 +00:00
|
|
|
|
Value * v = state.allocValue();
|
|
|
|
|
mkString(*v, value.c_str());
|
|
|
|
|
drv.setMeta(name, v);
|
2007-02-02 01:52:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-08-13 01:50:44 +00:00
|
|
|
|
static void opSetFlag(Globals & globals, Strings opFlags, Strings opArgs)
|
2007-02-02 01:52:42 +00:00
|
|
|
|
{
|
|
|
|
|
if (opFlags.size() > 0)
|
2017-07-30 11:27:57 +00:00
|
|
|
|
throw UsageError(format("unknown flag '%1%'") % opFlags.front());
|
2007-02-02 01:52:42 +00:00
|
|
|
|
if (opArgs.size() < 2)
|
2017-07-30 11:27:57 +00:00
|
|
|
|
throw UsageError("not enough arguments to '--set-flag'");
|
2007-02-02 01:52:42 +00:00
|
|
|
|
|
|
|
|
|
Strings::iterator arg = opArgs.begin();
|
|
|
|
|
string flagName = *arg++;
|
|
|
|
|
string flagValue = *arg++;
|
|
|
|
|
DrvNames selectors = drvNamesFromArgs(Strings(arg, opArgs.end()));
|
|
|
|
|
|
2008-08-04 16:21:45 +00:00
|
|
|
|
while (true) {
|
|
|
|
|
string lockToken = optimisticLockProfile(globals.profile);
|
2007-02-02 01:52:42 +00:00
|
|
|
|
|
2014-08-13 01:50:44 +00:00
|
|
|
|
DrvInfos installedElems = queryInstalled(*globals.state, globals.profile);
|
2008-08-04 16:21:45 +00:00
|
|
|
|
|
|
|
|
|
/* Update all matching derivations. */
|
2015-07-17 17:24:28 +00:00
|
|
|
|
for (auto & i : installedElems) {
|
2017-07-17 17:02:56 +00:00
|
|
|
|
DrvName drvName(i.queryName());
|
2015-07-17 17:24:28 +00:00
|
|
|
|
for (auto & j : selectors)
|
|
|
|
|
if (j.matches(drvName)) {
|
2017-07-30 11:27:57 +00:00
|
|
|
|
printInfo("setting flag on '%1%'", i.queryName());
|
2015-07-17 17:24:28 +00:00
|
|
|
|
j.hits++;
|
|
|
|
|
setMetaFlag(*globals.state, i, flagName, flagValue);
|
2008-08-04 16:21:45 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-02-02 01:52:42 +00:00
|
|
|
|
|
2013-12-20 12:56:42 +00:00
|
|
|
|
checkSelectorUse(selectors);
|
|
|
|
|
|
2008-08-04 16:21:45 +00:00
|
|
|
|
/* Write the new user environment. */
|
2014-08-13 01:50:44 +00:00
|
|
|
|
if (createUserEnv(*globals.state, installedElems,
|
2012-07-30 23:55:41 +00:00
|
|
|
|
globals.profile, settings.envKeepDerivations, lockToken)) break;
|
2008-08-04 16:21:45 +00:00
|
|
|
|
}
|
2003-11-19 17:27:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-08-13 01:50:44 +00:00
|
|
|
|
static void opSet(Globals & globals, Strings opFlags, Strings opArgs)
|
2006-12-12 19:06:02 +00:00
|
|
|
|
{
|
2016-06-02 11:33:49 +00:00
|
|
|
|
auto store2 = globals.state->store.dynamic_pointer_cast<LocalFSStore>();
|
|
|
|
|
if (!store2) throw Error("--set is not supported for this Nix store");
|
|
|
|
|
|
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)) ;
|
2017-07-30 11:27:57 +00:00
|
|
|
|
else throw UsageError(format("unknown flag '%1%'") % arg);
|
2007-09-17 19:24:07 +00:00
|
|
|
|
}
|
2006-12-12 19:06:02 +00:00
|
|
|
|
|
|
|
|
|
DrvInfos elems;
|
2014-08-13 01:50:44 +00:00
|
|
|
|
queryInstSources(*globals.state, globals.instSource, opArgs, elems, true);
|
2006-12-12 19:06:02 +00:00
|
|
|
|
|
|
|
|
|
if (elems.size() != 1)
|
|
|
|
|
throw Error("--set requires exactly one derivation");
|
2012-12-03 17:19:49 +00:00
|
|
|
|
|
2006-12-12 19:06:02 +00:00
|
|
|
|
DrvInfo & drv(elems.front());
|
|
|
|
|
|
2014-09-16 17:34:59 +00:00
|
|
|
|
if (globals.forceName != "")
|
2017-07-17 17:02:56 +00:00
|
|
|
|
drv.setName(globals.forceName);
|
2014-09-16 17:34:59 +00:00
|
|
|
|
|
2013-11-19 13:09:03 +00:00
|
|
|
|
if (drv.queryDrvPath() != "") {
|
2019-12-05 18:11:09 +00:00
|
|
|
|
std::vector<StorePathWithOutputs> paths{globals.state->store->parseStorePath(drv.queryDrvPath())};
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 13:28:26 +00:00
|
|
|
|
printMissing(globals.state->store, paths);
|
2008-08-04 14:58:50 +00:00
|
|
|
|
if (globals.dryRun) return;
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 13:28:26 +00:00
|
|
|
|
globals.state->store->buildPaths(paths, globals.state->repair ? bmRepair : bmNormal);
|
2019-12-05 18:11:09 +00:00
|
|
|
|
} else {
|
|
|
|
|
printMissing(globals.state->store,
|
|
|
|
|
{globals.state->store->parseStorePath(drv.queryOutPath())});
|
2008-08-04 14:58:50 +00:00
|
|
|
|
if (globals.dryRun) return;
|
2019-12-05 18:11:09 +00:00
|
|
|
|
globals.state->store->ensurePath(globals.state->store->parseStorePath(drv.queryOutPath()));
|
2008-08-04 14:58:50 +00:00
|
|
|
|
}
|
2006-12-12 19:06:02 +00:00
|
|
|
|
|
|
|
|
|
debug(format("switching to new user environment"));
|
2016-06-02 11:33:49 +00:00
|
|
|
|
Path generation = createGeneration(ref<LocalFSStore>(store2), globals.profile, drv.queryOutPath());
|
2006-12-12 19:06:02 +00:00
|
|
|
|
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
|
|
|
|
{
|
2008-08-04 16:21:45 +00:00
|
|
|
|
while (true) {
|
|
|
|
|
string lockToken = optimisticLockProfile(profile);
|
|
|
|
|
|
2014-08-13 01:50:44 +00:00
|
|
|
|
DrvInfos installedElems = queryInstalled(*globals.state, profile);
|
2008-08-04 16:21:45 +00:00
|
|
|
|
DrvInfos newElems;
|
|
|
|
|
|
2015-07-17 17:24:28 +00:00
|
|
|
|
for (auto & i : installedElems) {
|
2017-07-17 17:02:56 +00:00
|
|
|
|
DrvName drvName(i.queryName());
|
2008-08-04 16:21:45 +00:00
|
|
|
|
bool found = false;
|
2015-07-17 17:24:28 +00:00
|
|
|
|
for (auto & j : selectors)
|
2008-08-04 16:21:45 +00:00
|
|
|
|
/* !!! the repeated calls to followLinksToStorePath()
|
|
|
|
|
are expensive, should pre-compute them. */
|
2019-12-05 18:11:09 +00:00
|
|
|
|
if ((isPath(j) && globals.state->store->parseStorePath(i.queryOutPath()) == globals.state->store->followLinksToStorePath(j))
|
2015-07-17 17:24:28 +00:00
|
|
|
|
|| DrvName(j).matches(drvName))
|
2008-08-04 16:21:45 +00:00
|
|
|
|
{
|
2017-07-30 11:27:57 +00:00
|
|
|
|
printInfo("uninstalling '%s'", i.queryName());
|
2008-08-04 16:21:45 +00:00
|
|
|
|
found = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2015-07-17 17:24:28 +00:00
|
|
|
|
if (!found) newElems.push_back(i);
|
2008-08-04 16:21:45 +00:00
|
|
|
|
}
|
2003-11-20 13:48:48 +00:00
|
|
|
|
|
2008-08-04 16:21:45 +00:00
|
|
|
|
if (globals.dryRun) return;
|
2004-02-09 11:59:39 +00:00
|
|
|
|
|
2014-08-13 01:50:44 +00:00
|
|
|
|
if (createUserEnv(*globals.state, newElems,
|
2012-07-30 23:55:41 +00:00
|
|
|
|
profile, settings.envKeepDerivations, lockToken)) break;
|
2008-08-04 16:21:45 +00:00
|
|
|
|
}
|
2003-11-20 13:48:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-08-13 01:50:44 +00:00
|
|
|
|
static void opUninstall(Globals & globals, Strings opFlags, Strings opArgs)
|
2003-11-20 13:48:48 +00:00
|
|
|
|
{
|
2003-12-21 22:34:41 +00:00
|
|
|
|
if (opFlags.size() > 0)
|
2017-07-30 11:27:57 +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
|
|
|
|
{
|
2017-07-17 17:02:56 +00:00
|
|
|
|
auto a_name = a.queryName();
|
|
|
|
|
auto b_name = b.queryName();
|
2004-10-14 15:09:55 +00:00
|
|
|
|
return lexicographical_compare(
|
2017-07-17 17:02:56 +00:00
|
|
|
|
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)
|
|
|
|
|
{
|
2018-05-02 11:56:34 +00:00
|
|
|
|
auto nrColumns = table.size() > 0 ? table.front().size() : 0;
|
2012-12-03 17:19:49 +00:00
|
|
|
|
|
2018-05-02 11:56:34 +00:00
|
|
|
|
vector<size_t> widths;
|
2004-07-01 13:35:10 +00:00
|
|
|
|
widths.resize(nrColumns);
|
2012-12-03 17:19:49 +00:00
|
|
|
|
|
2015-07-17 17:24:28 +00:00
|
|
|
|
for (auto & i : table) {
|
|
|
|
|
assert(i.size() == nrColumns);
|
2004-10-29 11:22:49 +00:00
|
|
|
|
Strings::iterator j;
|
2018-05-02 11:56:34 +00:00
|
|
|
|
size_t column;
|
2015-07-17 17:24:28 +00:00
|
|
|
|
for (j = i.begin(), column = 0; j != i.end(); ++j, ++column)
|
2004-07-01 13:35:10 +00:00
|
|
|
|
if (j->size() > widths[column]) widths[column] = j->size();
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-17 17:24:28 +00:00
|
|
|
|
for (auto & i : table) {
|
2004-10-29 11:22:49 +00:00
|
|
|
|
Strings::iterator j;
|
2018-05-02 11:56:34 +00:00
|
|
|
|
size_t column;
|
2015-07-17 17:24:28 +00:00
|
|
|
|
for (j = i.begin(), column = 0; j != i.end(); ++j, ++column) {
|
2009-07-02 08:52:12 +00:00
|
|
|
|
string s = *j;
|
|
|
|
|
replace(s.begin(), s.end(), '\n', ' ');
|
|
|
|
|
cout << s;
|
2004-07-01 13:35:10 +00:00
|
|
|
|
if (column < nrColumns - 1)
|
2009-07-02 08:52:12 +00:00
|
|
|
|
cout << string(widths[column] - s.size() + 2, ' ');
|
2004-07-01 13:35:10 +00:00
|
|
|
|
}
|
2006-09-04 21:06:23 +00:00
|
|
|
|
cout << std::endl;
|
2004-07-01 13:35:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-08-10 21:36:16 +00:00
|
|
|
|
/* This function compares the version of an element against the
|
* 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
|
|
|
|
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
|
|
|
|
{
|
2017-07-17 17:02:56 +00:00
|
|
|
|
DrvName name(elem.queryName());
|
2012-12-03 17:19:49 +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
|
|
|
|
VersionDiff diff = cvUnavail;
|
|
|
|
|
version = "?";
|
2012-12-03 17:19:49 +00:00
|
|
|
|
|
2015-07-17 17:24:28 +00:00
|
|
|
|
for (auto & i : elems) {
|
2017-07-17 17:02:56 +00:00
|
|
|
|
DrvName name2(i.queryName());
|
* 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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-11-18 23:41:45 +00:00
|
|
|
|
static void queryJSON(Globals & globals, vector<DrvInfo> & elems)
|
|
|
|
|
{
|
2016-08-26 16:55:55 +00:00
|
|
|
|
JSONObject topObj(cout, true);
|
2015-07-17 17:24:28 +00:00
|
|
|
|
for (auto & i : elems) {
|
2016-08-26 16:55:55 +00:00
|
|
|
|
JSONObject pkgObj = topObj.object(i.attrPath);
|
2013-11-18 23:41:45 +00:00
|
|
|
|
|
2019-07-28 02:40:19 +00:00
|
|
|
|
auto drvName = DrvName(i.queryName());
|
|
|
|
|
pkgObj.attr("name", drvName.fullName);
|
|
|
|
|
pkgObj.attr("pname", drvName.name);
|
|
|
|
|
pkgObj.attr("version", drvName.version);
|
2017-07-17 17:02:56 +00:00
|
|
|
|
pkgObj.attr("system", i.querySystem());
|
2013-11-18 23:41:45 +00:00
|
|
|
|
|
2016-08-26 16:55:55 +00:00
|
|
|
|
JSONObject metaObj = pkgObj.object("meta");
|
2015-07-17 17:24:28 +00:00
|
|
|
|
StringSet metaNames = i.queryMetaNames();
|
|
|
|
|
for (auto & j : metaNames) {
|
2016-08-26 16:55:55 +00:00
|
|
|
|
auto placeholder = metaObj.placeholder(j);
|
2015-07-17 17:24:28 +00:00
|
|
|
|
Value * v = i.queryMeta(j);
|
2014-06-02 15:58:43 +00:00
|
|
|
|
if (!v) {
|
2017-07-30 11:27:57 +00:00
|
|
|
|
printError("derivation '%s' has invalid meta attribute '%s'", i.queryName(), j);
|
2016-08-26 16:55:55 +00:00
|
|
|
|
placeholder.write(nullptr);
|
2014-06-02 15:58:43 +00:00
|
|
|
|
} else {
|
2013-11-19 13:29:39 +00:00
|
|
|
|
PathSet context;
|
2016-08-26 16:55:55 +00:00
|
|
|
|
printValueAsJSON(*globals.state, true, *v, placeholder, context);
|
2013-11-19 13:29:39 +00:00
|
|
|
|
}
|
2013-11-18 23:41:45 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-08-13 01:50:44 +00:00
|
|
|
|
static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
|
2003-11-19 17:27:16 +00:00
|
|
|
|
{
|
2007-09-17 19:24:07 +00:00
|
|
|
|
Strings remaining;
|
|
|
|
|
string attrPath;
|
2012-12-03 17:19:49 +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;
|
* 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;
|
2013-11-18 23:41:45 +00:00
|
|
|
|
bool jsonOutput = false;
|
2004-07-01 13:13:37 +00:00
|
|
|
|
|
2003-11-19 17:27:16 +00:00
|
|
|
|
enum { sInstalled, sAvailable } source = sInstalled;
|
|
|
|
|
|
2012-07-30 23:55:41 +00:00
|
|
|
|
settings.readOnlyMode = true; /* makes evaluation a bit faster */
|
2004-10-27 10:24:44 +00:00
|
|
|
|
|
2014-08-13 01:50:44 +00:00
|
|
|
|
for (Strings::iterator i = opFlags.begin(); i != opFlags.end(); ) {
|
2007-09-17 19:24:07 +00:00
|
|
|
|
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 == "--xml") xmlOutput = true;
|
2013-11-18 23:41:45 +00:00
|
|
|
|
else if (arg == "--json") jsonOutput = true;
|
2007-09-17 19:24:07 +00:00
|
|
|
|
else if (arg == "--attr-path" || arg == "-P") printAttrPath = true;
|
|
|
|
|
else if (arg == "--attr" || arg == "-A")
|
2014-08-13 01:50:44 +00:00
|
|
|
|
attrPath = needArg(i, opFlags, arg);
|
|
|
|
|
else
|
2017-07-30 11:27:57 +00:00
|
|
|
|
throw UsageError(format("unknown flag '%1%'") % arg);
|
2006-03-10 10:24:46 +00:00
|
|
|
|
}
|
2003-11-19 17:27:16 +00:00
|
|
|
|
|
2020-03-01 08:11:22 +00:00
|
|
|
|
if (printAttrPath && source != sAvailable)
|
|
|
|
|
throw UsageError("--attr-path(-P) only works with --available");
|
2012-12-03 17:19:49 +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
|
|
|
|
/* 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)
|
2014-08-13 01:50:44 +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)
|
2014-08-13 01:50:44 +00:00
|
|
|
|
loadDerivations(*globals.state, globals.instSource.nixExprPath,
|
2014-09-19 14:49:41 +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
|
|
|
|
|
2014-08-13 01:50:44 +00:00
|
|
|
|
DrvInfos elems_ = filterBySelector(*globals.state,
|
2006-03-10 10:24:46 +00:00
|
|
|
|
source == sInstalled ? installedElems : availElems,
|
2014-08-13 01:50:44 +00:00
|
|
|
|
opArgs, false);
|
2011-04-11 16:27:05 +00:00
|
|
|
|
|
2006-02-08 13:21:16 +00:00
|
|
|
|
DrvInfos & otherElems(source == sInstalled ? availElems : installedElems);
|
2004-02-02 10:51:54 +00:00
|
|
|
|
|
2012-12-03 17:19:49 +00:00
|
|
|
|
|
2004-02-02 10:51:54 +00:00
|
|
|
|
/* Sort them by name. */
|
2006-02-08 13:21:16 +00:00
|
|
|
|
/* !!! */
|
2013-11-18 23:41:45 +00:00
|
|
|
|
vector<DrvInfo> elems;
|
2015-07-17 17:24:28 +00:00
|
|
|
|
for (auto & i : elems_) elems.push_back(i);
|
2013-11-18 23:41:45 +00:00
|
|
|
|
sort(elems.begin(), elems.end(), cmpElemByName);
|
2003-11-19 17:27:16 +00:00
|
|
|
|
|
2012-12-03 17:19:49 +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 */
|
2012-12-03 17:19:49 +00:00
|
|
|
|
|
2005-05-08 10:32:09 +00:00
|
|
|
|
if (printStatus) {
|
2015-07-17 17:24:28 +00:00
|
|
|
|
for (auto & i : installedElems)
|
|
|
|
|
installed.insert(i.queryOutPath());
|
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
|
|
|
|
|
2012-07-11 14:14:06 +00:00
|
|
|
|
|
|
|
|
|
/* Query which paths have substitutes. */
|
2019-12-05 18:11:09 +00:00
|
|
|
|
StorePathSet validPaths;
|
|
|
|
|
StorePathSet substitutablePaths;
|
2012-12-03 20:01:41 +00:00
|
|
|
|
if (printStatus || globals.prebuiltOnly) {
|
2019-12-05 18:11:09 +00:00
|
|
|
|
StorePathSet paths;
|
2015-07-17 17:24:28 +00:00
|
|
|
|
for (auto & i : elems)
|
2012-07-11 14:14:06 +00:00
|
|
|
|
try {
|
2019-12-05 18:11:09 +00:00
|
|
|
|
paths.insert(globals.state->store->parseStorePath(i.queryOutPath()));
|
2012-07-11 14:14:06 +00:00
|
|
|
|
} catch (AssertionError & e) {
|
2017-07-30 11:27:57 +00:00
|
|
|
|
printMsg(lvlTalkative, "skipping derivation named '%s' which gives an assertion failure", i.queryName());
|
2015-07-17 17:24:28 +00:00
|
|
|
|
i.setFailed();
|
2012-07-11 14:14:06 +00:00
|
|
|
|
}
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 13:28:26 +00:00
|
|
|
|
validPaths = globals.state->store->queryValidPaths(paths);
|
|
|
|
|
substitutablePaths = globals.state->store->querySubstitutablePaths(paths);
|
2012-07-11 14:14:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-12-03 17:19:49 +00:00
|
|
|
|
|
2006-08-03 15:52:09 +00:00
|
|
|
|
/* Print the desired columns, or XML output. */
|
2013-11-18 23:41:45 +00:00
|
|
|
|
if (jsonOutput) {
|
|
|
|
|
queryJSON(globals, elems);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-20 19:26:37 +00:00
|
|
|
|
bool tty = isatty(STDOUT_FILENO);
|
|
|
|
|
RunPager pager;
|
|
|
|
|
|
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");
|
2012-12-03 17:19:49 +00:00
|
|
|
|
|
2015-07-17 17:24:28 +00:00
|
|
|
|
for (auto & i : elems) {
|
2006-03-08 16:03:58 +00:00
|
|
|
|
try {
|
2015-07-17 17:24:28 +00:00
|
|
|
|
if (i.hasFailed()) continue;
|
2012-12-03 17:19:49 +00:00
|
|
|
|
|
2017-07-30 11:27:57 +00:00
|
|
|
|
//Activity act(*logger, lvlDebug, format("outputting query result '%1%'") % i.attrPath);
|
2006-08-03 15:52:09 +00:00
|
|
|
|
|
2012-12-03 20:01:41 +00:00
|
|
|
|
if (globals.prebuiltOnly &&
|
2019-12-05 18:11:09 +00:00
|
|
|
|
!validPaths.count(globals.state->store->parseStorePath(i.queryOutPath())) &&
|
|
|
|
|
!substitutablePaths.count(globals.state->store->parseStorePath(i.queryOutPath())))
|
2012-12-03 20:01:41 +00:00
|
|
|
|
continue;
|
2011-04-11 16:27:05 +00:00
|
|
|
|
|
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) {
|
2015-07-17 17:24:28 +00:00
|
|
|
|
Path outPath = i.queryOutPath();
|
2019-12-05 18:11:09 +00:00
|
|
|
|
bool hasSubs = substitutablePaths.count(globals.state->store->parseStorePath(outPath));
|
2012-07-11 15:08:47 +00:00
|
|
|
|
bool isInstalled = installed.find(outPath) != installed.end();
|
2019-12-05 18:11:09 +00:00
|
|
|
|
bool isValid = validPaths.count(globals.state->store->parseStorePath(outPath));
|
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)
|
2015-07-17 17:24:28 +00:00
|
|
|
|
attrs["attrPath"] = i.attrPath;
|
2006-08-03 15:52:09 +00:00
|
|
|
|
else if (printAttrPath)
|
2015-07-17 17:24:28 +00:00
|
|
|
|
columns.push_back(i.attrPath);
|
2006-07-25 16:40:38 +00:00
|
|
|
|
|
2019-07-28 02:40:19 +00:00
|
|
|
|
if (xmlOutput) {
|
|
|
|
|
auto drvName = DrvName(i.queryName());
|
|
|
|
|
attrs["name"] = drvName.fullName;
|
|
|
|
|
attrs["pname"] = drvName.name;
|
|
|
|
|
attrs["version"] = drvName.version;
|
|
|
|
|
} else if (printName) {
|
2017-07-17 17:02:56 +00:00
|
|
|
|
columns.push_back(i.queryName());
|
2019-07-28 02:40:19 +00:00
|
|
|
|
}
|
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;
|
2015-07-17 17:24:28 +00:00
|
|
|
|
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;
|
2014-08-20 19:26:37 +00:00
|
|
|
|
if (diff == cvGreater && tty)
|
2014-08-20 14:01:16 +00:00
|
|
|
|
column = ANSI_RED + column + ANSI_NORMAL;
|
2006-08-03 15:52:09 +00:00
|
|
|
|
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) {
|
2017-07-17 17:02:56 +00:00
|
|
|
|
if (i.querySystem() != "") attrs["system"] = i.querySystem();
|
2006-08-03 15:52:09 +00:00
|
|
|
|
}
|
2012-11-28 12:49:44 +00:00
|
|
|
|
else if (printSystem)
|
2017-07-17 17:02:56 +00:00
|
|
|
|
columns.push_back(i.querySystem());
|
2005-10-06 15:51:59 +00:00
|
|
|
|
|
2006-08-03 15:52:09 +00:00
|
|
|
|
if (printDrvPath) {
|
2015-07-17 17:24:28 +00:00
|
|
|
|
string drvPath = i.queryDrvPath();
|
2006-08-03 15:52:09 +00:00
|
|
|
|
if (xmlOutput) {
|
|
|
|
|
if (drvPath != "") attrs["drvPath"] = drvPath;
|
|
|
|
|
} else
|
|
|
|
|
columns.push_back(drvPath == "" ? "-" : drvPath);
|
|
|
|
|
}
|
2012-11-28 12:49:44 +00:00
|
|
|
|
|
|
|
|
|
if (printOutPath && !xmlOutput) {
|
2015-07-17 17:24:28 +00:00
|
|
|
|
DrvInfo::Outputs outputs = i.queryOutputs();
|
2012-11-28 12:49:44 +00:00
|
|
|
|
string s;
|
2015-07-17 17:24:28 +00:00
|
|
|
|
for (auto & j : outputs) {
|
2012-11-28 12:49:44 +00:00
|
|
|
|
if (!s.empty()) s += ';';
|
2015-07-17 17:24:28 +00:00
|
|
|
|
if (j.first != "out") { s += j.first; s += "="; }
|
|
|
|
|
s += j.second;
|
2012-11-28 12:49:44 +00:00
|
|
|
|
}
|
|
|
|
|
columns.push_back(s);
|
2006-08-03 15:52:09 +00:00
|
|
|
|
}
|
2006-03-10 16:20:42 +00:00
|
|
|
|
|
|
|
|
|
if (printDescription) {
|
2015-07-17 17:24:28 +00:00
|
|
|
|
string descr = i.queryMetaString("description");
|
2006-08-03 15:52:09 +00:00
|
|
|
|
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
|
|
|
|
|
2012-11-28 12:49:44 +00:00
|
|
|
|
if (xmlOutput) {
|
|
|
|
|
if (printOutPath || printMeta) {
|
2007-05-01 11:30:52 +00:00
|
|
|
|
XMLOpenElement item(xml, "item", attrs);
|
2012-11-28 12:49:44 +00:00
|
|
|
|
if (printOutPath) {
|
2015-07-17 17:24:28 +00:00
|
|
|
|
DrvInfo::Outputs outputs = i.queryOutputs();
|
|
|
|
|
for (auto & j : outputs) {
|
2012-11-28 12:49:44 +00:00
|
|
|
|
XMLAttrs attrs2;
|
2015-07-17 17:24:28 +00:00
|
|
|
|
attrs2["name"] = j.first;
|
|
|
|
|
attrs2["path"] = j.second;
|
2012-11-28 12:49:44 +00:00
|
|
|
|
xml.writeEmptyElement("output", attrs2);
|
2009-06-30 15:53:39 +00:00
|
|
|
|
}
|
2007-05-01 11:30:52 +00:00
|
|
|
|
}
|
2012-11-28 12:49:44 +00:00
|
|
|
|
if (printMeta) {
|
2015-07-17 17:24:28 +00:00
|
|
|
|
StringSet metaNames = i.queryMetaNames();
|
|
|
|
|
for (auto & j : metaNames) {
|
2012-11-28 12:49:44 +00:00
|
|
|
|
XMLAttrs attrs2;
|
2015-07-17 17:24:28 +00:00
|
|
|
|
attrs2["name"] = j;
|
|
|
|
|
Value * v = i.queryMeta(j);
|
2013-11-19 13:29:39 +00:00
|
|
|
|
if (!v)
|
2017-07-30 11:27:57 +00:00
|
|
|
|
printError("derivation '%s' has invalid meta attribute '%s'", i.queryName(), j);
|
2013-11-19 13:29:39 +00:00
|
|
|
|
else {
|
|
|
|
|
if (v->type == tString) {
|
|
|
|
|
attrs2["type"] = "string";
|
|
|
|
|
attrs2["value"] = v->string.s;
|
|
|
|
|
xml.writeEmptyElement("meta", attrs2);
|
|
|
|
|
} else if (v->type == tInt) {
|
|
|
|
|
attrs2["type"] = "int";
|
|
|
|
|
attrs2["value"] = (format("%1%") % v->integer).str();
|
|
|
|
|
xml.writeEmptyElement("meta", attrs2);
|
2016-01-04 23:40:40 +00:00
|
|
|
|
} else if (v->type == tFloat) {
|
|
|
|
|
attrs2["type"] = "float";
|
|
|
|
|
attrs2["value"] = (format("%1%") % v->fpoint).str();
|
|
|
|
|
xml.writeEmptyElement("meta", attrs2);
|
2013-11-19 13:29:39 +00:00
|
|
|
|
} else if (v->type == tBool) {
|
|
|
|
|
attrs2["type"] = "bool";
|
|
|
|
|
attrs2["value"] = v->boolean ? "true" : "false";
|
|
|
|
|
xml.writeEmptyElement("meta", attrs2);
|
2015-07-23 20:05:09 +00:00
|
|
|
|
} else if (v->isList()) {
|
2013-11-19 13:29:39 +00:00
|
|
|
|
attrs2["type"] = "strings";
|
|
|
|
|
XMLOpenElement m(xml, "meta", attrs2);
|
2015-07-23 20:05:09 +00:00
|
|
|
|
for (unsigned int j = 0; j < v->listSize(); ++j) {
|
|
|
|
|
if (v->listElems()[j]->type != tString) continue;
|
2013-11-19 13:29:39 +00:00
|
|
|
|
XMLAttrs attrs3;
|
2015-07-23 20:05:09 +00:00
|
|
|
|
attrs3["value"] = v->listElems()[j]->string.s;
|
2013-11-19 13:29:39 +00:00
|
|
|
|
xml.writeEmptyElement("string", attrs3);
|
|
|
|
|
}
|
2015-11-21 10:43:44 +00:00
|
|
|
|
} else if (v->type == tAttrs) {
|
|
|
|
|
attrs2["type"] = "strings";
|
|
|
|
|
XMLOpenElement m(xml, "meta", attrs2);
|
|
|
|
|
Bindings & attrs = *v->attrs;
|
|
|
|
|
for (auto &i : attrs) {
|
|
|
|
|
Attr & a(*attrs.find(i.name));
|
|
|
|
|
if(a.value->type != tString) continue;
|
|
|
|
|
XMLAttrs attrs3;
|
|
|
|
|
attrs3["type"] = i.name;
|
|
|
|
|
attrs3["value"] = a.value->string.s;
|
|
|
|
|
xml.writeEmptyElement("string", attrs3);
|
2013-11-19 13:09:03 +00:00
|
|
|
|
}
|
2015-11-21 10:43:44 +00:00
|
|
|
|
}
|
2012-11-28 12:49:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else
|
2007-05-01 11:30:52 +00:00
|
|
|
|
xml.writeEmptyElement("item", attrs);
|
2012-11-28 12:49:44 +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) {
|
2017-07-30 11:27:57 +00:00
|
|
|
|
printMsg(lvlTalkative, "skipping derivation named '%1%' which gives an assertion failure", i.queryName());
|
2013-11-19 13:09:03 +00:00
|
|
|
|
} catch (Error & e) {
|
2017-07-30 11:27:57 +00:00
|
|
|
|
e.addPrefix(fmt("while querying the derivation named '%1%':\n", i.queryName()));
|
2013-11-19 13:09:03 +00:00
|
|
|
|
throw;
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-08-13 01:50:44 +00:00
|
|
|
|
static void opSwitchProfile(Globals & globals, Strings opFlags, Strings opArgs)
|
2004-01-05 11:18:59 +00:00
|
|
|
|
{
|
|
|
|
|
if (opFlags.size() > 0)
|
2017-07-30 11:27:57 +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());
|
2017-05-05 14:40:12 +00:00
|
|
|
|
Path profileLink = getHome() + "/.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);
|
2012-12-03 17:19:49 +00:00
|
|
|
|
|
2004-02-08 14:07:43 +00:00
|
|
|
|
int curGen;
|
|
|
|
|
Generations gens = findGenerations(globals.profile, curGen);
|
|
|
|
|
|
|
|
|
|
Generation dst;
|
2015-07-17 17:24:28 +00:00
|
|
|
|
for (auto & i : gens)
|
|
|
|
|
if ((dstGen == prevGen && i.number < curGen) ||
|
|
|
|
|
(dstGen >= 0 && i.number == dstGen))
|
|
|
|
|
dst = i;
|
2004-02-08 14:07:43 +00:00
|
|
|
|
|
2009-06-30 15:53:39 +00:00
|
|
|
|
if (!dst) {
|
2004-02-08 14:07:43 +00:00
|
|
|
|
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);
|
2009-06-30 15:53:39 +00:00
|
|
|
|
}
|
2004-02-08 14:07:43 +00:00
|
|
|
|
|
2016-09-21 14:11:01 +00:00
|
|
|
|
printInfo(format("switching from generation %1% to %2%")
|
2004-02-10 13:42:58 +00:00
|
|
|
|
% curGen % dst.number);
|
2012-12-03 17:19:49 +00:00
|
|
|
|
|
2004-02-10 13:42:58 +00:00
|
|
|
|
if (globals.dryRun) return;
|
2012-12-03 17:19:49 +00:00
|
|
|
|
|
2004-02-08 14:07:43 +00:00
|
|
|
|
switchLink(globals.profile, dst.path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-08-13 01:50:44 +00:00
|
|
|
|
static void opSwitchGeneration(Globals & globals, Strings opFlags, Strings opArgs)
|
2004-02-08 14:07:43 +00:00
|
|
|
|
{
|
|
|
|
|
if (opFlags.size() > 0)
|
2017-07-30 11:27:57 +00:00
|
|
|
|
throw UsageError(format("unknown flag '%1%'") % opFlags.front());
|
2004-02-08 14:07:43 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-08-13 01:50:44 +00:00
|
|
|
|
static void opRollback(Globals & globals, Strings opFlags, Strings opArgs)
|
2004-02-08 14:07:43 +00:00
|
|
|
|
{
|
|
|
|
|
if (opFlags.size() > 0)
|
2017-07-30 11:27:57 +00:00
|
|
|
|
throw UsageError(format("unknown flag '%1%'") % opFlags.front());
|
2004-02-08 14:07:43 +00:00
|
|
|
|
if (opArgs.size() != 0)
|
|
|
|
|
throw UsageError(format("no arguments expected"));
|
|
|
|
|
|
|
|
|
|
switchGeneration(globals, prevGen);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-08-13 01:50:44 +00:00
|
|
|
|
static void opListGenerations(Globals & globals, Strings opFlags, Strings opArgs)
|
2004-02-06 16:03:27 +00:00
|
|
|
|
{
|
|
|
|
|
if (opFlags.size() > 0)
|
2017-07-30 11:27:57 +00:00
|
|
|
|
throw UsageError(format("unknown flag '%1%'") % opFlags.front());
|
2004-02-06 16:03:27 +00:00
|
|
|
|
if (opArgs.size() != 0)
|
|
|
|
|
throw UsageError(format("no arguments expected"));
|
|
|
|
|
|
2006-09-14 22:33:53 +00:00
|
|
|
|
PathLocks lock;
|
|
|
|
|
lockProfile(lock, globals.profile);
|
2012-12-03 17:19:49 +00:00
|
|
|
|
|
2004-02-06 16:16:55 +00:00
|
|
|
|
int curGen;
|
|
|
|
|
Generations gens = findGenerations(globals.profile, curGen);
|
2004-02-06 16:03:27 +00:00
|
|
|
|
|
2014-08-20 19:26:37 +00:00
|
|
|
|
RunPager pager;
|
|
|
|
|
|
2015-07-17 17:24:28 +00:00
|
|
|
|
for (auto & i : gens) {
|
2004-02-06 16:03:27 +00:00
|
|
|
|
tm t;
|
2015-07-17 17:24:28 +00:00
|
|
|
|
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")
|
2015-07-17 17:24:28 +00:00
|
|
|
|
% i.number
|
2004-02-06 16:03:27 +00:00
|
|
|
|
% (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
|
2015-07-17 17:24:28 +00:00
|
|
|
|
% (i.number == curGen ? "(current)" : "");
|
2004-02-06 16:03:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-08-13 01:50:44 +00:00
|
|
|
|
static void opDeleteGenerations(Globals & globals, Strings opFlags, Strings opArgs)
|
2004-09-10 13:32:08 +00:00
|
|
|
|
{
|
|
|
|
|
if (opFlags.size() > 0)
|
2017-07-30 11:27:57 +00:00
|
|
|
|
throw UsageError(format("unknown flag '%1%'") % opFlags.front());
|
2004-09-10 13:32:08 +00:00
|
|
|
|
|
2015-05-21 14:26:03 +00:00
|
|
|
|
if (opArgs.size() == 1 && opArgs.front() == "old") {
|
|
|
|
|
deleteOldGenerations(globals.profile, globals.dryRun);
|
|
|
|
|
} else if (opArgs.size() == 1 && opArgs.front().find('d') != string::npos) {
|
|
|
|
|
deleteGenerationsOlderThan(globals.profile, opArgs.front(), globals.dryRun);
|
2016-01-07 01:15:19 +00:00
|
|
|
|
} else if (opArgs.size() == 1 && opArgs.front().find('+') != string::npos) {
|
2016-05-19 19:42:54 +00:00
|
|
|
|
if(opArgs.front().size() < 2)
|
|
|
|
|
throw Error(format("invalid number of generations ‘%1%’") % opArgs.front());
|
2017-09-22 01:41:19 +00:00
|
|
|
|
string str_max = string(opArgs.front(), 1, opArgs.front().size());
|
2016-05-19 19:42:54 +00:00
|
|
|
|
int max;
|
|
|
|
|
if (!string2Int(str_max, max) || max == 0)
|
|
|
|
|
throw Error(format("invalid number of generations to keep ‘%1%’") % opArgs.front());
|
|
|
|
|
deleteGenerationsGreaterThan(globals.profile, max, globals.dryRun);
|
2015-05-21 14:26:03 +00:00
|
|
|
|
} else {
|
|
|
|
|
std::set<unsigned int> gens;
|
|
|
|
|
for (auto & i : opArgs) {
|
|
|
|
|
unsigned int n;
|
2015-09-17 23:22:06 +00:00
|
|
|
|
if (!string2Int(i, n))
|
2017-07-30 11:27:57 +00:00
|
|
|
|
throw UsageError(format("invalid generation number '%1%'") % i);
|
2015-05-21 14:26:03 +00:00
|
|
|
|
gens.insert(n);
|
2004-09-10 13:32:08 +00:00
|
|
|
|
}
|
2015-05-21 14:26:03 +00:00
|
|
|
|
deleteGenerations(globals.profile, gens, globals.dryRun);
|
2004-09-10 13:32:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-07-23 12:19:49 +00:00
|
|
|
|
static void opVersion(Globals & globals, Strings opFlags, Strings opArgs)
|
|
|
|
|
{
|
|
|
|
|
printVersion("nix-env");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2018-10-26 09:35:46 +00:00
|
|
|
|
static int _main(int argc, char * * argv)
|
2003-11-19 17:27:16 +00:00
|
|
|
|
{
|
2018-10-26 09:35:46 +00:00
|
|
|
|
{
|
2017-10-24 10:45:11 +00:00
|
|
|
|
Strings opFlags, opArgs;
|
2014-08-13 01:50:44 +00:00
|
|
|
|
Operation op = 0;
|
2017-06-28 16:11:01 +00:00
|
|
|
|
RepairFlag repair = NoRepair;
|
2014-08-13 01:50:44 +00:00
|
|
|
|
string file;
|
|
|
|
|
|
|
|
|
|
Globals globals;
|
|
|
|
|
|
|
|
|
|
globals.instSource.type = srcUnknown;
|
2019-10-09 17:50:46 +00:00
|
|
|
|
globals.instSource.nixExprPath = getHome() + "/.nix-defexpr";
|
2014-08-13 01:50:44 +00:00
|
|
|
|
globals.instSource.systemFilter = "*";
|
|
|
|
|
|
2019-10-09 17:50:46 +00:00
|
|
|
|
if (!pathExists(globals.instSource.nixExprPath)) {
|
2019-10-10 07:14:05 +00:00
|
|
|
|
try {
|
|
|
|
|
createDirs(globals.instSource.nixExprPath);
|
2019-10-09 17:50:46 +00:00
|
|
|
|
replaceSymlink(
|
2019-10-10 07:14:05 +00:00
|
|
|
|
fmt("%s/profiles/per-user/%s/channels", settings.nixStateDir, getUserName()),
|
|
|
|
|
globals.instSource.nixExprPath + "/channels");
|
|
|
|
|
if (getuid() != 0)
|
|
|
|
|
replaceSymlink(
|
|
|
|
|
fmt("%s/profiles/per-user/root/channels", settings.nixStateDir),
|
|
|
|
|
globals.instSource.nixExprPath + "/channels_root");
|
|
|
|
|
} catch (Error &) { }
|
2019-10-09 17:50:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-13 01:50:44 +00:00
|
|
|
|
globals.dryRun = false;
|
|
|
|
|
globals.preserveInstalled = false;
|
|
|
|
|
globals.removeAll = false;
|
|
|
|
|
globals.prebuiltOnly = false;
|
|
|
|
|
|
2017-10-24 10:45:11 +00:00
|
|
|
|
struct MyArgs : LegacyArgs, MixEvalArgs
|
|
|
|
|
{
|
|
|
|
|
using LegacyArgs::LegacyArgs;
|
|
|
|
|
};
|
|
|
|
|
|
2019-12-05 18:11:09 +00:00
|
|
|
|
MyArgs myArgs(std::string(baseNameOf(argv[0])), [&](Strings::iterator & arg, const Strings::iterator & end) {
|
2014-08-13 01:50:44 +00:00
|
|
|
|
Operation oldOp = op;
|
|
|
|
|
|
|
|
|
|
if (*arg == "--help")
|
|
|
|
|
showManPage("nix-env");
|
|
|
|
|
else if (*arg == "--version")
|
2015-07-23 12:19:49 +00:00
|
|
|
|
op = opVersion;
|
2014-08-13 01:50:44 +00:00
|
|
|
|
else if (*arg == "--install" || *arg == "-i")
|
|
|
|
|
op = opInstall;
|
|
|
|
|
else if (*arg == "--force-name") // undocumented flag for nix-install-package
|
|
|
|
|
globals.forceName = getArg(*arg, arg, end);
|
|
|
|
|
else if (*arg == "--uninstall" || *arg == "-e")
|
|
|
|
|
op = opUninstall;
|
|
|
|
|
else if (*arg == "--upgrade" || *arg == "-u")
|
|
|
|
|
op = opUpgrade;
|
|
|
|
|
else if (*arg == "--set-flag")
|
|
|
|
|
op = opSetFlag;
|
|
|
|
|
else if (*arg == "--set")
|
|
|
|
|
op = opSet;
|
|
|
|
|
else if (*arg == "--query" || *arg == "-q")
|
|
|
|
|
op = opQuery;
|
|
|
|
|
else if (*arg == "--profile" || *arg == "-p")
|
|
|
|
|
globals.profile = absPath(getArg(*arg, arg, end));
|
|
|
|
|
else if (*arg == "--file" || *arg == "-f")
|
|
|
|
|
file = getArg(*arg, arg, end);
|
|
|
|
|
else if (*arg == "--switch-profile" || *arg == "-S")
|
|
|
|
|
op = opSwitchProfile;
|
|
|
|
|
else if (*arg == "--switch-generation" || *arg == "-G")
|
|
|
|
|
op = opSwitchGeneration;
|
|
|
|
|
else if (*arg == "--rollback")
|
|
|
|
|
op = opRollback;
|
|
|
|
|
else if (*arg == "--list-generations")
|
|
|
|
|
op = opListGenerations;
|
|
|
|
|
else if (*arg == "--delete-generations")
|
|
|
|
|
op = opDeleteGenerations;
|
|
|
|
|
else if (*arg == "--dry-run") {
|
2016-09-21 14:11:01 +00:00
|
|
|
|
printInfo("(dry run; not doing anything)");
|
2014-08-13 01:50:44 +00:00
|
|
|
|
globals.dryRun = true;
|
|
|
|
|
}
|
|
|
|
|
else if (*arg == "--system-filter")
|
|
|
|
|
globals.instSource.systemFilter = getArg(*arg, arg, end);
|
|
|
|
|
else if (*arg == "--prebuilt-only" || *arg == "-b")
|
|
|
|
|
globals.prebuiltOnly = true;
|
|
|
|
|
else if (*arg == "--repair")
|
2017-06-28 16:11:01 +00:00
|
|
|
|
repair = Repair;
|
2014-08-13 01:50:44 +00:00
|
|
|
|
else if (*arg != "" && arg->at(0) == '-') {
|
|
|
|
|
opFlags.push_back(*arg);
|
2014-08-18 13:48:23 +00:00
|
|
|
|
/* FIXME: hacky */
|
|
|
|
|
if (*arg == "--from-profile" ||
|
|
|
|
|
(op == opQuery && (*arg == "--attr" || *arg == "-A")))
|
2014-08-13 01:50:44 +00:00
|
|
|
|
opFlags.push_back(getArg(*arg, arg, end));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
opArgs.push_back(*arg);
|
2012-12-03 17:19:49 +00:00
|
|
|
|
|
2014-08-13 01:50:44 +00:00
|
|
|
|
if (oldOp && oldOp != op)
|
|
|
|
|
throw UsageError("only one operation may be specified");
|
2012-12-03 17:19:49 +00:00
|
|
|
|
|
2014-08-13 01:50:44 +00:00
|
|
|
|
return true;
|
|
|
|
|
});
|
2003-11-19 17:27:16 +00:00
|
|
|
|
|
2017-10-24 10:45:11 +00:00
|
|
|
|
myArgs.parseCmdline(argvToStrings(argc, argv));
|
|
|
|
|
|
2018-02-08 16:26:18 +00:00
|
|
|
|
initPlugins();
|
|
|
|
|
|
2014-08-13 01:50:44 +00:00
|
|
|
|
if (!op) throw UsageError("no operation specified");
|
2003-11-19 17:27:16 +00:00
|
|
|
|
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 13:28:26 +00:00
|
|
|
|
auto store = openStore();
|
2015-05-05 15:09:42 +00:00
|
|
|
|
|
2017-10-24 10:45:11 +00:00
|
|
|
|
globals.state = std::shared_ptr<EvalState>(new EvalState(myArgs.searchPath, store));
|
2014-08-13 01:50:44 +00:00
|
|
|
|
globals.state->repair = repair;
|
2003-11-19 17:27:16 +00:00
|
|
|
|
|
2014-08-13 01:50:44 +00:00
|
|
|
|
if (file != "")
|
|
|
|
|
globals.instSource.nixExprPath = lookupFileArg(*globals.state, file);
|
2003-11-19 17:27:16 +00:00
|
|
|
|
|
2017-10-24 10:45:11 +00:00
|
|
|
|
globals.instSource.autoArgs = myArgs.getAutoArgs(*globals.state);
|
2003-11-19 17:27:16 +00:00
|
|
|
|
|
2014-08-13 01:50:44 +00:00
|
|
|
|
if (globals.profile == "")
|
2019-11-22 15:06:44 +00:00
|
|
|
|
globals.profile = getEnv("NIX_PROFILE").value_or("");
|
2012-12-12 15:01:46 +00:00
|
|
|
|
|
2014-08-13 01:50:44 +00:00
|
|
|
|
if (globals.profile == "") {
|
2017-05-05 14:40:12 +00:00
|
|
|
|
Path profileLink = getHome() + "/.nix-profile";
|
2019-10-10 07:14:05 +00:00
|
|
|
|
try {
|
|
|
|
|
if (!pathExists(profileLink)) {
|
|
|
|
|
replaceSymlink(
|
|
|
|
|
getuid() == 0
|
|
|
|
|
? settings.nixStateDir + "/profiles/default"
|
|
|
|
|
: fmt("%s/profiles/per-user/%s/profile", settings.nixStateDir, getUserName()),
|
|
|
|
|
profileLink);
|
|
|
|
|
}
|
|
|
|
|
globals.profile = absPath(readLink(profileLink), dirOf(profileLink));
|
|
|
|
|
} catch (Error &) {
|
|
|
|
|
globals.profile = profileLink;
|
2019-10-09 17:21:07 +00:00
|
|
|
|
}
|
2014-08-13 01:50:44 +00:00
|
|
|
|
}
|
2012-12-03 17:19:49 +00:00
|
|
|
|
|
2014-08-13 01:50:44 +00:00
|
|
|
|
op(globals, opFlags, opArgs);
|
2003-11-19 17:27:16 +00:00
|
|
|
|
|
2014-08-13 01:50:44 +00:00
|
|
|
|
globals.state->printStats();
|
2018-10-26 09:35:46 +00:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2003-11-19 17:27:16 +00:00
|
|
|
|
}
|
2018-10-26 09:35:46 +00:00
|
|
|
|
|
|
|
|
|
static RegisterLegacyCommand s1("nix-env", _main);
|