mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-11 00:36:20 +02:00
Add a command :s to start a nix-shell for a derivation
This commit is contained in:
parent
c6712a007f
commit
b5944ac4ff
1 changed files with 21 additions and 13 deletions
16
nix-repl.cc
16
nix-repl.cc
|
@ -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,6 +173,8 @@ 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");
|
||||||
|
|
||||||
|
if (command == ":b") {
|
||||||
/* We could do the build in this process using buildPaths(),
|
/* We could do the build in this process using buildPaths(),
|
||||||
but doing it in a child makes it easier to recover from
|
but doing it in a child makes it easier to recover from
|
||||||
problems / SIGINT. */
|
problems / SIGINT. */
|
||||||
|
@ -180,6 +184,10 @@ void NixRepl::processLine(string line)
|
||||||
std::cout << "this derivation produced the following outputs:" << std::endl;
|
std::cout << "this derivation produced the following outputs:" << std::endl;
|
||||||
foreach (DerivationOutputs::iterator, i, drv.outputs)
|
foreach (DerivationOutputs::iterator, i, drv.outputs)
|
||||||
std::cout << format(" %1% -> %2%") % i->first % i->second.path << std::endl;
|
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) == ":")
|
||||||
|
|
Loading…
Reference in a new issue