aboutsummaryrefslogtreecommitdiff
path: root/src/nix/app.cc
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2020-07-16 14:58:53 +0000
committerJohn Ericson <John.Ericson@Obsidian.Systems>2020-07-16 14:58:53 +0000
commit5ea817dace2b554e602d7f9df6e43084ad112e3d (patch)
tree409213f4980018df204fe45afaf115f420a72907 /src/nix/app.cc
parentd0905623488ca97feeb28ebd9817af6270a53c48 (diff)
parent8807ff902e1b543410a9572cc146efa6c90dec87 (diff)
Merge remote-tracking branch 'upstream/master' into hash-always-has-type
Diffstat (limited to 'src/nix/app.cc')
-rw-r--r--src/nix/app.cc46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/nix/app.cc b/src/nix/app.cc
new file mode 100644
index 000000000..3935297cf
--- /dev/null
+++ b/src/nix/app.cc
@@ -0,0 +1,46 @@
+#include "installables.hh"
+#include "store-api.hh"
+#include "eval-inline.hh"
+#include "eval-cache.hh"
+#include "names.hh"
+
+namespace nix {
+
+App Installable::toApp(EvalState & state)
+{
+ auto [cursor, attrPath] = getCursor(state, true);
+
+ auto type = cursor->getAttr("type")->getString();
+
+ if (type == "app") {
+ auto [program, context] = cursor->getAttr("program")->getStringWithContext();
+
+ if (!state.store->isInStore(program))
+ throw Error("app program '%s' is not in the Nix store", program);
+
+ 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);
+}
+
+}