about summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorRobert Hensing <robert@roberthensing.nl>2022-02-20 13:44:13 +0100
committerRobert Hensing <robert@roberthensing.nl>2022-02-20 13:44:13 +0100
commitb550b4b6f8413c086a1ec4235e174cda82538e73 (patch)
treee93a65fcd2f80686edda9967d8974ee08d0820ac /nixos
parent94f61e4c82834ca5c79384bc35853d6841583664 (diff)
downloadnixlib-b550b4b6f8413c086a1ec4235e174cda82538e73.tar
nixlib-b550b4b6f8413c086a1ec4235e174cda82538e73.tar.gz
nixlib-b550b4b6f8413c086a1ec4235e174cda82538e73.tar.bz2
nixlib-b550b4b6f8413c086a1ec4235e174cda82538e73.tar.lz
nixlib-b550b4b6f8413c086a1ec4235e174cda82538e73.tar.xz
nixlib-b550b4b6f8413c086a1ec4235e174cda82538e73.tar.zst
nixlib-b550b4b6f8413c086a1ec4235e174cda82538e73.zip
nixos/nix-daemon: Ensure continued availability of daemon socket
As `nix-daemon.service` does not make use of `ExecStop`, we prefer
to keep the socket up and available. This is important for machines
that run Nix-based services, such as automated build, test, and deploy
services, that expect the daemon socket to be available at all times.

See committed inline comment for further explanation.
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/services/misc/nix-daemon.nix34
1 files changed, 34 insertions, 0 deletions
diff --git a/nixos/modules/services/misc/nix-daemon.nix b/nixos/modules/services/misc/nix-daemon.nix
index a401458c4169..d27abfb76eb9 100644
--- a/nixos/modules/services/misc/nix-daemon.nix
+++ b/nixos/modules/services/misc/nix-daemon.nix
@@ -730,6 +730,40 @@ in
           };
 
         restartTriggers = [ nixConf ];
+
+        # `stopIfChanged = false` changes to switch behavior
+        # from   stop -> update units -> start
+        #   to   update units -> restart
+        #
+        # The `stopIfChanged` setting therefore controls a trade-off between a
+        # more predictable lifecycle, which runs the correct "version" of
+        # the `ExecStop` line, and on the other hand the availability of
+        # sockets during the switch, as the effectiveness of the stop operation
+        # depends on the socket being stopped as well.
+        #
+        # As `nix-daemon.service` does not make use of `ExecStop`, we prefer
+        # to keep the socket up and available. This is important for machines
+        # that run Nix-based services, such as automated build, test, and deploy
+        # services, that expect the daemon socket to be available at all times.
+        #
+        # Notably, the Nix client does not retry on failure to connect to the
+        # daemon socket, and the in-process RemoteStore instance will disable
+        # itself. This makes retries infeasible even for services that are
+        # aware of the issue. Failure to connect can affect not only new client
+        # processes, but also new RemoteStore instances in existing processes,
+        # as well as existing RemoteStore instances that have not saturated
+        # their connection pool.
+        #
+        # Also note that `stopIfChanged = true` does not kill existing
+        # connection handling daemons, as one might wish to happen before a
+        # breaking Nix upgrade (which is rare). The daemon forks that handle
+        # the individual connections split off into their own sessions, causing
+        # them not to be stopped by systemd.
+        # If a Nix upgrade does require all existing daemon processes to stop,
+        # nix-daemon must do so on its own accord, and only when the new version
+        # starts and detects that Nix's persistent state needs an upgrade.
+        stopIfChanged = false;
+
       };
 
     # Set up the environment variables for running Nix.