diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2013-09-06T12·58+0200 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2013-09-06T12·58+0200 |
commit | c6712a007fc55398893995a3466d35ae0697db05 (patch) | |
tree | b817b2554833436d41ae2d562a9d7fb6006e2a87 /nix-repl.cc | |
parent | ad0dd359b4434db84bf6458715440cc15f896ddc (diff) |
Add a command :b to build a derivation
Diffstat (limited to 'nix-repl.cc')
-rw-r--r-- | nix-repl.cc | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/nix-repl.cc b/nix-repl.cc index 45d7433396ec..f41cf4d292d9 100644 --- a/nix-repl.cc +++ b/nix-repl.cc @@ -11,6 +11,8 @@ #include "eval-inline.hh" #include "store-api.hh" #include "common-opts.hh" +#include "get-drvs.hh" +#include "derivations.hh" using namespace std; using namespace nix; @@ -122,9 +124,9 @@ void NixRepl::mainLoop() try { processLine(removeWhitespace(line)); } catch (Error & e) { - printMsg(lvlError, e.msg()); + printMsg(lvlError, "error: " + e.msg()); } catch (Interrupted & e) { - printMsg(lvlError, e.msg()); + printMsg(lvlError, "error: " + e.msg()); } std::cout << std::endl; @@ -160,10 +162,29 @@ void NixRepl::processLine(string line) std::cout << showType(v) << std::endl; } - else if (string(line, 0, 1) == ":") { - throw Error(format("unknown command ‘%1%’") % string(line, 0, 2)); + else if (string(line, 0, 2) == ":b") { + Value v; + evalString(string(line, 2), v); + DrvInfo drvInfo; + if (!getDerivation(state, v, drvInfo, false)) + throw Error("expression does not evaluation to a derivation, so I can't build it"); + Path drvPath = drvInfo.queryDrvPath(state); + if (drvPath == "" || !store->isValidPath(drvPath)) + throw Error("expression did not evaluate to a valid derivation"); + /* We could do the build in this process using buildPaths(), + but doing it in a child makes it easier to recover from + problems / SIGINT. */ + if (system(("nix-store -r " + drvPath + " > /dev/null").c_str()) == -1) + throw SysError("starting nix-store"); + Derivation drv = parseDerivation(readFile(drvPath)); + std::cout << "this derivation produced the following outputs:" << std::endl; + foreach (DerivationOutputs::iterator, i, drv.outputs) + std::cout << format(" %1% -> %2%") % i->first % i->second.path << std::endl; } + else if (string(line, 0, 1) == ":") + throw Error(format("unknown command ‘%1%’") % string(line, 0, 2)); + else { Value v; evalString(line, v); @@ -178,7 +199,7 @@ void NixRepl::addAttrsToScope(Value & attrs) state.forceAttrs(attrs); foreach (Bindings::iterator, i, *attrs.attrs) addVarToScope(i->name, i->value); - printMsg(lvlError, format("added %1% variables") % attrs.attrs->size()); + std::cout << format("added %1% variables") % attrs.attrs->size() << std::endl; } |