summary refs log tree commit diff
path: root/nixos/modules/services/misc/nix-daemon.nix
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2022-03-18 16:22:38 +0100
committerFlorian Klink <flokli@flokli.de>2022-03-21 11:43:38 +0100
commit0d198e7a52c71db7b607bbcab91b3b28f7786587 (patch)
tree58c570cc1d7cd68ada6f0c79e117cd55036c952f /nixos/modules/services/misc/nix-daemon.nix
parentb94a60e451d379c5b78cc18f55f54b61330861df (diff)
downloadnixpkgs-0d198e7a52c71db7b607bbcab91b3b28f7786587.tar
nixpkgs-0d198e7a52c71db7b607bbcab91b3b28f7786587.tar.gz
nixpkgs-0d198e7a52c71db7b607bbcab91b3b28f7786587.tar.bz2
nixpkgs-0d198e7a52c71db7b607bbcab91b3b28f7786587.tar.lz
nixpkgs-0d198e7a52c71db7b607bbcab91b3b28f7786587.tar.xz
nixpkgs-0d198e7a52c71db7b607bbcab91b3b28f7786587.tar.zst
nixpkgs-0d198e7a52c71db7b607bbcab91b3b28f7786587.zip
nixos/nix-daemon: workaround NixOS/nix#6285
The Nix-provided `nix-daemon.socket` file has a

> ConditionPathIsReadWrite=/nix/var/nix/daemon-socket/socket

line, to skip that unit if /nix/var/nix/daemon-socket/socket is
read-only (which is the case in some nixos-containers with that folder
bind-ro-mounted from the host).

In these cases, the unit was skipped.

Systemd 250 (rightfully) started to also skip in these cases:

> [ 237.187747] systemd[1]: Nix Daemon Socket was skipped because of a failed condition check (ConditionPathIsReadWrite=/nix/var/nix/daemon-socket).

However, systemd < 250 didn't skip if /nix/var/nix/daemon-socket/socket
didn't /exist at all/, and we were relying on this bug in the case for
fresh NixOS systems, to have /nix/var/nix/daemon-socket/socket created
initially.

Move the creation of that folder to systemd-tmpfiles, by shipping an
appropriate file in `${nixPackage}/lib/tmpfiles.d/nix-daemon.conf`
(NixOS/nix#6285).

In the meantime, set a systemd tmpfiles rule manually in NixOS.

This has been tested to still work with read-only bind-mounted
/nix/var/nix/daemon-socket/socket in containers, it'll keep them
read-only ;-)
Diffstat (limited to 'nixos/modules/services/misc/nix-daemon.nix')
-rw-r--r--nixos/modules/services/misc/nix-daemon.nix8
1 files changed, 8 insertions, 0 deletions
diff --git a/nixos/modules/services/misc/nix-daemon.nix b/nixos/modules/services/misc/nix-daemon.nix
index 2b21df91b82..0c3435ce70b 100644
--- a/nixos/modules/services/misc/nix-daemon.nix
+++ b/nixos/modules/services/misc/nix-daemon.nix
@@ -708,6 +708,14 @@ in
 
     systemd.packages = [ nixPackage ];
 
+    # Will only work once https://github.com/NixOS/nix/pull/6285 is merged
+    # systemd.tmpfiles.packages = [ nixPackage ];
+
+    # Can be dropped for Nix > https://github.com/NixOS/nix/pull/6285
+    systemd.tmpfiles.rules = [
+      "d /nix/var/nix/daemon-socket 0755 root root - -"
+    ];
+
     systemd.sockets.nix-daemon.wantedBy = [ "sockets.target" ];
 
     systemd.services.nix-daemon =