@@ -58,33 +58,24 @@ std::string resolveString(Store & store, const std::string & toResolve, const Bu
58
58
return rewriteStrings (toResolve, rewrites);
59
59
}
60
60
61
- App Installable::toApp (EvalState & state)
61
+ UnresolvedApp Installable::toApp (EvalState & state)
62
62
{
63
63
auto [cursor, attrPath] = getCursor (state);
64
64
65
65
auto type = cursor->getAttr (" type" )->getString ();
66
66
67
- auto checkProgram = [&](const Path & program)
68
- {
69
- if (!state.store ->isInStore (program))
70
- throw Error (" app program '%s' is not in the Nix store" , program);
71
- };
67
+ if (type == " app" ) {
68
+ auto [program, context] = cursor->getAttr (" program" )->getStringWithContext ();
72
69
73
- std::vector<std::shared_ptr<Installable>> context;
74
- std::string unresolvedProgram;
75
70
71
+ std::vector<StorePathWithOutputs> context2;
72
+ for (auto & [path, name] : context)
73
+ context2.push_back ({state.store ->parseStorePath (path), {name}});
76
74
77
- if (type == " app" ) {
78
- auto [program, context_] = cursor->getAttr (" program" )->getStringWithContext ();
79
- unresolvedProgram = program;
80
-
81
- for (auto & [path, name] : context_)
82
- context.push_back (std::make_shared<InstallableDerivedPath>(
83
- state.store ,
84
- DerivedPathBuilt{
85
- .drvPath = state.store ->parseStorePath (path),
86
- .outputs = {name},
87
- }));
75
+ return UnresolvedApp{App {
76
+ .context = std::move (context2),
77
+ .program = program,
78
+ }};
88
79
}
89
80
90
81
else if (type == " derivation" ) {
@@ -98,24 +89,33 @@ App Installable::toApp(EvalState & state)
98
89
aMainProgram
99
90
? aMainProgram->getString ()
100
91
: DrvName (name).name ;
101
- unresolvedProgram = outPath + " /bin/" + mainProgram;
102
- context = {std::make_shared<InstallableDerivedPath>(
103
- state.store ,
104
- DerivedPathBuilt{
105
- .drvPath = drvPath,
106
- .outputs = {outputName},
107
- })};
92
+ auto program = outPath + " /bin/" + mainProgram;
93
+ return UnresolvedApp { App {
94
+ .context = { { drvPath, {outputName} } },
95
+ .program = program,
96
+ }};
108
97
}
109
98
110
99
else
111
100
throw Error (" attribute '%s' has unsupported type '%s'" , attrPath, type);
101
+ }
102
+
103
+ App UnresolvedApp::resolve (ref<Store> store)
104
+ {
105
+ auto res = unresolved;
106
+
107
+ std::vector<std::shared_ptr<Installable>> installableContext;
108
+
109
+ for (auto & ctxElt : unresolved.context )
110
+ installableContext.push_back (
111
+ std::make_shared<InstallableDerivedPath>(store, ctxElt.toDerivedPath ()));
112
112
113
- auto builtContext = build (state. store , Realise::Outputs, context );
114
- auto program = resolveString (*state. store , unresolvedProgram , builtContext);
115
- checkProgram ( program);
116
- return App {
117
- . program = program,
118
- } ;
113
+ auto builtContext = build (store, Realise::Outputs, installableContext );
114
+ res. program = resolveString (*store, unresolved. program , builtContext);
115
+ if (store-> isInStore (res. program ))
116
+ throw Error ( " app program '%s' is not in the Nix store " , res. program );
117
+
118
+ return res ;
119
119
}
120
120
121
121
}
0 commit comments