about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGriffin Smith <grfn@gws.fyi>2020-07-17T00·28-0400
committerglittershark <grfn@gws.fyi>2020-07-17T20·37+0000
commiteb4c8717cdeeaa93f24d2c3aeca075e6928d15e5 (patch)
tree1efc55d06b247d215c79ecd3f04a0f1771a1acf8
parent80eaa1eaf9dde0caa4e983374fb1356aed67c8e1 (diff)
feat(3p/nix/nix-daemon): Implement Worker::QueryPathInfo handler r/1355
Change-Id: I580bd29356f7bcd0cc2050afda11d2e115d44c94
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1230
Tested-by: BuildkiteCI
Reviewed-by: tazjin <mail@tazj.in>
-rw-r--r--third_party/nix/src/nix-daemon/nix-daemon-proto.cc40
-rw-r--r--third_party/nix/src/proto/worker.proto2
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 85c9a7bc14..1783867308 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 6d4b2a9547..90af308f85 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;