1{ config, pkgs, lib, ... }: 2 3with lib; 4 5let 6 cfg = config.services.skydns; 7 8in { 9 options.services.skydns = { 10 enable = mkEnableOption "skydns service"; 11 12 etcd = { 13 machines = mkOption { 14 default = [ "http://localhost:4001" ]; 15 type = types.listOf types.str; 16 description = "Skydns list of etcd endpoints to connect to."; 17 }; 18 19 tlsKey = mkOption { 20 default = null; 21 type = types.nullOr types.path; 22 description = "Skydns path of TLS client certificate - private key."; 23 }; 24 25 tlsPem = mkOption { 26 default = null; 27 type = types.nullOr types.path; 28 description = "Skydns path of TLS client certificate - public key."; 29 }; 30 31 caCert = mkOption { 32 default = null; 33 type = types.nullOr types.path; 34 description = "Skydns path of TLS certificate authority public key."; 35 }; 36 }; 37 38 address = mkOption { 39 default = "0.0.0.0:53"; 40 type = types.str; 41 description = "Skydns address to bind to."; 42 }; 43 44 domain = mkOption { 45 default = "skydns.local."; 46 type = types.str; 47 description = "Skydns default domain if not specified by etcd config."; 48 }; 49 50 nameservers = mkOption { 51 default = map (n: n + ":53") config.networking.nameservers; 52 type = types.listOf types.str; 53 description = "Skydns list of nameservers to forward DNS requests to when not authoritative for a domain."; 54 example = ["8.8.8.8:53" "8.8.4.4:53"]; 55 }; 56 57 package = mkOption { 58 default = pkgs.skydns; 59 defaultText = "pkgs.skydns"; 60 type = types.package; 61 description = "Skydns package to use."; 62 }; 63 64 extraConfig = mkOption { 65 default = {}; 66 type = types.attrsOf types.str; 67 description = "Skydns attribute set of extra config options passed as environemnt variables."; 68 }; 69 }; 70 71 config = mkIf (cfg.enable) { 72 systemd.services.skydns = { 73 wantedBy = [ "multi-user.target" ]; 74 after = [ "network.target" "etcd.service" ]; 75 description = "Skydns Service"; 76 environment = { 77 ETCD_MACHINES = concatStringsSep "," cfg.etcd.machines; 78 ETCD_TLSKEY = cfg.etcd.tlsKey; 79 ETCD_TLSPEM = cfg.etcd.tlsPem; 80 ETCD_CACERT = cfg.etcd.caCert; 81 SKYDNS_ADDR = cfg.address; 82 SKYDNS_DOMAIN = cfg.domain; 83 SKYDNS_NAMESERVERS = concatStringsSep "," cfg.nameservers; 84 }; 85 serviceConfig = { 86 ExecStart = "${cfg.package}/bin/skydns"; 87 }; 88 }; 89 90 environment.systemPackages = [ cfg.package ]; 91 }; 92}