aboutsummaryrefslogtreecommitdiff
path: root/src/nix/app.cc
diff options
context:
space:
mode:
authorregnat <rg@regnat.ovh>2021-05-17 17:49:20 +0200
committerregnat <rg@regnat.ovh>2021-05-17 17:50:41 +0200
commitca96f5219489c1002499bfe2c580fdd458219144 (patch)
treed4b0f564f5a5da65900ab51babf5c85cc328d15e /src/nix/app.cc
parentbd6cf25952a42afabea822141798566e0f0583b3 (diff)
Split the parsing of an `App` and its resolving
That way things (like `nix flake check`) can evaluate the `app` outputs without having to build anything
Diffstat (limited to 'src/nix/app.cc')
-rw-r--r--src/nix/app.cc64
1 files changed, 32 insertions, 32 deletions
diff --git a/src/nix/app.cc b/src/nix/app.cc
index 1e30deb34..bdc64a886 100644
--- a/src/nix/app.cc
+++ b/src/nix/app.cc
@@ -58,33 +58,24 @@ std::string resolveString(Store & store, const std::string & toResolve, const Bu
return rewriteStrings(toResolve, rewrites);
}
-App Installable::toApp(EvalState & state)
+UnresolvedApp Installable::toApp(EvalState & state)
{
auto [cursor, attrPath] = getCursor(state);
auto type = cursor->getAttr("type")->getString();
- auto checkProgram = [&](const Path & program)
- {
- if (!state.store->isInStore(program))
- throw Error("app program '%s' is not in the Nix store", program);
- };
+ if (type == "app") {
+ auto [program, context] = cursor->getAttr("program")->getStringWithContext();
- std::vector<std::shared_ptr<Installable>> context;
- std::string unresolvedProgram;
+ std::vector<StorePathWithOutputs> context2;
+ for (auto & [path, name] : context)
+ context2.push_back({state.store->parseStorePath(path), {name}});
- if (type == "app") {
- auto [program, context_] = cursor->getAttr("program")->getStringWithContext();
- unresolvedProgram = program;
-
- for (auto & [path, name] : context_)
- context.push_back(std::make_shared<InstallableDerivedPath>(
- state.store,
- DerivedPathBuilt{
- .drvPath = state.store->parseStorePath(path),
- .outputs = {name},
- }));
+ return UnresolvedApp{App {
+ .context = std::move(context2),
+ .program = program,
+ }};
}
else if (type == "derivation") {
@@ -98,24 +89,33 @@ App Installable::toApp(EvalState & state)
aMainProgram
? aMainProgram->getString()
: DrvName(name).name;
- unresolvedProgram = outPath + "/bin/" + mainProgram;
- context = {std::make_shared<InstallableDerivedPath>(
- state.store,
- DerivedPathBuilt{
- .drvPath = drvPath,
- .outputs = {outputName},
- })};
+ auto program = outPath + "/bin/" + mainProgram;
+ return UnresolvedApp { App {
+ .context = { { drvPath, {outputName} } },
+ .program = program,
+ }};
}
else
throw Error("attribute '%s' has unsupported type '%s'", attrPath, type);
+}
+
+App UnresolvedApp::resolve(ref<Store> store)
+{
+ auto res = unresolved;
+
+ std::vector<std::shared_ptr<Installable>> installableContext;
+
+ for (auto & ctxElt : unresolved.context)
+ installableContext.push_back(
+ std::make_shared<InstallableDerivedPath>(store, ctxElt.toDerivedPath()));
- auto builtContext = build(state.store, Realise::Outputs, context);
- auto program = resolveString(*state.store, unresolvedProgram, builtContext);
- checkProgram(program);
- return App {
- .program = program,
- };
+ auto builtContext = build(store, Realise::Outputs, installableContext);
+ res.program = resolveString(*store, unresolved.program, builtContext);
+ if (store->isInStore(res.program))
+ throw Error("app program '%s' is not in the Nix store", res.program);
+
+ return res;
}
}