diff options
Diffstat (limited to 'src/nix/run.cc')
-rw-r--r-- | src/nix/run.cc | 57 |
1 files changed, 54 insertions, 3 deletions
diff --git a/src/nix/run.cc b/src/nix/run.cc index 5334531fd..901b87fbb 100644 --- a/src/nix/run.cc +++ b/src/nix/run.cc @@ -89,15 +89,15 @@ struct CmdRun : InstallablesCommand, RunCommon, MixEnvironment }, Example{ "To start a shell providing youtube-dl from your 'nixpkgs' channel:", - "nix run nixpkgs.youtube-dl" + "nix run nixpkgs#youtube-dl" }, Example{ "To run GNU Hello:", - "nix run nixpkgs.hello -c hello --greeting 'Hi everybody!'" + "nix run nixpkgs#hello -c hello --greeting 'Hi everybody!'" }, Example{ "To run GNU Hello in a chroot store:", - "nix run --store ~/my-nix nixpkgs.hello -c hello" + "nix run --store ~/my-nix nixpkgs#hello -c hello" }, }; } @@ -143,6 +143,57 @@ struct CmdRun : InstallablesCommand, RunCommon, MixEnvironment static auto r1 = registerCommand<CmdRun>("run"); +struct CmdApp : InstallableCommand, RunCommon +{ + std::vector<std::string> args; + + CmdApp() + { + expectArgs("args", &args); + } + + std::string description() override + { + return "run a Nix application"; + } + + Examples examples() override + { + return { + Example{ + "To run Blender:", + "nix app blender-bin" + }, + }; + } + + Strings getDefaultFlakeAttrPaths() override + { + return {"defaultApp." + settings.thisSystem.get()}; + } + + Strings getDefaultFlakeAttrPathPrefixes() override + { + return {"apps." + settings.thisSystem.get() + "."}; + } + + void run(ref<Store> store) override + { + auto state = getEvalState(); + + auto app = installable->toApp(*state); + + state->realiseContext(app.context); + + Strings allArgs{app.program}; + for (auto & i : args) allArgs.push_back(i); + + runProgram(store, app.program, allArgs); + } +}; + +static auto r2 = registerCommand<CmdApp>("app"); + void chrootHelper(int argc, char * * argv) { int p = 1; |