about summary refs log tree commit diff
path: root/third_party/nix/src/nix-daemon/nix-daemon.cc
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2020-08-03T18·05+0100
committertazjin <mail@tazj.in>2020-08-03T18·26+0000
commit1f12544179041b151f146fbb604e9af165ffe379 (patch)
treef1cba1958e25749cd9a85192c672d1ffb9aca82b /third_party/nix/src/nix-daemon/nix-daemon.cc
parent229c1ed820fe20515a69f749c38d5f9f89d20c8d (diff)
refactor(3p/nix): Build nix-daemon as a separate binary r/1569
Skips over all the monobinary stuff and moves to a separate binary for
nix-daemon.

This also replaces the flag parsing logic with absl::flags. This
causes a behaviour change for --help, which no longer tries to display
a man page but instead shows the actual command-line help.

Note: This binary no longer links to the Boehm GC.

Change-Id: Ib852e994b82f2d56e91262878c10650e656427a9
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1622
Tested-by: BuildkiteCI
Reviewed-by: glittershark <grfn@gws.fyi>
Diffstat (limited to '')
-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
1 files changed, 19 insertions, 31 deletions
diff --git a/third_party/nix/src/nix-daemon/nix-daemon-main.cc b/third_party/nix/src/nix-daemon/nix-daemon.cc
index e492c343b9..02b350c3d8 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();
+}