forked from lix-project/lix
nix run: Allow program name to be set in meta.mainProgram
This is useful when the program name doesn't match the package name (e.g. ripgrep vs rg). Fixes #4498.
This commit is contained in:
parent
13897afbe6
commit
7bd9898d5c
|
@ -12,11 +12,16 @@ App Installable::toApp(EvalState & state)
|
||||||
|
|
||||||
auto type = cursor->getAttr("type")->getString();
|
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") {
|
if (type == "app") {
|
||||||
auto [program, context] = cursor->getAttr("program")->getStringWithContext();
|
auto [program, context] = cursor->getAttr("program")->getStringWithContext();
|
||||||
|
|
||||||
if (!state.store->isInStore(program))
|
checkProgram(program);
|
||||||
throw Error("app program '%s' is not in the Nix store", program);
|
|
||||||
|
|
||||||
std::vector<StorePathWithOutputs> context2;
|
std::vector<StorePathWithOutputs> context2;
|
||||||
for (auto & [path, name] : context)
|
for (auto & [path, name] : context)
|
||||||
|
@ -33,9 +38,17 @@ App Installable::toApp(EvalState & state)
|
||||||
auto outPath = cursor->getAttr(state.sOutPath)->getString();
|
auto outPath = cursor->getAttr(state.sOutPath)->getString();
|
||||||
auto outputName = cursor->getAttr(state.sOutputName)->getString();
|
auto outputName = cursor->getAttr(state.sOutputName)->getString();
|
||||||
auto name = cursor->getAttr(state.sName)->getString();
|
auto name = cursor->getAttr(state.sName)->getString();
|
||||||
|
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);
|
||||||
return App {
|
return App {
|
||||||
.context = { { drvPath, {outputName} } },
|
.context = { { drvPath, {outputName} } },
|
||||||
.program = outPath + "/bin/" + DrvName(name).name,
|
.program = program,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue