at 18.09-beta 2.1 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 7 nssModulesPath = config.system.nssModules.path; 8 cfg = config.services.nscd; 9 10in 11 12{ 13 14 ###### interface 15 16 options = { 17 18 services.nscd = { 19 20 enable = mkOption { 21 type = types.bool; 22 default = true; 23 description = "Whether to enable the Name Service Cache Daemon."; 24 }; 25 26 config = mkOption { 27 type = types.lines; 28 default = builtins.readFile ./nscd.conf; 29 description = "Configuration to use for Name Service Cache Daemon."; 30 }; 31 32 }; 33 34 }; 35 36 37 ###### implementation 38 39 config = mkIf cfg.enable { 40 environment.etc."nscd.conf".text = cfg.config; 41 42 users.users.nscd = 43 { isSystemUser = true; 44 description = "Name service cache daemon user"; 45 }; 46 47 systemd.services.nscd = 48 { description = "Name Service Cache Daemon"; 49 50 wantedBy = [ "nss-lookup.target" "nss-user-lookup.target" ]; 51 52 environment = { LD_LIBRARY_PATH = nssModulesPath; }; 53 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 61 restartTriggers = [ 62 config.environment.etc.hosts.source 63 config.environment.etc."nsswitch.conf".source 64 config.environment.etc."nscd.conf".source 65 ]; 66 67 serviceConfig = 68 { ExecStart = "@${pkgs.glibc.bin}/sbin/nscd nscd"; 69 Type = "forking"; 70 PIDFile = "/run/nscd/nscd.pid"; 71 Restart = "always"; 72 ExecReload = 73 [ "${pkgs.glibc.bin}/sbin/nscd --invalidate passwd" 74 "${pkgs.glibc.bin}/sbin/nscd --invalidate group" 75 "${pkgs.glibc.bin}/sbin/nscd --invalidate hosts" 76 ]; 77 }; 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 ''; 87 }; 88 89 }; 90}