From 2646e57aae5aedc3d07d8596aa6a61048b312e54 Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Sat, 1 Aug 2020 15:44:48 -0400 Subject: fix(3p/nix): Prepend unix:// to daemon socket Prepend the unix:// URI scheme to the daemon socket so that grpc knows we want to connect to a unix socket rather than another type of URI. As part of debugging this I made the failure message for the RPCStore include the URI, which I'm leaving in since it'll be nice to have. Change-Id: I6e70596895117b9a0d53fe2a61d8542ceb64c940 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1543 Reviewed-by: kanepyork Tested-by: BuildkiteCI --- third_party/nix/src/libstore/rpc-store.cc | 5 ++-- third_party/nix/src/libstore/rpc-store.hh | 2 ++ third_party/nix/src/libstore/store-api.cc | 44 ++++++++++++++++--------------- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/third_party/nix/src/libstore/rpc-store.cc b/third_party/nix/src/libstore/rpc-store.cc index d1687473c1..080a1e0a5d 100644 --- a/third_party/nix/src/libstore/rpc-store.cc +++ b/third_party/nix/src/libstore/rpc-store.cc @@ -56,9 +56,10 @@ T FillFrom(const U& src) { // TODO(grfn): Obviously this should go away and be replaced by StatusOr... but // that would require refactoring the entire store api, which we don't feel like // doing right now. We should at some point though -void SuccessOrThrow(const grpc::Status& status) { +void const RpcStore::SuccessOrThrow(const grpc::Status& status) const { if (!status.ok()) { - throw Error(absl::StrFormat("Rpc call failed (%d): %s ", + throw Error(absl::StrFormat("Rpc call to %s failed (%d): %s ", + uri_.value_or("unknown URI"), status.error_code(), status.error_message())); } } diff --git a/third_party/nix/src/libstore/rpc-store.hh b/third_party/nix/src/libstore/rpc-store.hh index 332d1f4ba1..0ef24e22b7 100644 --- a/third_party/nix/src/libstore/rpc-store.hh +++ b/third_party/nix/src/libstore/rpc-store.hh @@ -137,6 +137,8 @@ class RpcStore : public LocalFSStore, public virtual Store { private: std::optional uri_; std::unique_ptr stub_; + + void const SuccessOrThrow(const grpc::Status& status) const; }; } // namespace nix::store diff --git a/third_party/nix/src/libstore/store-api.cc b/third_party/nix/src/libstore/store-api.cc index 96c6f93410..2598c4ce2e 100644 --- a/third_party/nix/src/libstore/store-api.cc +++ b/third_party/nix/src/libstore/store-api.cc @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -984,28 +985,29 @@ StoreType getStoreType(const std::string& uri, const std::string& stateDir) { } } -static RegisterStoreImplementation regStore( - [](const std::string& uri, - const Store::Params& params) -> std::shared_ptr { - switch (getStoreType(uri, get(params, "state", settings.nixStateDir))) { - case tDaemon: { - auto daemon_socket_uri = settings.nixDaemonSocketFile; - auto channel = grpc::CreateChannel( - daemon_socket_uri, grpc::InsecureChannelCredentials()); - return std::shared_ptr(std::make_shared( - params, proto::WorkerService::NewStub(channel))); - } - case tLocal: { - Store::Params params2 = params; - if (absl::StartsWith(uri, "/")) { - params2["root"] = uri; - } - return std::shared_ptr(std::make_shared(params2)); - } - default: - return nullptr; +static RegisterStoreImplementation regStore([](const std::string& uri, + const Store::Params& params) + -> std::shared_ptr { + switch (getStoreType(uri, get(params, "state", settings.nixStateDir))) { + case tDaemon: { + auto daemon_socket_uri = + absl::StrCat("unix://", settings.nixDaemonSocketFile); + auto channel = grpc::CreateChannel(daemon_socket_uri, + grpc::InsecureChannelCredentials()); + return std::shared_ptr(std::make_shared( + daemon_socket_uri, params, proto::WorkerService::NewStub(channel))); + } + case tLocal: { + Store::Params params2 = params; + if (absl::StartsWith(uri, "/")) { + params2["root"] = uri; } - }); + return std::shared_ptr(std::make_shared(params2)); + } + default: + return nullptr; + } +}); std::list> getDefaultSubstituters() { static auto stores([]() { -- cgit 1.4.1