about summary refs log tree commit diff
path: root/third_party/nix/src/nix-daemon
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/nix/src/nix-daemon')
-rw-r--r--third_party/nix/src/nix-daemon/nix-daemon-proto.cc40
1 files changed, 40 insertions, 0 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;