Add the nix-store --serve command
This is essentially the substituter API operating on the local store, which will be used by the ssh substituter. It runs in a loop rather than just taking one command so that in the future nix will be able to keep one connection open for multiple instances of the substituter. Signed-off-by: Shea Levy <shea@shealevy.com>
This commit is contained in:
		
							parent
							
								
									84a8b5e9af
								
							
						
					
					
						commit
						3a38d0f356
					
				
					 3 changed files with 55 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -258,6 +258,37 @@ string StoreAPI::makeValidityRegistration(const PathSet & paths,
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void StoreAPI::serve(Source & in, Sink & out, bool sign)
 | 
			
		||||
{
 | 
			
		||||
    for (string cmd = readString(in); !cmd.empty(); cmd = readString(in)) {
 | 
			
		||||
        if (cmd == "query") {
 | 
			
		||||
            for (cmd = readString(in); !cmd.empty(); cmd = readString(in)) {
 | 
			
		||||
                PathSet paths = readStrings<PathSet>(in);
 | 
			
		||||
                if (cmd == "have") {
 | 
			
		||||
                    writeStrings(queryValidPaths(paths), out);
 | 
			
		||||
                } else if (cmd == "info") {
 | 
			
		||||
                    // !!! Maybe we want a queryPathInfos?
 | 
			
		||||
                    foreach (PathSet::iterator, i, paths) {
 | 
			
		||||
                        ValidPathInfo info = queryPathInfo(*i);
 | 
			
		||||
                        writeString(info.path, out);
 | 
			
		||||
                        writeString(info.deriver, out);
 | 
			
		||||
                        writeStrings(info.references, out);
 | 
			
		||||
                        // !!! Maybe we want compression?
 | 
			
		||||
                        writeLongLong(info.narSize, out); // downloadSize
 | 
			
		||||
                        writeLongLong(info.narSize, out);
 | 
			
		||||
                    }
 | 
			
		||||
                    writeString("", out);
 | 
			
		||||
                } else
 | 
			
		||||
                    throw Error(format("Unknown serve query `%1%'") % cmd);
 | 
			
		||||
            }
 | 
			
		||||
        } else if (cmd == "substitute")
 | 
			
		||||
            exportPath(readString(in), sign, out);
 | 
			
		||||
        else
 | 
			
		||||
            throw Error(format("Unknown serve command `%1%'") % cmd);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
ValidPathInfo decodeValidPathInfo(std::istream & str, bool hashGiven)
 | 
			
		||||
{
 | 
			
		||||
    ValidPathInfo info;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -248,6 +248,10 @@ public:
 | 
			
		|||
       `nix-store --register-validity'. */
 | 
			
		||||
    string makeValidityRegistration(const PathSet & paths,
 | 
			
		||||
        bool showDerivers, bool showHash);
 | 
			
		||||
 | 
			
		||||
    /* Serve the store for ssh substituters by taking commands
 | 
			
		||||
     * from in and printing results to out */
 | 
			
		||||
    void serve(Source & in, Sink & out, bool sign);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue