aboutsummaryrefslogtreecommitdiff
path: root/src/nix/app.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/nix/app.cc')
-rw-r--r--src/nix/app.cc46
1 files changed, 32 insertions, 14 deletions
diff --git a/src/nix/app.cc b/src/nix/app.cc
index 749dea02b..3935297cf 100644
--- a/src/nix/app.cc
+++ b/src/nix/app.cc
@@ -1,28 +1,46 @@
#include "installables.hh"
#include "store-api.hh"
#include "eval-inline.hh"
+#include "eval-cache.hh"
+#include "names.hh"
namespace nix {
-App::App(EvalState & state, Value & vApp)
+App Installable::toApp(EvalState & state)
{
- state.forceAttrs(vApp);
+ auto [cursor, attrPath] = getCursor(state, true);
- auto aType = vApp.attrs->need(state.sType);
- if (state.forceStringNoCtx(*aType.value, *aType.pos) != "app")
- throw Error("value does not have type 'app', at %s", *aType.pos);
+ auto type = cursor->getAttr("type")->getString();
- auto aProgram = vApp.attrs->need(state.symbols.create("program"));
- program = state.forceString(*aProgram.value, context, *aProgram.pos);
+ if (type == "app") {
+ auto [program, context] = cursor->getAttr("program")->getStringWithContext();
- // FIXME: check that 'program' is in the closure of 'context'.
- if (!state.store->isInStore(program))
- throw Error("app program '%s' is not in the Nix store", program);
-}
+ if (!state.store->isInStore(program))
+ throw Error("app program '%s' is not in the Nix store", program);
-App Installable::toApp(EvalState & state)
-{
- return App(state, *toValue(state).first);
+ 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();
+ return App {
+ .context = { { drvPath, {outputName} } },
+ .program = outPath + "/bin/" + DrvName(name).name,
+ };
+ }
+
+ else
+ throw Error("attribute '%s' has unsupported type '%s'", attrPath, type);
}
}