2020-06-29 15:14:23 +03:00
|
|
|
#include "installables.hh"
|
|
|
|
#include "store-api.hh"
|
|
|
|
#include "eval-inline.hh"
|
2020-06-29 20:08:50 +03:00
|
|
|
#include "eval-cache.hh"
|
|
|
|
#include "names.hh"
|
2020-06-29 15:14:23 +03:00
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
2020-06-29 20:08:50 +03:00
|
|
|
App Installable::toApp(EvalState & state)
|
2020-06-29 15:14:23 +03:00
|
|
|
{
|
2020-08-07 15:13:24 +03:00
|
|
|
auto [cursor, attrPath] = getCursor(state);
|
2020-06-29 15:14:23 +03:00
|
|
|
|
2020-06-29 20:08:50 +03:00
|
|
|
auto type = cursor->getAttr("type")->getString();
|
2020-06-29 15:14:23 +03:00
|
|
|
|
2021-02-17 18:54:13 +02:00
|
|
|
auto checkProgram = [&](const Path & program)
|
|
|
|
{
|
|
|
|
if (!state.store->isInStore(program))
|
|
|
|
throw Error("app program '%s' is not in the Nix store", program);
|
|
|
|
};
|
|
|
|
|
2020-06-29 20:08:50 +03:00
|
|
|
if (type == "app") {
|
|
|
|
auto [program, context] = cursor->getAttr("program")->getStringWithContext();
|
2020-06-29 15:14:23 +03:00
|
|
|
|
2021-02-17 18:54:13 +02:00
|
|
|
checkProgram(program);
|
2020-06-29 15:14:23 +03:00
|
|
|
|
2020-06-29 20:08:50 +03:00
|
|
|
std::vector<StorePathWithOutputs> context2;
|
|
|
|
for (auto & [path, name] : context)
|
|
|
|
context2.push_back({state.store->parseStorePath(path), {name}});
|
|
|
|
|
|
|
|
return App {
|
|
|
|
.context = std::move(context2),
|
|
|
|
.program = program,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (type == "derivation") {
|
|
|
|
auto drvPath = cursor->forceDerivation();
|
|
|
|
auto outPath = cursor->getAttr(state.sOutPath)->getString();
|
|
|
|
auto outputName = cursor->getAttr(state.sOutputName)->getString();
|
|
|
|
auto name = cursor->getAttr(state.sName)->getString();
|
2021-02-17 18:54:13 +02:00
|
|
|
auto aMeta = cursor->maybeGetAttr("meta");
|
|
|
|
auto aMainProgram = aMeta ? aMeta->maybeGetAttr("mainProgram") : nullptr;
|
|
|
|
auto mainProgram =
|
|
|
|
aMainProgram
|
|
|
|
? aMainProgram->getString()
|
|
|
|
: DrvName(name).name;
|
|
|
|
auto program = outPath + "/bin/" + mainProgram;
|
|
|
|
checkProgram(program);
|
2020-06-29 20:08:50 +03:00
|
|
|
return App {
|
|
|
|
.context = { { drvPath, {outputName} } },
|
2021-02-17 18:54:13 +02:00
|
|
|
.program = program,
|
2020-06-29 20:08:50 +03:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
throw Error("attribute '%s' has unsupported type '%s'", attrPath, type);
|
2020-06-29 15:14:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|