2009-03-05 14:59:43 +00:00
|
|
|
|
#include <map>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
2018-08-10 18:25:43 +00:00
|
|
|
|
#define GC_LINUX_THREADS 1
|
2011-01-14 12:53:54 +00:00
|
|
|
|
#include <gc/gc_allocator.h>
|
|
|
|
|
|
2009-03-05 14:59:43 +00:00
|
|
|
|
#include "shared.hh"
|
|
|
|
|
#include "store-api.hh"
|
|
|
|
|
#include "eval.hh"
|
2012-10-04 19:24:25 +00:00
|
|
|
|
#include "eval-inline.hh"
|
2009-03-05 15:41:43 +00:00
|
|
|
|
#include "util.hh"
|
2016-10-06 13:05:05 +00:00
|
|
|
|
#include "json.hh"
|
2009-03-06 15:16:29 +00:00
|
|
|
|
#include "get-drvs.hh"
|
2014-09-12 12:30:01 +00:00
|
|
|
|
#include "globals.hh"
|
2017-10-26 11:10:14 +00:00
|
|
|
|
#include "common-eval-args.hh"
|
2019-05-10 20:18:37 +00:00
|
|
|
|
#include "flakeref.hh"
|
|
|
|
|
#include "flake.hh"
|
2009-03-05 14:59:43 +00:00
|
|
|
|
|
2018-05-16 12:14:53 +00:00
|
|
|
|
#include "hydra-config.hh"
|
|
|
|
|
|
2018-06-05 10:18:55 +00:00
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <sys/wait.h>
|
|
|
|
|
|
2009-03-05 14:59:43 +00:00
|
|
|
|
using namespace nix;
|
|
|
|
|
|
|
|
|
|
|
2009-03-15 11:56:11 +00:00
|
|
|
|
static Path gcRootsDir;
|
|
|
|
|
|
|
|
|
|
|
2014-09-29 22:20:54 +00:00
|
|
|
|
static void findJobs(EvalState & state, JSONObject & top,
|
2017-10-26 11:10:14 +00:00
|
|
|
|
Bindings & autoArgs, Value & v, const string & attrPath);
|
2009-03-06 16:55:19 +00:00
|
|
|
|
|
2009-03-07 14:06:10 +00:00
|
|
|
|
|
2018-12-29 13:47:03 +00:00
|
|
|
|
static string queryMetaStrings(EvalState & state, DrvInfo & drv, const string & name, const string & subAttribute)
|
2009-07-07 13:20:00 +00:00
|
|
|
|
{
|
2015-10-08 09:56:30 +00:00
|
|
|
|
Strings res;
|
|
|
|
|
std::function<void(Value & v)> rec;
|
|
|
|
|
|
|
|
|
|
rec = [&](Value & v) {
|
|
|
|
|
state.forceValue(v);
|
|
|
|
|
if (v.type == tString)
|
|
|
|
|
res.push_back(v.string.s);
|
|
|
|
|
else if (v.isList())
|
|
|
|
|
for (unsigned int n = 0; n < v.listSize(); ++n)
|
|
|
|
|
rec(*v.listElems()[n]);
|
|
|
|
|
else if (v.type == tAttrs) {
|
2018-12-29 13:47:03 +00:00
|
|
|
|
auto a = v.attrs->find(state.symbols.create(subAttribute));
|
2015-10-08 09:56:30 +00:00
|
|
|
|
if (a != v.attrs->end())
|
|
|
|
|
res.push_back(state.forceString(*a->value));
|
2013-11-04 21:50:32 +00:00
|
|
|
|
}
|
2015-10-08 09:56:30 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Value * v = drv.queryMeta(name);
|
|
|
|
|
if (v) rec(*v);
|
|
|
|
|
|
|
|
|
|
return concatStringsSep(", ", res);
|
2013-11-04 21:50:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-09-29 22:20:54 +00:00
|
|
|
|
static void findJobsWrapped(EvalState & state, JSONObject & top,
|
2017-10-26 11:10:14 +00:00
|
|
|
|
Bindings & autoArgs, Value & vIn, const string & attrPath)
|
2009-03-05 15:41:43 +00:00
|
|
|
|
{
|
2009-03-06 16:55:19 +00:00
|
|
|
|
debug(format("at path `%1%'") % attrPath);
|
2010-11-19 11:01:31 +00:00
|
|
|
|
|
2012-10-04 18:31:47 +00:00
|
|
|
|
checkInterrupt();
|
|
|
|
|
|
2017-10-26 11:10:14 +00:00
|
|
|
|
Value v;
|
|
|
|
|
state.autoCallFunction(autoArgs, vIn, v);
|
2009-03-05 15:41:43 +00:00
|
|
|
|
|
2010-05-18 09:57:37 +00:00
|
|
|
|
if (v.type == tAttrs) {
|
2009-03-05 15:41:43 +00:00
|
|
|
|
|
2017-07-21 11:09:08 +00:00
|
|
|
|
auto drv = getDerivation(state, v, false);
|
2013-01-22 13:41:02 +00:00
|
|
|
|
|
2017-07-21 11:09:08 +00:00
|
|
|
|
if (drv) {
|
2009-03-15 11:56:11 +00:00
|
|
|
|
Path drvPath;
|
2009-03-05 15:41:43 +00:00
|
|
|
|
|
2017-07-21 11:09:08 +00:00
|
|
|
|
DrvInfo::Outputs outputs = drv->queryOutputs();
|
2013-02-13 16:49:28 +00:00
|
|
|
|
|
2017-07-21 11:09:08 +00:00
|
|
|
|
if (drv->querySystem() == "unknown")
|
2014-09-22 14:53:40 +00:00
|
|
|
|
throw EvalError("derivation must have a ‘system’ attribute");
|
|
|
|
|
|
2015-03-18 21:03:55 +00:00
|
|
|
|
{
|
2016-10-06 13:05:05 +00:00
|
|
|
|
auto res = top.object(attrPath);
|
2017-07-21 11:09:08 +00:00
|
|
|
|
res.attr("nixName", drv->queryName());
|
|
|
|
|
res.attr("system", drv->querySystem());
|
|
|
|
|
res.attr("drvPath", drvPath = drv->queryDrvPath());
|
|
|
|
|
res.attr("description", drv->queryMetaString("description"));
|
2018-12-29 13:47:03 +00:00
|
|
|
|
res.attr("license", queryMetaStrings(state, *drv, "license", "shortName"));
|
2017-07-21 11:09:08 +00:00
|
|
|
|
res.attr("homepage", drv->queryMetaString("homepage"));
|
2018-12-29 13:47:03 +00:00
|
|
|
|
res.attr("maintainers", queryMetaStrings(state, *drv, "maintainers", "email"));
|
2017-07-21 11:09:08 +00:00
|
|
|
|
res.attr("schedulingPriority", drv->queryMetaInt("schedulingPriority", 100));
|
|
|
|
|
res.attr("timeout", drv->queryMetaInt("timeout", 36000));
|
|
|
|
|
res.attr("maxSilent", drv->queryMetaInt("maxSilent", 7200));
|
|
|
|
|
res.attr("isChannel", drv->queryMetaBool("isHydraChannel", false));
|
2010-05-26 08:03:59 +00:00
|
|
|
|
|
2013-08-15 00:33:10 +00:00
|
|
|
|
/* If this is an aggregate, then get its constituents. */
|
2013-08-13 23:59:29 +00:00
|
|
|
|
Bindings::iterator a = v.attrs->find(state.symbols.create("_hydraAggregate"));
|
2016-10-06 13:05:05 +00:00
|
|
|
|
if (a != v.attrs->end() && state.forceBool(*a->value, *a->pos)) {
|
2013-08-15 00:33:10 +00:00
|
|
|
|
Bindings::iterator a = v.attrs->find(state.symbols.create("constituents"));
|
2013-08-13 23:59:29 +00:00
|
|
|
|
if (a == v.attrs->end())
|
2013-08-15 00:33:10 +00:00
|
|
|
|
throw EvalError("derivation must have a ‘constituents’ attribute");
|
2013-08-13 23:59:29 +00:00
|
|
|
|
PathSet context;
|
2014-04-08 15:08:09 +00:00
|
|
|
|
state.coerceToString(*a->pos, *a->value, context, true, false);
|
2013-08-13 23:59:29 +00:00
|
|
|
|
PathSet drvs;
|
2015-07-30 23:45:16 +00:00
|
|
|
|
for (auto & i : context)
|
|
|
|
|
if (i.at(0) == '!') {
|
|
|
|
|
size_t index = i.find("!", 1);
|
|
|
|
|
drvs.insert(string(i, index + 1));
|
2013-08-13 23:59:29 +00:00
|
|
|
|
}
|
2014-09-29 22:20:54 +00:00
|
|
|
|
res.attr("constituents", concatStringsSep(" ", drvs));
|
2013-08-13 23:59:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-03-15 11:56:11 +00:00
|
|
|
|
/* Register the derivation as a GC root. !!! This
|
|
|
|
|
registers roots for jobs that we may have already
|
|
|
|
|
done. */
|
2016-10-06 13:05:05 +00:00
|
|
|
|
auto localStore = state.store.dynamic_pointer_cast<LocalFSStore>();
|
|
|
|
|
if (gcRootsDir != "" && localStore) {
|
2010-06-01 11:20:05 +00:00
|
|
|
|
Path root = gcRootsDir + "/" + baseNameOf(drvPath);
|
2016-10-06 13:05:05 +00:00
|
|
|
|
if (!pathExists(root)) localStore->addPermRoot(drvPath, root, false);
|
2010-06-01 11:20:05 +00:00
|
|
|
|
}
|
2013-01-22 13:41:02 +00:00
|
|
|
|
|
2016-10-06 13:05:05 +00:00
|
|
|
|
auto res2 = res.object("outputs");
|
2014-09-29 22:20:54 +00:00
|
|
|
|
for (auto & j : outputs)
|
|
|
|
|
res2.attr(j.first, j.second);
|
2015-03-18 21:03:55 +00:00
|
|
|
|
|
|
|
|
|
}
|
2009-03-05 15:41:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else {
|
2012-10-04 18:31:47 +00:00
|
|
|
|
if (!state.isDerivation(v)) {
|
2018-06-05 10:18:55 +00:00
|
|
|
|
for (auto & i : v.attrs->lexicographicOrder()) {
|
|
|
|
|
std::string name(i->name);
|
|
|
|
|
|
|
|
|
|
/* Skip jobs with dots in the name. */
|
|
|
|
|
if (name.find('.') != std::string::npos) {
|
|
|
|
|
printError("skipping job with illegal name '%s'", name);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
findJobs(state, top, autoArgs, *i->value,
|
|
|
|
|
(attrPath.empty() ? "" : attrPath + ".") + name);
|
|
|
|
|
}
|
2012-10-04 18:31:47 +00:00
|
|
|
|
}
|
2009-03-05 15:41:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-16 10:14:22 +00:00
|
|
|
|
else if (v.type == tNull) {
|
2012-02-16 10:03:22 +00:00
|
|
|
|
// allow null values, meaning 'do nothing'
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-06 16:55:19 +00:00
|
|
|
|
else
|
2010-05-18 09:57:37 +00:00
|
|
|
|
throw TypeError(format("unsupported value: %1%") % v);
|
2009-03-07 14:06:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-09-29 22:20:54 +00:00
|
|
|
|
static void findJobs(EvalState & state, JSONObject & top,
|
2017-10-26 11:10:14 +00:00
|
|
|
|
Bindings & autoArgs, Value & v, const string & attrPath)
|
2009-03-07 14:06:10 +00:00
|
|
|
|
{
|
|
|
|
|
try {
|
2017-10-26 11:10:14 +00:00
|
|
|
|
findJobsWrapped(state, top, autoArgs, v, attrPath);
|
2009-10-08 12:29:20 +00:00
|
|
|
|
} catch (EvalError & e) {
|
2016-10-06 13:05:05 +00:00
|
|
|
|
auto res = top.object(attrPath);
|
2018-08-01 15:06:32 +00:00
|
|
|
|
res.attr("error", filterANSIEscapes(e.msg(), true));
|
2009-03-07 14:06:10 +00:00
|
|
|
|
}
|
2009-03-05 15:41:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-08-13 14:24:26 +00:00
|
|
|
|
int main(int argc, char * * argv)
|
2009-03-05 14:59:43 +00:00
|
|
|
|
{
|
2012-05-23 18:44:10 +00:00
|
|
|
|
/* Prevent undeclared dependencies in the evaluation via
|
|
|
|
|
$NIX_PATH. */
|
|
|
|
|
unsetenv("NIX_PATH");
|
2013-01-22 13:41:02 +00:00
|
|
|
|
|
2014-08-13 14:24:26 +00:00
|
|
|
|
return handleExceptions(argv[0], [&]() {
|
2018-05-16 12:14:53 +00:00
|
|
|
|
|
|
|
|
|
auto config = std::make_unique<::Config>();
|
|
|
|
|
|
|
|
|
|
auto initialHeapSize = config->getStrOption("evaluator_initial_heap_size", "");
|
|
|
|
|
if (initialHeapSize != "")
|
|
|
|
|
setenv("GC_INITIAL_HEAP_SIZE", initialHeapSize.c_str(), 1);
|
|
|
|
|
|
2014-08-13 14:24:26 +00:00
|
|
|
|
initNix();
|
2015-03-19 19:16:38 +00:00
|
|
|
|
initGC();
|
2014-08-13 14:24:26 +00:00
|
|
|
|
|
2019-05-10 20:05:49 +00:00
|
|
|
|
struct MyArgs : MixEvalArgs, MixCommonArgs
|
2017-10-26 11:10:14 +00:00
|
|
|
|
{
|
2019-05-10 20:05:49 +00:00
|
|
|
|
Path releaseExpr;
|
2019-05-10 20:18:37 +00:00
|
|
|
|
bool flake = false;
|
2017-10-26 11:10:14 +00:00
|
|
|
|
|
2019-05-10 20:05:49 +00:00
|
|
|
|
MyArgs() : MixCommonArgs("hydra-eval-jobs")
|
|
|
|
|
{
|
|
|
|
|
mkFlag()
|
|
|
|
|
.longName("help")
|
|
|
|
|
.description("show usage information")
|
|
|
|
|
.handler([&]() {
|
|
|
|
|
printHelp(programName, std::cout);
|
|
|
|
|
throw Exit();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
mkFlag()
|
|
|
|
|
.longName("gc-roots-dir")
|
|
|
|
|
.description("garbage collector roots directory")
|
|
|
|
|
.labels({"path"})
|
|
|
|
|
.dest(&gcRootsDir);
|
|
|
|
|
|
|
|
|
|
mkFlag()
|
|
|
|
|
.longName("dry-run")
|
|
|
|
|
.description("don't create store derivations")
|
|
|
|
|
.set(&settings.readOnlyMode, true);
|
|
|
|
|
|
2019-05-10 20:18:37 +00:00
|
|
|
|
mkFlag()
|
|
|
|
|
.longName("flake")
|
|
|
|
|
.description("build a flake")
|
|
|
|
|
.set(&flake, true);
|
|
|
|
|
|
2019-05-10 20:05:49 +00:00
|
|
|
|
expectArg("expr", &releaseExpr);
|
|
|
|
|
}
|
|
|
|
|
};
|
2009-03-05 14:59:43 +00:00
|
|
|
|
|
2019-05-10 20:05:49 +00:00
|
|
|
|
MyArgs myArgs;
|
2017-10-26 11:10:14 +00:00
|
|
|
|
myArgs.parseCmdline(argvToStrings(argc, argv));
|
|
|
|
|
|
2018-06-05 10:18:55 +00:00
|
|
|
|
JSONObject json(std::cout, true);
|
|
|
|
|
std::cout.flush();
|
2017-03-20 16:57:05 +00:00
|
|
|
|
|
2019-05-10 19:57:19 +00:00
|
|
|
|
/* FIXME: The build hook in conjunction with import-from-derivation is causing "unexpected EOF" during eval */
|
|
|
|
|
settings.builders = "";
|
2009-03-05 15:41:43 +00:00
|
|
|
|
|
2019-05-10 19:57:19 +00:00
|
|
|
|
/* Prevent access to paths outside of the Nix search path and
|
|
|
|
|
to the environment. */
|
|
|
|
|
evalSettings.restrictEval = true;
|
2009-03-05 14:59:43 +00:00
|
|
|
|
|
2019-05-10 20:18:37 +00:00
|
|
|
|
/* When building a flake, use pure evaluation (no access to
|
|
|
|
|
'getEnv', 'currentSystem' etc. */
|
|
|
|
|
evalSettings.pureEval = myArgs.flake;
|
|
|
|
|
|
2019-05-10 20:05:49 +00:00
|
|
|
|
if (myArgs.releaseExpr == "") throw UsageError("no expression specified");
|
2018-06-05 10:18:55 +00:00
|
|
|
|
|
2019-05-10 19:57:19 +00:00
|
|
|
|
if (gcRootsDir == "") printMsg(lvlError, "warning: `--gc-roots-dir' not specified");
|
2018-06-05 10:18:55 +00:00
|
|
|
|
|
2019-05-10 19:57:19 +00:00
|
|
|
|
EvalState state(myArgs.searchPath, openStore());
|
2018-06-05 10:18:55 +00:00
|
|
|
|
|
2019-05-10 19:57:19 +00:00
|
|
|
|
Bindings & autoArgs = *myArgs.getAutoArgs(state);
|
2018-06-05 10:18:55 +00:00
|
|
|
|
|
2019-05-10 19:57:19 +00:00
|
|
|
|
Value v;
|
2009-03-05 14:59:43 +00:00
|
|
|
|
|
2019-05-10 20:18:37 +00:00
|
|
|
|
if (myArgs.flake) {
|
|
|
|
|
FlakeRef flakeRef(myArgs.releaseExpr);
|
|
|
|
|
auto vFlake = state.allocValue();
|
2019-05-22 12:51:55 +00:00
|
|
|
|
makeFlakeValue(state, flakeRef, AllPure, *vFlake);
|
2019-05-10 20:18:37 +00:00
|
|
|
|
|
|
|
|
|
auto vProvides = (*vFlake->attrs->get(state.symbols.create("provides")))->value;
|
|
|
|
|
state.forceValue(*vProvides);
|
2018-08-07 09:47:53 +00:00
|
|
|
|
|
2019-05-10 20:18:37 +00:00
|
|
|
|
auto aHydraJobs = vProvides->attrs->get(state.symbols.create("hydraJobs"));
|
|
|
|
|
if (!aHydraJobs)
|
|
|
|
|
throw Error("flake '%s' does not provide any Hydra jobs", flakeRef);
|
|
|
|
|
|
|
|
|
|
v = *(*aHydraJobs)->value;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
state.evalFile(lookupFileArg(state, myArgs.releaseExpr), v);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
findJobs(state, json, autoArgs, v, "");
|
2014-08-13 14:24:26 +00:00
|
|
|
|
});
|
|
|
|
|
}
|