From 71a5161365f40699092e491bbff88473237fc432 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 3 Sep 2015 12:56:59 +0200 Subject: [PATCH] Implement buildDerivation() via the daemon --- src/libstore/remote-store.cc | 10 +++++++++- src/libstore/worker-protocol.hh | 3 ++- src/libutil/serialise.cc | 7 +++++++ src/libutil/serialise.hh | 1 + src/nix-daemon/nix-daemon.cc | 15 +++++++++++++++ 5 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc index fdb0975ac..ed9895ac8 100644 --- a/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -5,6 +5,7 @@ #include "archive.hh" #include "affinity.hh" #include "globals.hh" +#include "derivations.hh" #include #include @@ -458,7 +459,14 @@ void RemoteStore::buildPaths(const PathSet & drvPaths, BuildMode buildMode) BuildResult RemoteStore::buildDerivation(const Path & drvPath, const BasicDerivation & drv, BuildMode buildMode) { - throw Error("not implemented"); + openConnection(); + to << wopBuildDerivation << drvPath << drv << buildMode; + processStderr(); + BuildResult res; + unsigned int status; + from >> status >> res.errorMsg; + res.status = (BuildResult::Status) status; + return res; } diff --git a/src/libstore/worker-protocol.hh b/src/libstore/worker-protocol.hh index d037d7402..5a0ef5117 100644 --- a/src/libstore/worker-protocol.hh +++ b/src/libstore/worker-protocol.hh @@ -43,7 +43,8 @@ typedef enum { wopQuerySubstitutablePaths = 32, wopQueryValidDerivers = 33, wopOptimiseStore = 34, - wopVerifyStore = 35 + wopVerifyStore = 35, + wopBuildDerivation = 36, } WorkerOp; diff --git a/src/libutil/serialise.cc b/src/libutil/serialise.cc index f8e9d00c1..f136a1324 100644 --- a/src/libutil/serialise.cc +++ b/src/libutil/serialise.cc @@ -248,6 +248,13 @@ Source & operator >> (Source & in, string & s) } +Source & operator >> (Source & in, unsigned int & n) +{ + n = readInt(in); + return in; +} + + template T readStrings(Source & source) { unsigned int count = readInt(source); diff --git a/src/libutil/serialise.hh b/src/libutil/serialise.hh index 97ac3e912..979ff849f 100644 --- a/src/libutil/serialise.hh +++ b/src/libutil/serialise.hh @@ -143,6 +143,7 @@ string readString(Source & source); template T readStrings(Source & source); Source & operator >> (Source & in, string & s); +Source & operator >> (Source & in, unsigned int & n); MakeError(SerialisationError, Error) diff --git a/src/nix-daemon/nix-daemon.cc b/src/nix-daemon/nix-daemon.cc index 199d3288f..aaae691e9 100644 --- a/src/nix-daemon/nix-daemon.cc +++ b/src/nix-daemon/nix-daemon.cc @@ -7,6 +7,7 @@ #include "affinity.hh" #include "globals.hh" #include "monitor-fd.hh" +#include "derivations.hh" #include @@ -325,6 +326,20 @@ static void performOp(bool trusted, unsigned int clientVersion, break; } + case wopBuildDerivation: { + Path drvPath = readStorePath(from); + BasicDerivation drv; + from >> drv; + BuildMode buildMode = (BuildMode) readInt(from); + startWork(); + if (!trusted) + throw Error("you are not privileged to build derivations"); + auto res = store->buildDerivation(drvPath, drv, buildMode); + stopWork(); + to << res.status << res.errorMsg; + break; + } + case wopEnsurePath: { Path path = readStorePath(from); startWork();