at 17.09-beta 2.3 kB view raw
1{ config, pkgs, lib, ... }: 2 3with lib; 4 5let 6 cfg = config.services.pdnsd; 7 pdnsd = pkgs.pdnsd; 8 pdnsdUser = "pdnsd"; 9 pdnsdGroup = "pdnsd"; 10 pdnsdConf = pkgs.writeText "pdnsd.conf" 11 '' 12 global { 13 run_as=${pdnsdUser}; 14 cache_dir="${cfg.cacheDir}"; 15 ${cfg.globalConfig} 16 } 17 18 server { 19 ${cfg.serverConfig} 20 } 21 ${cfg.extraConfig} 22 ''; 23in 24 25{ options = 26 { services.pdnsd = 27 { enable = mkEnableOption "pdnsd"; 28 29 cacheDir = mkOption { 30 type = types.str; 31 default = "/var/cache/pdnsd"; 32 description = "Directory holding the pdnsd cache"; 33 }; 34 35 globalConfig = mkOption { 36 type = types.lines; 37 default = ""; 38 description = '' 39 Global configuration that should be added to the global directory 40 of <literal>pdnsd.conf</literal>. 41 ''; 42 }; 43 44 serverConfig = mkOption { 45 type = types.lines; 46 default = ""; 47 description = '' 48 Server configuration that should be added to the server directory 49 of <literal>pdnsd.conf</literal>. 50 ''; 51 }; 52 53 extraConfig = mkOption { 54 type = types.lines; 55 default = ""; 56 description = '' 57 Extra configuration directives that should be added to 58 <literal>pdnsd.conf</literal>. 59 ''; 60 }; 61 }; 62 }; 63 64 config = mkIf cfg.enable { 65 users.extraUsers = singleton { 66 name = pdnsdUser; 67 uid = config.ids.uids.pdnsd; 68 group = pdnsdGroup; 69 description = "pdnsd user"; 70 }; 71 72 users.extraGroups = singleton { 73 name = pdnsdGroup; 74 gid = config.ids.gids.pdnsd; 75 }; 76 77 systemd.services.pdnsd = 78 { wantedBy = [ "multi-user.target" ]; 79 after = [ "network.target" ]; 80 preStart = 81 '' 82 mkdir -p "${cfg.cacheDir}" 83 touch "${cfg.cacheDir}/pdnsd.cache" 84 chown -R ${pdnsdUser}:${pdnsdGroup} "${cfg.cacheDir}" 85 ''; 86 description = "pdnsd"; 87 serviceConfig = 88 { 89 ExecStart = "${pdnsd}/bin/pdnsd -c ${pdnsdConf}"; 90 }; 91 }; 92 }; 93}