Add a command :s to start a nix-shell for a derivation

This commit is contained in:
Eelco Dolstra 2013-09-06 15:05:18 +02:00
parent c6712a007f
commit b5944ac4ff

View file

@ -140,13 +140,15 @@ void NixRepl::processLine(string line)
{ {
if (line == "") return; if (line == "") return;
if (string(line, 0, 2) == ":a") { string command = string(line, 0, 2);
if (command == ":a") {
Value v; Value v;
evalString(string(line, 2), v); evalString(string(line, 2), v);
addAttrsToScope(v); addAttrsToScope(v);
} }
else if (string(line, 0, 2) == ":l") { else if (command == ":l") {
state.resetFileCache(); state.resetFileCache();
Path path = lookupFileArg(state, removeWhitespace(string(line, 2))); Path path = lookupFileArg(state, removeWhitespace(string(line, 2)));
Value v, v2; Value v, v2;
@ -156,13 +158,13 @@ void NixRepl::processLine(string line)
addAttrsToScope(v2); addAttrsToScope(v2);
} }
else if (string(line, 0, 2) == ":t") { else if (command == ":t") {
Value v; Value v;
evalString(string(line, 2), v); evalString(string(line, 2), v);
std::cout << showType(v) << std::endl; std::cout << showType(v) << std::endl;
} }
else if (string(line, 0, 2) == ":b") { else if (command == ":b" || command == ":s") {
Value v; Value v;
evalString(string(line, 2), v); evalString(string(line, 2), v);
DrvInfo drvInfo; DrvInfo drvInfo;
@ -171,15 +173,21 @@ void NixRepl::processLine(string line)
Path drvPath = drvInfo.queryDrvPath(state); Path drvPath = drvInfo.queryDrvPath(state);
if (drvPath == "" || !store->isValidPath(drvPath)) if (drvPath == "" || !store->isValidPath(drvPath))
throw Error("expression did not evaluate to a valid derivation"); 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 if (command == ":b") {
problems / SIGINT. */ /* We could do the build in this process using buildPaths(),
if (system(("nix-store -r " + drvPath + " > /dev/null").c_str()) == -1) but doing it in a child makes it easier to recover from
throw SysError("starting nix-store"); problems / SIGINT. */
Derivation drv = parseDerivation(readFile(drvPath)); if (system(("nix-store -r " + drvPath + " > /dev/null").c_str()) == -1)
std::cout << "this derivation produced the following outputs:" << std::endl; throw SysError("starting nix-store");
foreach (DerivationOutputs::iterator, i, drv.outputs) Derivation drv = parseDerivation(readFile(drvPath));
std::cout << format(" %1% -> %2%") % i->first % i->second.path << std::endl; 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 (system(("nix-shell " + drvPath).c_str()) == -1)
throw SysError("starting nix-shell");
}
} }
else if (string(line, 0, 1) == ":") else if (string(line, 0, 1) == ":")