diff options
Diffstat (limited to 'third_party/nix/src')
-rw-r--r-- | third_party/nix/src/CMakeLists.txt | 3 | ||||
-rw-r--r-- | third_party/nix/src/nix-daemon/CMakeLists.txt | 26 | ||||
-rw-r--r-- | third_party/nix/src/nix-daemon/nix-daemon.cc (renamed from third_party/nix/src/nix-daemon/nix-daemon-main.cc) | 50 |
3 files changed, 46 insertions, 33 deletions
diff --git a/third_party/nix/src/CMakeLists.txt b/third_party/nix/src/CMakeLists.txt index a142bfafb463..486c69fa2a3c 100644 --- a/third_party/nix/src/CMakeLists.txt +++ b/third_party/nix/src/CMakeLists.txt @@ -10,6 +10,7 @@ add_subdirectory(libutil) add_subdirectory(libstore) add_subdirectory(libmain) add_subdirectory(libexpr) +add_subdirectory(nix-daemon) if (PACKAGE_TESTS) add_subdirectory(tests) @@ -61,8 +62,6 @@ target_sources(nix nix-channel/nix-channel.cc nix-collect-garbage/nix-collect-garbage.cc nix-copy-closure/nix-copy-closure.cc - nix-daemon/nix-daemon-proto.cc - nix-daemon/nix-daemon-main.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/CMakeLists.txt b/third_party/nix/src/nix-daemon/CMakeLists.txt new file mode 100644 index 000000000000..27a4a1254e77 --- /dev/null +++ b/third_party/nix/src/nix-daemon/CMakeLists.txt @@ -0,0 +1,26 @@ +# -*- mode: cmake; -*- + +# The nix-daemon is the binary running the gRPC server component to +# which other components of Nix talk to perform store and builder +# operations. + +add_executable(nix-daemon) +include_directories(${PROJECT_BINARY_DIR}) # for config.h +set_property(TARGET nix-daemon PROPERTY CXX_STANDARD 17) + +target_sources(nix-daemon + PRIVATE + nix-daemon-proto.hh + nix-daemon-proto.cc + nix-daemon.cc +) + +target_link_libraries(nix-daemon + nixutil + nixstore + nixmain + absl::flags + absl::flags_parse +) + +install(TARGETS nix-daemon DESTINATION bin) diff --git a/third_party/nix/src/nix-daemon/nix-daemon-main.cc b/third_party/nix/src/nix-daemon/nix-daemon.cc index e492c343b900..02b350c3d87b 100644 --- a/third_party/nix/src/nix-daemon/nix-daemon-main.cc +++ b/third_party/nix/src/nix-daemon/nix-daemon.cc @@ -1,5 +1,8 @@ #include <filesystem> +#include <absl/flags/flag.h> +#include <absl/flags/parse.h> +#include <absl/flags/usage_config.h> #include <absl/strings/str_format.h> #include <fcntl.h> #include <glog/logging.h> @@ -9,7 +12,7 @@ #include <sys/socket.h> #include <sys/un.h> -#include "libmain/shared.hh" +#include "libmain/shared.hh" // TODO(tazjin): can this be removed? #include "libstore/globals.hh" #include "libstore/store-api.hh" #include "libutil/util.hh" @@ -17,6 +20,8 @@ #include "nix-daemon/nix-daemon-proto.hh" #include "nix/legacy.hh" +ABSL_FLAG(bool, pipe, false, "Use pipes for daemon communication"); + namespace nix::daemon { using grpc::Server; @@ -105,39 +110,22 @@ int RunServer() { } } -static int main_(int argc, char** argv) { - auto pipe = false; - - // TODO(grfn): Replace with absl::flags - parseCmdLine(argc, argv, - [&](Strings::iterator& arg, const Strings::iterator& end) { - if (*arg == "--help") { - showManPage("nix-daemon"); - } else if (*arg == "--version") { - printVersion("nix-daemon"); - } else if (*arg == "--pipe") { - // Causes the daemon to forward stdin and stdout to and from - // the actual daemon socket - pipe = true; - } else { - return false; - } - return true; - }); - - if (pipe) { - if (getStoreType() == tDaemon) { - return ForwardToSocket(settings.nixDaemonSocketFile); +} // namespace nix::daemon + +int main(int argc, char** argv) { + absl::SetFlagsUsageConfig({.version_string = [] { return nix::nixVersion; }}); + absl::ParseCommandLine(argc, argv); + + if (absl::GetFlag(FLAGS_pipe)) { + if (nix::getStoreType() == nix::tDaemon) { + return nix::daemon::ForwardToSocket(nix::settings.nixDaemonSocketFile); } else { // TODO(grfn): Need to launch a server on stdin here - upstream calls // processConnection(true, "root", 0); - throw "Not implemented"; + LOG(ERROR) << "not implemented"; + return 1; } } - return RunServer(); -} - -// TODO(grfn): Replace this with something less magical -static RegisterLegacyCommand s1("nix-daemon", main_); -} // namespace nix::daemon + return nix::daemon::RunServer(); +} |