@@ -39,11 +39,6 @@ in
3939 config = mkIf cfg.enable {
4040 environment.etc."nscd.conf".text = cfg.config;
4141
42− users.users.nscd =
43− { isSystemUser = true;
44− description = "Name service cache daemon user";
45− };
46−
4742 systemd.services.nscd =
4843 { description = "Name Service Cache Daemon";
4944
@@ -51,22 +46,23 @@ in
5146
5247 environment = { LD_LIBRARY_PATH = nssModulesPath; };
5348
54− preStart =
55− ''
56− mkdir -m 0755 -p /run/nscd
57− rm -f /run/nscd/nscd.pid
58− mkdir -m 0755 -p /var/db/nscd
59− '';
60−
6149 restartTriggers = [
6250 config.environment.etc.hosts.source
6351 config.environment.etc."nsswitch.conf".source
6452 config.environment.etc."nscd.conf".source
6553 ];
6654
55+ # We use DynamicUser because in default configurations nscd doesn't
56+ # create any files that need to survive restarts. However, in some
57+ # configurations, nscd needs to be started as root; it will drop
58+ # privileges after all the NSS modules have read their configuration
59+ # files. So prefix the ExecStart command with "!" to prevent systemd
60+ # from dropping privileges early. See ExecStart in systemd.service(5).
6761 serviceConfig =
68− { ExecStart = "@${pkgs.glibc.bin}/sbin/nscd nscd";
62+ { ExecStart = "!@${pkgs.glibc.bin}/sbin/nscd nscd";
6963 Type = "forking";
64+ DynamicUser = true;
65+ RuntimeDirectory = "nscd";
7066 PIDFile = "/run/nscd/nscd.pid";
7167 Restart = "always";
7268 ExecReload =
@@ -75,15 +71,6 @@ in
7571 "${pkgs.glibc.bin}/sbin/nscd --invalidate hosts"
7672 ];
7773 };
78−
79− # Urgggggh... Nscd forks before opening its socket and writing
80− # its pid. So wait until it's ready.
81− postStart =
82− ''
83− while ! ${pkgs.glibc.bin}/sbin/nscd -g > /dev/null; do
84− sleep 0.2
85− done
86− '';
8774 };
8875
8976 };