1{ config, lib, pkgs, ... }:
2
3with lib;
4let
5 pkg = pkgs.nixops-dns;
6 cfg = config.services.nixops-dns;
7in
8
9{
10 options = {
11 services.nixops-dns = {
12 enable = mkOption {
13 type = types.bool;
14 default = false;
15 description = ''
16 Whether to enable the nixops-dns resolution
17 of NixOps virtual machines via dnsmasq and fake domain name.
18 '';
19 };
20
21 user = mkOption {
22 type = types.str;
23 description = ''
24 The user the nixops-dns daemon should run as.
25 This should be the user, which is also used for nixops and
26 have the .nixops directory in its home.
27 '';
28 };
29
30 domain = mkOption {
31 type = types.str;
32 description = ''
33 Fake domain name to resolve to NixOps virtual machines.
34
35 For example "ops" will resolve "vm.ops".
36 '';
37 example = "ops";
38 default = "ops";
39 };
40
41 dnsmasq = mkOption {
42 type = types.bool;
43 default = true;
44 description = ''
45 Enable dnsmasq forwarding to nixops-dns. This allows to use
46 nixops-dns for `services.nixops-dns.domain` resolution
47 while forwarding the rest of the queries to original resolvers.
48 '';
49 };
50
51 };
52 };
53
54 config = mkIf cfg.enable {
55 systemd.services.nixops-dns = {
56 description = "nixops-dns: DNS server for resolving NixOps machines";
57 wantedBy = [ "multi-user.target" ];
58
59 serviceConfig = {
60 Type = "simple";
61 User = cfg.user;
62 ExecStart="${pkg}/bin/nixops-dns --domain=.${cfg.domain}";
63 };
64 };
65
66 services.dnsmasq = mkIf cfg.dnsmasq {
67 enable = true;
68 resolveLocalQueries = true;
69 servers = [
70 "/${cfg.domain}/127.0.0.1#5300"
71 ];
72 extraConfig = ''
73 bind-interfaces
74 listen-address=127.0.0.1
75 '';
76 };
77
78 };
79}