feat(3p/nix/nix-daemon): Implement Worker::BuildDerivation handler

Implement the proto handler on the server side for
Worker::BuildDerivation. This includes several additions to the proto
which I had missed on the first pass, including the actual proto
definition for the Derivation itself and a few sequence number
reorderings which are fine because this is all provisional and not
deployed yet.

A couple things to note

- I implemented a couple constructors for nix classes that initialize
  themselves based on their proto variants, which felt nice and didn't
  end up causing any issues.
- I've made the conversions between the enum types in nix and in proto
  explicit via switch statements rather than using a static_cast, out of
  an abundance of caution that the error would get mismatched in the
  future and we'd convert the wrong thing to the wrong thing - this is
  verbose, but exceptionally future proof.

Change-Id: Iecf6b88e76bc37e49efa05fd65d6cd0cb0deffed
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1249
Tested-by: BuildkiteCI
Reviewed-by: tazjin <mail@tazj.in>
Reviewed-by: Kane York <rikingcoding@gmail.com>
This commit is contained in:
Griffin Smith 2020-07-17 09:30:04 -04:00 committed by glittershark
parent 3f4e5050cd
commit a79df261b4
6 changed files with 133 additions and 1 deletions

View file

@ -6,11 +6,13 @@
#include "libproto/worker.grpc.pb.h"
#include "libproto/worker.pb.h"
#include "libstore/derivations.hh"
#include "libstore/store-api.hh"
namespace nix::daemon {
using ::grpc::Status;
using ::nix::proto::BuildStatus;
using ::nix::proto::PathInfo;
using ::nix::proto::StorePath;
using ::nix::proto::StorePaths;
@ -204,6 +206,27 @@ class WorkerServiceImpl final : public WorkerService::Service {
return Status::OK;
}
Status BuildDerivation(
grpc::ServerContext* context,
const nix::proto::BuildDerivationRequest* request,
nix::proto::BuildDerivationResponse* response) override {
auto drv_path = request->drv_path().path();
store_->assertStorePath(drv_path);
auto drv = BasicDerivation::from_proto(&request->derivation(), store_);
auto build_mode = nix::build_mode_from(request->build_mode());
if (!build_mode) {
return Status(grpc::StatusCode::INTERNAL, "Invalid build mode");
}
auto res = store_->buildDerivation(drv_path, drv, *build_mode);
response->set_status(res.status_to_proto());
response->set_error_message(res.errorMsg);
return Status::OK;
}
Status QueryMissing(grpc::ServerContext* context, const StorePaths* request,
nix::proto::QueryMissingResponse* response) override {
std::set<Path> targets;