aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2021-02-17 17:54:13 +0100
committerEelco Dolstra <edolstra@gmail.com>2021-02-17 17:55:15 +0100
commit7bd9898d5ca72ed136032590745c56826317a328 (patch)
treefceaf05a40b7373687ffac387b84f8e618ea02cc
parent13897afbe6cf7ef8013c0c94109696bb7b13d0c0 (diff)
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.
-rw-r--r--src/nix/app.cc19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/nix/app.cc b/src/nix/app.cc
index 80acbf658..cf147c631 100644
--- a/src/nix/app.cc
+++ b/src/nix/app.cc
@@ -12,11 +12,16 @@ App Installable::toApp(EvalState & 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();
- if (!state.store->isInStore(program))
- throw Error("app program '%s' is not in the Nix store", program);
+ checkProgram(program);
std::vector<StorePathWithOutputs> context2;
for (auto & [path, name] : context)
@@ -33,9 +38,17 @@ App Installable::toApp(EvalState & state)
auto outPath = cursor->getAttr(state.sOutPath)->getString();
auto outputName = cursor->getAttr(state.sOutputName)->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 {
.context = { { drvPath, {outputName} } },
- .program = outPath + "/bin/" + DrvName(name).name,
+ .program = program,
};
}