2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2011-04-13 15:09:02 +01:00
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
with lib;
|
2011-04-13 15:09:02 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.dnsmasq;
|
|
|
|
dnsmasq = pkgs.dnsmasq;
|
|
|
|
|
2012-11-12 16:58:48 +00:00
|
|
|
dnsmasqConf = pkgs.writeText "dnsmasq.conf" ''
|
2014-07-02 23:59:35 +01:00
|
|
|
${optionalString cfg.resolveLocalQueries ''
|
|
|
|
conf-file=/etc/dnsmasq-conf.conf
|
|
|
|
resolv-file=/etc/dnsmasq-resolv.conf
|
|
|
|
''}
|
2014-09-02 23:36:25 +01:00
|
|
|
${flip concatMapStrings cfg.servers (server: ''
|
|
|
|
server=${server}
|
|
|
|
'')}
|
|
|
|
${cfg.extraConfig}
|
2012-11-12 16:58:48 +00:00
|
|
|
'';
|
|
|
|
|
2011-04-13 15:09:02 +01:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2011-04-13 15:09:02 +01:00
|
|
|
options = {
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2011-04-13 15:09:02 +01:00
|
|
|
services.dnsmasq = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
2011-04-19 14:37:31 +01:00
|
|
|
default = false;
|
2011-04-13 15:09:02 +01:00
|
|
|
description = ''
|
|
|
|
Whether to run dnsmasq.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-07-02 23:59:35 +01:00
|
|
|
resolveLocalQueries = mkOption {
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether dnsmasq should resolve local queries (i.e. add 127.0.0.1 to
|
|
|
|
/etc/resolv.conf)
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2011-04-13 15:09:02 +01:00
|
|
|
servers = mkOption {
|
|
|
|
default = [];
|
|
|
|
example = [ "8.8.8.8" "8.8.4.4" ];
|
|
|
|
description = ''
|
2014-09-03 17:03:03 +01:00
|
|
|
The DNS servers which dnsmasq should query.
|
2011-04-13 15:09:02 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2012-11-12 16:58:48 +00:00
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.string;
|
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
Extra configuration directives that should be added to
|
|
|
|
<literal>dnsmasq.conf</literal>
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2011-04-13 15:09:02 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf config.services.dnsmasq.enable {
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2014-09-02 23:36:25 +01:00
|
|
|
networking.nameservers =
|
|
|
|
optional cfg.resolveLocalQueries "127.0.0.1";
|
2011-04-13 15:09:02 +01:00
|
|
|
|
2014-07-02 23:59:35 +01:00
|
|
|
services.dbus.packages = [ dnsmasq ];
|
2011-04-13 15:09:02 +01:00
|
|
|
|
2014-07-02 23:59:35 +01:00
|
|
|
users.extraUsers = singleton
|
|
|
|
{ name = "dnsmasq";
|
|
|
|
uid = config.ids.uids.dnsmasq;
|
|
|
|
description = "Dnsmasq daemon user";
|
|
|
|
home = "/var/empty";
|
2011-04-13 15:09:02 +01:00
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2014-07-02 23:59:35 +01:00
|
|
|
systemd.services.dnsmasq = {
|
|
|
|
description = "dnsmasq daemon";
|
2014-11-19 21:11:30 +00:00
|
|
|
after = [ "network.target" "systemd-resolved.conf" ];
|
2014-07-02 23:59:35 +01:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2014-09-02 23:36:25 +01:00
|
|
|
path = [ dnsmasq ];
|
|
|
|
preStart = ''
|
|
|
|
touch /etc/dnsmasq-{conf,resolv}.conf
|
|
|
|
dnsmasq --test
|
|
|
|
'';
|
2014-07-02 23:59:35 +01:00
|
|
|
serviceConfig = {
|
|
|
|
Type = "dbus";
|
|
|
|
BusName = "uk.org.thekelleys.dnsmasq";
|
|
|
|
ExecStart = "${dnsmasq}/bin/dnsmasq -k --enable-dbus --user=dnsmasq -C ${dnsmasqConf}";
|
|
|
|
ExecReload = "${dnsmasq}/bin/kill -HUP $MAINPID";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2011-04-13 15:09:02 +01:00
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2011-04-13 15:09:02 +01:00
|
|
|
}
|