about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2020-07-16T22·34+0100
committertazjin <mail@tazj.in>2020-07-16T22·48+0000
commitbb66262068d0fbc495adfd7ab49ba10ab7a2c608 (patch)
treead8b58107120e2e7a908412265e5fe5d0331fb71
parentf1aa62c9ee5871cef263d140703d7b7208d51055 (diff)
feat(3p/nix/nix-daemon): Implement Worker::IsValidPath handler r/1338
Change-Id: I741c2b9b58f234a21850640e2b0c071ff4441234
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1223
Tested-by: BuildkiteCI
Reviewed-by: lukegb <lukegb@tvl.fyi>
Reviewed-by: glittershark <grfn@gws.fyi>
-rw-r--r--third_party/nix/src/CMakeLists.txt1
-rw-r--r--third_party/nix/src/nix-daemon/nix-daemon-proto.cc29
2 files changed, 30 insertions, 0 deletions
diff --git a/third_party/nix/src/CMakeLists.txt b/third_party/nix/src/CMakeLists.txt
index 3f30b1672562..05386fa2dd7c 100644
--- a/third_party/nix/src/CMakeLists.txt
+++ b/third_party/nix/src/CMakeLists.txt
@@ -58,6 +58,7 @@ target_sources(nix
     nix-collect-garbage/nix-collect-garbage.cc
     nix-copy-closure/nix-copy-closure.cc
     nix-daemon/nix-daemon.cc
+    nix-daemon/nix-daemon-proto.cc
     nix-env/nix-env.cc
     nix-env/user-env.cc
     nix-instantiate/nix-instantiate.cc
diff --git a/third_party/nix/src/nix-daemon/nix-daemon-proto.cc b/third_party/nix/src/nix-daemon/nix-daemon-proto.cc
new file mode 100644
index 000000000000..35171c769ab8
--- /dev/null
+++ b/third_party/nix/src/nix-daemon/nix-daemon-proto.cc
@@ -0,0 +1,29 @@
+#include "libproto/worker.grpc.pb.h"
+#include "libproto/worker.pb.h"
+#include "libstore/store-api.hh"
+
+namespace nix::daemon {
+
+using ::grpc::Status;
+using ::nix::proto::StorePath;
+using ::nix::proto::Worker;
+
+class WorkerServiceImpl final : public Worker::Service {
+ public:
+  WorkerServiceImpl(nix::Store* store) : store_(store) {}
+
+  Status IsValidPath(grpc::ServerContext* context, const StorePath* request,
+                     nix::proto::IsValidPathResponse* response) {
+    const auto& path = request->path();
+    store_->assertStorePath(path);
+    response->set_is_valid(store_->isValidPath(path));
+
+    return Status::OK;
+  }
+
+ private:
+  // TODO(tazjin): Who owns the store?
+  nix::Store* store_;
+};
+
+}  // namespace nix::daemon