Add a command :b to build a derivation
This commit is contained in:
		
							parent
							
								
									ad0dd359b4
								
							
						
					
					
						commit
						c6712a007f
					
				
					 1 changed files with 26 additions and 5 deletions
				
			
		
							
								
								
									
										31
									
								
								nix-repl.cc
									
										
									
									
									
								
							
							
						
						
									
										31
									
								
								nix-repl.cc
									
										
									
									
									
								
							| 
						 | 
					@ -11,6 +11,8 @@
 | 
				
			||||||
#include "eval-inline.hh"
 | 
					#include "eval-inline.hh"
 | 
				
			||||||
#include "store-api.hh"
 | 
					#include "store-api.hh"
 | 
				
			||||||
#include "common-opts.hh"
 | 
					#include "common-opts.hh"
 | 
				
			||||||
 | 
					#include "get-drvs.hh"
 | 
				
			||||||
 | 
					#include "derivations.hh"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
using namespace std;
 | 
					using namespace std;
 | 
				
			||||||
using namespace nix;
 | 
					using namespace nix;
 | 
				
			||||||
| 
						 | 
					@ -122,9 +124,9 @@ void NixRepl::mainLoop()
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            processLine(removeWhitespace(line));
 | 
					            processLine(removeWhitespace(line));
 | 
				
			||||||
        } catch (Error & e) {
 | 
					        } catch (Error & e) {
 | 
				
			||||||
            printMsg(lvlError, e.msg());
 | 
					            printMsg(lvlError, "error: " + e.msg());
 | 
				
			||||||
        } catch (Interrupted & e) {
 | 
					        } catch (Interrupted & e) {
 | 
				
			||||||
            printMsg(lvlError, e.msg());
 | 
					            printMsg(lvlError, "error: " + e.msg());
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        std::cout << std::endl;
 | 
					        std::cout << std::endl;
 | 
				
			||||||
| 
						 | 
					@ -160,10 +162,29 @@ void NixRepl::processLine(string line)
 | 
				
			||||||
        std::cout << showType(v) << std::endl;
 | 
					        std::cout << showType(v) << std::endl;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    else if (string(line, 0, 1) == ":") {
 | 
					    else if (string(line, 0, 2) == ":b") {
 | 
				
			||||||
        throw Error(format("unknown command ‘%1%’") % string(line, 0, 2));
 | 
					        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 {
 | 
					    else {
 | 
				
			||||||
        Value v;
 | 
					        Value v;
 | 
				
			||||||
        evalString(line, v);
 | 
					        evalString(line, v);
 | 
				
			||||||
| 
						 | 
					@ -178,7 +199,7 @@ void NixRepl::addAttrsToScope(Value & attrs)
 | 
				
			||||||
    state.forceAttrs(attrs);
 | 
					    state.forceAttrs(attrs);
 | 
				
			||||||
    foreach (Bindings::iterator, i, *attrs.attrs)
 | 
					    foreach (Bindings::iterator, i, *attrs.attrs)
 | 
				
			||||||
        addVarToScope(i->name, i->value);
 | 
					        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;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue