diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2017-11-24T17·07+0100 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2017-11-24T17·08+0100 |
commit | 90948a4e3a64492b7d117d93657221fa7b598e6e (patch) | |
tree | d339dad0dd12db1132d3484a6cad199c13a78b82 /src | |
parent | 0fc3e581e0585e377d4b42e343b0487606add547 (diff) |
nix-shell/nix-build: Support .drv files again
Fixes #1663. Also handle '!<output-name>' (#1694).
Diffstat (limited to 'src')
-rw-r--r-- | src/libexpr/get-drvs.cc | 28 | ||||
-rw-r--r-- | src/libexpr/get-drvs.hh | 1 | ||||
-rwxr-xr-x | src/nix-build/nix-build.cc | 6 |
3 files changed, 33 insertions, 2 deletions
diff --git a/src/libexpr/get-drvs.cc b/src/libexpr/get-drvs.cc index d5bc42352a26..d38ed2df3b18 100644 --- a/src/libexpr/get-drvs.cc +++ b/src/libexpr/get-drvs.cc @@ -1,6 +1,7 @@ #include "get-drvs.hh" #include "util.hh" #include "eval-inline.hh" +#include "derivations.hh" #include <cstring> #include <regex> @@ -15,6 +16,33 @@ DrvInfo::DrvInfo(EvalState & state, const string & attrPath, Bindings * attrs) } +DrvInfo::DrvInfo(EvalState & state, ref<Store> store, const std::string & drvPathWithOutputs) + : state(&state), attrs(nullptr), attrPath("") +{ + auto spec = parseDrvPathWithOutputs(drvPathWithOutputs); + + drvPath = spec.first; + + auto drv = store->derivationFromPath(drvPath); + + name = storePathToName(drvPath); + + if (spec.second.size() > 1) + throw Error("building more than one derivation output is not supported, in '%s'", drvPathWithOutputs); + + outputName = + spec.second.empty() + ? get(drv.env, "outputName", "out") + : *spec.second.begin(); + + auto i = drv.outputs.find(outputName); + if (i == drv.outputs.end()) + throw Error("derivation '%s' does not have output '%s'", drvPath, outputName); + + outPath = i->second.path; +} + + string DrvInfo::queryName() const { if (name == "" && attrs) { diff --git a/src/libexpr/get-drvs.hh b/src/libexpr/get-drvs.hh index 32294e458751..4d9128e3f448 100644 --- a/src/libexpr/get-drvs.hh +++ b/src/libexpr/get-drvs.hh @@ -37,6 +37,7 @@ public: DrvInfo(EvalState & state) : state(&state) { }; DrvInfo(EvalState & state, const string & attrPath, Bindings * attrs); + DrvInfo(EvalState & state, ref<Store> store, const std::string & drvPathWithOutputs); string queryName() const; string querySystem() const; diff --git a/src/nix-build/nix-build.cc b/src/nix-build/nix-build.cc index 21b0a18dd887..58366daa6e86 100755 --- a/src/nix-build/nix-build.cc +++ b/src/nix-build/nix-build.cc @@ -263,6 +263,8 @@ void mainWrapped(int argc, char * * argv) if (runEnv) setenv("IN_NIX_SHELL", pure ? "pure" : "impure", 1); + DrvInfos drvs; + /* Parse the expressions. */ std::vector<Expr *> exprs; @@ -272,6 +274,8 @@ void mainWrapped(int argc, char * * argv) for (auto i : left) { if (fromArgs) exprs.push_back(state.parseExprFromString(i, absPath("."))); + else if (store->isStorePath(i) && std::regex_match(i, std::regex(".*\\.drv(!.*)?"))) + drvs.push_back(DrvInfo(state, store, i)); else /* If we're in a #! script, interpret filenames relative to the script. */ @@ -280,8 +284,6 @@ void mainWrapped(int argc, char * * argv) } /* Evaluate them into derivations. */ - DrvInfos drvs; - if (attrPaths.empty()) attrPaths = {""}; for (auto e : exprs) { |