2016-02-09 20:34:24 +00:00
|
|
|
#include "attr-path.hh"
|
|
|
|
#include "common-opts.hh"
|
|
|
|
#include "derivations.hh"
|
|
|
|
#include "eval-inline.hh"
|
|
|
|
#include "eval.hh"
|
|
|
|
#include "get-drvs.hh"
|
|
|
|
#include "installables.hh"
|
|
|
|
#include "store-api.hh"
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
2016-08-23 15:11:19 +00:00
|
|
|
Value * MixInstallables::buildSourceExpr(EvalState & state)
|
|
|
|
{
|
|
|
|
Value * vRoot = state.allocValue();
|
|
|
|
|
|
|
|
if (file != "") {
|
|
|
|
Expr * e = state.parseExprFromFile(resolveExprPath(lookupFileArg(state, file)));
|
|
|
|
state.eval(e, *vRoot);
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
/* Construct the installation source from $NIX_PATH. */
|
|
|
|
|
|
|
|
auto searchPath = state.getSearchPath();
|
|
|
|
|
|
|
|
state.mkAttrs(*vRoot, searchPath.size());
|
|
|
|
|
|
|
|
std::unordered_set<std::string> seen;
|
|
|
|
|
|
|
|
for (auto & i : searchPath) {
|
|
|
|
if (i.first == "") continue;
|
|
|
|
if (seen.count(i.first)) continue;
|
|
|
|
seen.insert(i.first);
|
|
|
|
if (!pathExists(i.second)) continue;
|
|
|
|
mkApp(*state.allocAttr(*vRoot, state.symbols.create(i.first)),
|
|
|
|
state.getBuiltin("import"),
|
|
|
|
mkString(*state.allocValue(), i.second));
|
|
|
|
}
|
|
|
|
|
|
|
|
vRoot->attrs->sort();
|
|
|
|
}
|
|
|
|
|
|
|
|
return vRoot;
|
|
|
|
}
|
|
|
|
|
2016-02-09 20:34:24 +00:00
|
|
|
UserEnvElems MixInstallables::evalInstallables(ref<Store> store)
|
|
|
|
{
|
|
|
|
UserEnvElems res;
|
|
|
|
|
|
|
|
for (auto & installable : installables) {
|
|
|
|
|
|
|
|
if (std::string(installable, 0, 1) == "/") {
|
|
|
|
|
2016-06-01 12:49:12 +00:00
|
|
|
if (store->isStorePath(installable)) {
|
2016-02-09 20:34:24 +00:00
|
|
|
|
|
|
|
if (isDerivation(installable)) {
|
|
|
|
UserEnvElem elem;
|
|
|
|
// FIXME: handle empty case, drop version
|
|
|
|
elem.attrPath = {storePathToName(installable)};
|
|
|
|
elem.isDrv = true;
|
|
|
|
elem.drvPath = installable;
|
|
|
|
res.push_back(elem);
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
UserEnvElem elem;
|
|
|
|
// FIXME: handle empty case, drop version
|
|
|
|
elem.attrPath = {storePathToName(installable)};
|
|
|
|
elem.isDrv = false;
|
|
|
|
elem.outPaths = {installable};
|
|
|
|
res.push_back(elem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
2016-11-25 14:48:27 +00:00
|
|
|
throw UsageError(format("don't know what to do with '%1%'") % installable);
|
2016-02-09 20:34:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
EvalState state({}, store);
|
|
|
|
|
2016-08-23 15:11:19 +00:00
|
|
|
auto vRoot = buildSourceExpr(state);
|
2016-02-09 20:34:24 +00:00
|
|
|
|
|
|
|
std::map<string, string> autoArgs_;
|
|
|
|
Bindings & autoArgs(*evalAutoArgs(state, autoArgs_));
|
|
|
|
|
2016-08-23 15:11:19 +00:00
|
|
|
Value & v(*findAlongAttrPath(state, installable, autoArgs, *vRoot));
|
2016-02-09 20:34:24 +00:00
|
|
|
state.forceValue(v);
|
|
|
|
|
|
|
|
DrvInfos drvs;
|
|
|
|
getDerivations(state, v, "", autoArgs, drvs, false);
|
|
|
|
|
|
|
|
for (auto & i : drvs) {
|
|
|
|
UserEnvElem elem;
|
|
|
|
elem.isDrv = true;
|
|
|
|
elem.drvPath = i.queryDrvPath();
|
|
|
|
res.push_back(elem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|