1{ config, lib, pkgs, ... }:
2
3with lib;
4
5{
6 ###### interface
7
8 options = {
9 services.tinydns = {
10 enable = mkOption {
11 default = false;
12 type = types.bool;
13 description = lib.mdDoc "Whether to run the tinydns dns server";
14 };
15
16 data = mkOption {
17 type = types.lines;
18 default = "";
19 description = lib.mdDoc "The DNS data to serve, in the format described by tinydns-data(8)";
20 };
21
22 ip = mkOption {
23 default = "0.0.0.0";
24 type = types.str;
25 description = lib.mdDoc "IP address on which to listen for connections";
26 };
27 };
28 };
29
30 ###### implementation
31
32 config = mkIf config.services.tinydns.enable {
33 environment.systemPackages = [ pkgs.djbdns ];
34
35 users.users.tinydns = {
36 isSystemUser = true;
37 group = "tinydns";
38 };
39 users.groups.tinydns = {};
40
41 systemd.services.tinydns = {
42 description = "djbdns tinydns server";
43 wantedBy = [ "multi-user.target" ];
44 after = [ "network.target" ];
45 path = with pkgs; [ daemontools djbdns ];
46 preStart = ''
47 rm -rf /var/lib/tinydns
48 tinydns-conf tinydns tinydns /var/lib/tinydns ${config.services.tinydns.ip}
49 cd /var/lib/tinydns/root/
50 ln -sf ${pkgs.writeText "tinydns-data" config.services.tinydns.data} data
51 tinydns-data
52 '';
53 script = ''
54 cd /var/lib/tinydns
55 exec ./run
56 '';
57 };
58 };
59}