diff options
-rw-r--r-- | third_party/nix/src/nix-daemon/nix-daemon-proto.cc | 40 | ||||
-rw-r--r-- | third_party/nix/src/proto/worker.proto | 2 |
2 files changed, 41 insertions, 1 deletions
diff --git a/third_party/nix/src/nix-daemon/nix-daemon-proto.cc b/third_party/nix/src/nix-daemon/nix-daemon-proto.cc index 85c9a7bc1467..178386730841 100644 --- a/third_party/nix/src/nix-daemon/nix-daemon-proto.cc +++ b/third_party/nix/src/nix-daemon/nix-daemon-proto.cc @@ -1,3 +1,6 @@ +#include <google/protobuf/util/time_util.h> +#include <grpcpp/impl/codegen/status_code_enum.h> + #include "libproto/worker.grpc.pb.h" #include "libproto/worker.pb.h" #include "libstore/store-api.hh" @@ -5,10 +8,14 @@ namespace nix::daemon { using ::grpc::Status; +using ::nix::proto::PathInfo; using ::nix::proto::StorePath; using ::nix::proto::StorePaths; using ::nix::proto::WorkerService; +static Status INVALID_STORE_PATH = + Status(grpc::StatusCode::INVALID_ARGUMENT, "Invalid store path"); + class WorkerServiceImpl final : public WorkerService::Service { public: WorkerServiceImpl(nix::Store* store) : store_(store) {} @@ -88,6 +95,39 @@ class WorkerServiceImpl final : public WorkerService::Service { return Status::OK; } + Status QueryPathInfo(grpc::ServerContext* context, const StorePath* request, + PathInfo* response) override { + auto path = request->path(); + try { + auto info = store_->queryPathInfo(path); + response->mutable_deriver()->set_path(info->deriver); + response->set_nar_hash( + reinterpret_cast<const char*>(&info->narHash.hash[0]), + info->narHash.hashSize); + + for (const auto& reference : info->references) { + response->add_references(reference); + } + + *response->mutable_registration_time() = + google::protobuf::util::TimeUtil::TimeTToTimestamp( + info->registrationTime); + + response->set_nar_size(info->narSize); + response->set_ultimate(info->ultimate); + + for (const auto& sig : info->sigs) { + response->add_sigs(sig); + } + + response->set_ca(info->ca); + + return Status::OK; + } catch (InvalidPath&) { + return Status(grpc::StatusCode::INVALID_ARGUMENT, "Invalid store path"); + } + } + Status QueryMissing(grpc::ServerContext* context, const StorePaths* request, nix::proto::QueryMissingResponse* response) override { std::set<Path> targets; diff --git a/third_party/nix/src/proto/worker.proto b/third_party/nix/src/proto/worker.proto index 6d4b2a9547f1..90af308f85dc 100644 --- a/third_party/nix/src/proto/worker.proto +++ b/third_party/nix/src/proto/worker.proto @@ -252,7 +252,7 @@ message CollectGarbageResponse { message PathInfo { StorePath deriver = 1; - string nar_hash = 2; + bytes nar_hash = 2; repeated string references = 3; google.protobuf.Timestamp registration_time = 4; uint64 nar_size = 5; |