From 86e93b9f61cf53cfd766e1724e65507aca952f55 Mon Sep 17 00:00:00 2001 From: Scott Olson Date: Wed, 17 Feb 2016 20:31:30 -0600 Subject: [PATCH 1/2] Add :x command which works like `nix-shell -p`. --- nix-repl.cc | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/nix-repl.cc b/nix-repl.cc index 8c4f40174..adf418697 100644 --- a/nix-repl.cc +++ b/nix-repl.cc @@ -39,6 +39,7 @@ struct NixRepl void mainLoop(const Strings & files); void completePrefix(string prefix); bool getLine(string & input, const char * prompt); + Path getDerivationPath(Value & v); bool processLine(string line); void loadFile(const Path & path); void initEnv(); @@ -300,6 +301,17 @@ bool isVarName(const string & s) } +Path NixRepl::getDerivationPath(Value & v) { + DrvInfo drvInfo(state); + if (!getDerivation(state, v, drvInfo, false)) + throw Error("expression does not evaluate to a derivation, so I can't build it"); + Path drvPath = drvInfo.queryDrvPath(); + if (drvPath == "" || !state.store->isValidPath(drvPath)) + throw Error("expression did not evaluate to a valid derivation"); + return drvPath; +} + + bool NixRepl::processLine(string line) { if (line == "") return true; @@ -327,7 +339,8 @@ bool NixRepl::processLine(string line) << " :q Exit nix-repl\n" << " :r Reload all files\n" << " :s Build dependencies of derivation, then start nix-shell\n" - << " :t Describe result of evaluation\n"; + << " :t Describe result of evaluation\n" + << " :x Build derivation, then start nix-shell\n"; } else if (command == ":a" || command == ":add") { @@ -350,17 +363,21 @@ bool NixRepl::processLine(string line) Value v; evalString(arg, v); std::cout << showType(v) << std::endl; + + } else if (command == ":x") { + Value v, f, result; + evalString(arg, v); + evalString("drv: (import {}).runCommand \"shell\" { buildInputs = [ drv ]; } \"\"", f); + state.callFunction(f, v, result, Pos()); + + Path drvPath = getDerivationPath(result); + runProgram("nix-shell", Strings{drvPath}); } else if (command == ":b" || command == ":i" || command == ":s") { Value v; evalString(arg, v); - DrvInfo drvInfo(state); - if (!getDerivation(state, v, drvInfo, false)) - throw Error("expression does not evaluate to a derivation, so I can't build it"); - Path drvPath = drvInfo.queryDrvPath(); - if (drvPath == "" || !state.store->isValidPath(drvPath)) - throw Error("expression did not evaluate to a valid derivation"); + Path drvPath = getDerivationPath(v); if (command == ":b") { /* We could do the build in this process using buildPaths(), From e2ff27da07f30c598c88e8e7552be0d126e2b4da Mon Sep 17 00:00:00 2001 From: Scott Olson Date: Fri, 19 Feb 2016 04:00:36 -0600 Subject: [PATCH 2/2] Rename :x to :u, for 'use'. --- nix-repl.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nix-repl.cc b/nix-repl.cc index adf418697..a9a21ae76 100644 --- a/nix-repl.cc +++ b/nix-repl.cc @@ -340,7 +340,7 @@ bool NixRepl::processLine(string line) << " :r Reload all files\n" << " :s Build dependencies of derivation, then start nix-shell\n" << " :t Describe result of evaluation\n" - << " :x Build derivation, then start nix-shell\n"; + << " :u Build derivation, then start nix-shell\n"; } else if (command == ":a" || command == ":add") { @@ -364,7 +364,7 @@ bool NixRepl::processLine(string line) evalString(arg, v); std::cout << showType(v) << std::endl; - } else if (command == ":x") { + } else if (command == ":u") { Value v, f, result; evalString(arg, v); evalString("drv: (import {}).runCommand \"shell\" { buildInputs = [ drv ]; } \"\"", f);