feat(3p/nix): Implement two more RPC calls
Implement AddTextToStore and BuildPaths both on the client and the server Refs: #29 Change-Id: I45294c3e1c1a7489e42099d36425b7acc04e0427 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1560 Reviewed-by: kanepyork <rikingcoding@gmail.com> Tested-by: BuildkiteCI
This commit is contained in:
parent
8a1c7da357
commit
209489e348
4 changed files with 76 additions and 6 deletions
27
third_party/nix/src/libstore/rpc-store.cc
vendored
27
third_party/nix/src/libstore/rpc-store.cc
vendored
|
@ -214,9 +214,23 @@ Path RpcStore::addToStore(const std::string& name, const Path& srcPath,
|
|||
throw absl::StrCat("Not implemented ", __func__);
|
||||
}
|
||||
|
||||
Path RpcStore::addTextToStore(const std::string& name, const std::string& s,
|
||||
Path RpcStore::addTextToStore(const std::string& name,
|
||||
const std::string& content,
|
||||
const PathSet& references, RepairFlag repair) {
|
||||
throw absl::StrCat("Not implemented ", __func__);
|
||||
if (repair != 0u) {
|
||||
throw Error(
|
||||
"repairing is not supported when building through the Nix daemon");
|
||||
}
|
||||
ClientContext ctx;
|
||||
proto::AddTextToStoreRequest request;
|
||||
request.set_name(name);
|
||||
request.set_content(content);
|
||||
for (const auto& ref : references) {
|
||||
request.add_references(ref);
|
||||
}
|
||||
proto::StorePath result;
|
||||
SuccessOrThrow(stub_->AddTextToStore(&ctx, request, &result));
|
||||
return result.path();
|
||||
}
|
||||
|
||||
void RpcStore::narFromPath(const Path& path, Sink& sink) {
|
||||
|
@ -224,7 +238,14 @@ void RpcStore::narFromPath(const Path& path, Sink& sink) {
|
|||
}
|
||||
|
||||
void RpcStore::buildPaths(const PathSet& paths, BuildMode buildMode) {
|
||||
throw absl::StrCat("Not implemented ", __func__);
|
||||
ClientContext ctx;
|
||||
proto::BuildPathsRequest request;
|
||||
for (const auto& path : paths) {
|
||||
request.add_drvs(path);
|
||||
}
|
||||
google::protobuf::Empty response;
|
||||
request.set_mode(nix::BuildModeToProto(buildMode));
|
||||
SuccessOrThrow(stub_->BuildPaths(&ctx, request, &response));
|
||||
}
|
||||
|
||||
BuildResult RpcStore::buildDerivation(const Path& drvPath,
|
||||
|
|
14
third_party/nix/src/libstore/store-api.cc
vendored
14
third_party/nix/src/libstore/store-api.cc
vendored
|
@ -10,6 +10,7 @@
|
|||
#include <glog/logging.h>
|
||||
#include <grpcpp/create_channel.h>
|
||||
|
||||
#include "libproto/worker.pb.h"
|
||||
#include "libstore/crypto.hh"
|
||||
#include "libstore/derivations.hh"
|
||||
#include "libstore/globals.hh"
|
||||
|
@ -21,7 +22,7 @@
|
|||
|
||||
namespace nix {
|
||||
|
||||
std::optional<BuildMode> build_mode_from(nix::proto::BuildMode mode) {
|
||||
std::optional<BuildMode> BuildModeFrom(nix::proto::BuildMode mode) {
|
||||
switch (mode) {
|
||||
case nix::proto::BuildMode::Normal:
|
||||
return BuildMode::bmNormal;
|
||||
|
@ -34,6 +35,17 @@ std::optional<BuildMode> build_mode_from(nix::proto::BuildMode mode) {
|
|||
}
|
||||
}
|
||||
|
||||
nix::proto::BuildMode BuildModeToProto(BuildMode mode) {
|
||||
switch (mode) {
|
||||
case BuildMode::bmNormal:
|
||||
return nix::proto::BuildMode::Normal;
|
||||
case BuildMode::bmRepair:
|
||||
return nix::proto::BuildMode::Repair;
|
||||
case BuildMode::bmCheck:
|
||||
return nix::proto::BuildMode::Check;
|
||||
}
|
||||
}
|
||||
|
||||
nix::proto::BuildStatus BuildResult::status_to_proto() {
|
||||
switch (status) {
|
||||
case BuildResult::Status::Built:
|
||||
|
|
5
third_party/nix/src/libstore/store-api.hh
vendored
5
third_party/nix/src/libstore/store-api.hh
vendored
|
@ -184,7 +184,10 @@ enum BuildMode { bmNormal, bmRepair, bmCheck };
|
|||
|
||||
// Convert the proto version of a `nix::proto::BuildMode` to its corresponding
|
||||
// nix `BuildMode`
|
||||
std::optional<BuildMode> build_mode_from(nix::proto::BuildMode mode);
|
||||
std::optional<BuildMode> BuildModeFrom(nix::proto::BuildMode mode);
|
||||
|
||||
// Convert a `nix::BuildMode` to its corresponding proto representation
|
||||
nix::proto::BuildMode BuildModeToProto(BuildMode mode);
|
||||
|
||||
struct BuildResult {
|
||||
/* Note: don't remove status codes, and only add new status codes
|
||||
|
|
|
@ -172,6 +172,40 @@ class WorkerServiceImpl final : public WorkerService::Service {
|
|||
return Status::OK;
|
||||
}
|
||||
|
||||
Status AddTextToStore(grpc::ServerContext*,
|
||||
const nix::proto::AddTextToStoreRequest* request,
|
||||
nix::proto::StorePath* response) override {
|
||||
PathSet references;
|
||||
for (const auto& ref : request->references()) {
|
||||
references.insert(ref);
|
||||
}
|
||||
auto path =
|
||||
store_->addTextToStore(request->name(), request->content(), references);
|
||||
response->set_path(path);
|
||||
return Status::OK;
|
||||
}
|
||||
|
||||
Status BuildPaths(grpc::ServerContext*,
|
||||
const nix::proto::BuildPathsRequest* request,
|
||||
google::protobuf::Empty*) override {
|
||||
PathSet drvs;
|
||||
for (const auto& drv : request->drvs()) {
|
||||
drvs.insert(drv);
|
||||
}
|
||||
auto mode = BuildModeFrom(request->mode());
|
||||
|
||||
if (!mode.has_value()) {
|
||||
return Status(grpc::StatusCode::INTERNAL, "Invalid build mode");
|
||||
}
|
||||
|
||||
// TODO(grfn): If mode is repair and not trusted, we need to return an error
|
||||
// here (but we can't yet because we don't know anything about trusted
|
||||
// users)
|
||||
store_->buildPaths(drvs, mode.value());
|
||||
|
||||
return Status::OK;
|
||||
}
|
||||
|
||||
Status QuerySubstitutablePathInfos(
|
||||
grpc::ServerContext*, const StorePaths* request,
|
||||
nix::proto::SubstitutablePathInfos* response) override {
|
||||
|
@ -357,7 +391,7 @@ class WorkerServiceImpl final : public WorkerService::Service {
|
|||
store_->assertStorePath(drv_path);
|
||||
auto drv = BasicDerivation::from_proto(&request->derivation(), *store_);
|
||||
|
||||
auto build_mode = nix::build_mode_from(request->build_mode());
|
||||
auto build_mode = nix::BuildModeFrom(request->build_mode());
|
||||
if (!build_mode) {
|
||||
return Status(grpc::StatusCode::INTERNAL, "Invalid build mode");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue