about summary refs log tree commit diff
path: root/src/libutil/serialise.cc
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2015-07-17T15·57+0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2015-07-17T15·57+0200
commit1511aa9f488ba0762c2da0bf8ab61b5fde47305d (patch)
treefc394f398be8d2aa4a040794618713a22179e9e0 /src/libutil/serialise.cc
parentf39979c6d3e49b09aa82fea5e167d4253f63d71f (diff)
Allow remote builds without sending the derivation closure
Previously, to build a derivation remotely, we had to copy the entire
closure of the .drv file to the remote machine, even though we only
need the top-level derivation. This is very wasteful: the closure can
contain thousands of store paths, and in some Hydra use cases, include
source paths that are very large (e.g. Git/Mercurial checkouts).

So now there is a new operation, StoreAPI::buildDerivation(), that
performs a build from an in-memory representation of a derivation
(BasicDerivation) rather than from a on-disk .drv file. The only files
that need to be in the Nix store are the sources of the derivation
(drv.inputSrcs), and the needed output paths of the dependencies (as
described by drv.inputDrvs). "nix-store --serve" exposes this
interface.

Note that this is a privileged operation, because you can construct a
derivation that builds any store path whatsoever. Fixing this will
require changing the hashing scheme (i.e., the output paths should be
computed from the other fields in BasicDerivation, allowing them to be
verified without access to other derivations). However, this would be
quite nice because it would allow .drv-free building (e.g. "nix-env
-i" wouldn't have to write any .drv files to disk).

Fixes #173.
Diffstat (limited to 'src/libutil/serialise.cc')
-rw-r--r--src/libutil/serialise.cc32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/libutil/serialise.cc b/src/libutil/serialise.cc
index 92417507508a..aa16a20e6d35 100644
--- a/src/libutil/serialise.cc
+++ b/src/libutil/serialise.cc
@@ -155,6 +155,12 @@ void writeInt(unsigned int n, Sink & sink)
     sink(buf, sizeof(buf));
 }
 
+Sink & operator << (Sink & out, unsigned int n)
+{
+    writeInt(n, out);
+    return out;
+}
+
 
 void writeLongLong(unsigned long long n, Sink & sink)
 {
@@ -184,6 +190,12 @@ void writeString(const string & s, Sink & sink)
     writeString((const unsigned char *) s.data(), s.size(), sink);
 }
 
+Sink & operator << (Sink & out, const string & s)
+{
+    writeString(s, out);
+    return out;
+}
+
 
 template<class T> void writeStrings(const T & ss, Sink & sink)
 {
@@ -195,6 +207,18 @@ template<class T> void writeStrings(const T & ss, Sink & sink)
 template void writeStrings(const Paths & ss, Sink & sink);
 template void writeStrings(const PathSet & ss, Sink & sink);
 
+Sink & operator << (Sink & out, const Strings & s)
+{
+    writeStrings(s, out);
+    return out;
+}
+
+Sink & operator << (Sink & out, const StringSet & s)
+{
+    writeStrings(s, out);
+    return out;
+}
+
 
 void readPadding(size_t len, Source & source)
 {
@@ -258,7 +282,13 @@ string readString(Source & source)
     return string((char *) buf, len);
 }
 
- 
+Source & operator >> (Source & in, string & s)
+{
+    s = readString(in);
+    return in;
+}
+
+
 template<class T> T readStrings(Source & source)
 {
     unsigned int count = readInt(source);