git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #64268 from jameysharp/nscd-dynamicuser

nixos/nscd: DynamicUser and other cleanups

commita0ba42e3f4e7de10de156707ef845e8a52525e0c authorNikolay Amiantov <ab@fmap.me> dateMon 22 Jul 2019, 16:23 (7 years ago) parent3c65adad79584c
2 files changed+9−40
nixos/modules/services/system/nscd.conf−18 nixos/modules/services/system/nscd.nix+9−22
nixos/modules/services/system/nscd.conf−18
@@ -7,46 +7,28 @@
77# is not aware of the path in which the nss modules live. As a workaround, we
88# have `enable-cache yes` with an explicit ttl of 0
99server-user nscd
10−threads 1
11−paranoia no
12−debug-level 0
1310
1411enable-cache passwd yes
1512positive-time-to-live passwd 0
1613negative-time-to-live passwd 0
17−suggested-size passwd 211
18−check-files passwd yes
19−persistent passwd no
2014shared passwd yes
2115
2216enable-cache group yes
2317positive-time-to-live group 0
2418negative-time-to-live group 0
25−suggested-size group 211
26−check-files group yes
27−persistent group no
2819shared group yes
2920
3021enable-cache netgroup yes
3122positive-time-to-live netgroup 0
3223negative-time-to-live netgroup 0
33−suggested-size netgroup 211
34−check-files netgroup yes
35−persistent netgroup no
3624shared netgroup yes
3725
3826enable-cache hosts yes
3927positive-time-to-live hosts 600
4028negative-time-to-live hosts 0
41−suggested-size hosts 211
42−check-files hosts yes
43−persistent hosts no
4429shared hosts yes
4530
4631enable-cache services yes
4732positive-time-to-live services 0
4833negative-time-to-live services 0
49−suggested-size services 211
50−check-files services yes
51−persistent services no
5234shared services yes
nixos/modules/services/system/nscd.nix+9−22
@@ -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 };