diff --git a/src/nix/daemon.cc b/src/nix/daemon.cc
index 2cf2a04c9..6a40a0bd3 100644
--- a/src/nix/daemon.cc
+++ b/src/nix/daemon.cc
@@ -156,9 +156,6 @@ static void daemonLoop()
     if (chdir("/") == -1)
         throw SysError("cannot change current directory");
 
-    //  Get rid of children automatically; don't let them become zombies.
-    setSigChldAction(true);
-
     AutoCloseFD fdSocket;
 
     //  Handle socket-based activation by systemd.
@@ -176,6 +173,9 @@ static void daemonLoop()
         fdSocket = createUnixDomainSocket(settings.nixDaemonSocketFile, 0666);
     }
 
+    //  Get rid of children automatically; don't let them become zombies.
+    setSigChldAction(true);
+
     //  Loop accepting connections.
     while (1) {