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