-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nix run: Use packages/legacyPackages as fallback if there is no app d…
…efinition 'nix run' will try to run $out/bin/<name>, where <name> is the derivation name (excluding the version). This often works well: $ nix run nixpkgs#hello Hello, world! $ nix run nix -- --version nix (Nix) 2.4pre20200626_adf2fbb $ nix run patchelf -- --version patchelf 0.11.20200623.e61654b $ nix run nixpkgs#firefox -- --version Mozilla Firefox 77.0.1 $ nix run nixpkgs#gimp -- --version GNU Image Manipulation Program version 2.10.14 though not always: $ nix run nixpkgs#git error: unable to execute '/nix/store/kp7wp760l4gryq9s36x481b2x4rfklcy-git-2.25.4/bin/git-minimal': No such file or directory
- Loading branch information
Showing
4 changed files
with
47 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,46 @@ | ||
#include "installables.hh" | ||
#include "store-api.hh" | ||
#include "eval-inline.hh" | ||
#include "eval-cache.hh" | ||
#include "names.hh" | ||
|
||
namespace nix { | ||
|
||
App::App(EvalState & state, Value & vApp) | ||
App Installable::toApp(EvalState & state) | ||
{ | ||
state.forceAttrs(vApp); | ||
auto [cursor, attrPath] = getCursor(state, true); | ||
|
||
auto aType = vApp.attrs->need(state.sType); | ||
if (state.forceStringNoCtx(*aType.value, *aType.pos) != "app") | ||
throw Error("value does not have type 'app', at %s", *aType.pos); | ||
auto type = cursor->getAttr("type")->getString(); | ||
|
||
auto aProgram = vApp.attrs->need(state.symbols.create("program")); | ||
program = state.forceString(*aProgram.value, context, *aProgram.pos); | ||
if (type == "app") { | ||
auto [program, context] = cursor->getAttr("program")->getStringWithContext(); | ||
|
||
// FIXME: check that 'program' is in the closure of 'context'. | ||
if (!state.store->isInStore(program)) | ||
throw Error("app program '%s' is not in the Nix store", program); | ||
} | ||
if (!state.store->isInStore(program)) | ||
throw Error("app program '%s' is not in the Nix store", program); | ||
|
||
App Installable::toApp(EvalState & state) | ||
{ | ||
return App(state, *toValue(state).first); | ||
std::vector<StorePathWithOutputs> context2; | ||
for (auto & [path, name] : context) | ||
context2.push_back({state.store->parseStorePath(path), {name}}); | ||
|
||
return App { | ||
.context = std::move(context2), | ||
.program = program, | ||
}; | ||
} | ||
|
||
else if (type == "derivation") { | ||
auto drvPath = cursor->forceDerivation(); | ||
auto outPath = cursor->getAttr(state.sOutPath)->getString(); | ||
auto outputName = cursor->getAttr(state.sOutputName)->getString(); | ||
auto name = cursor->getAttr(state.sName)->getString(); | ||
return App { | ||
.context = { { drvPath, {outputName} } }, | ||
.program = outPath + "/bin/" + DrvName(name).name, | ||
}; | ||
} | ||
|
||
else | ||
throw Error("attribute '%s' has unsupported type '%s'", attrPath, type); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26cf0c6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice feature! Could Nix first check whether the executable exists before running it, and describe what should be done in case the executable does not exist? This may otherwise be a bit too much magic and get confusing. Typically this type of checking is avoided because the file could be created/moved, but with the read-only store we do not have this issue.
26cf0c6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding
pkgs.gitMinimal
, maybe we could move the variants into the version, likegit-2.26.2+minimal
. Another idea is to introduce apassthru.entrypoint
that can be used to override the location of the binary.