blob: 6cd927c4b55a8a1a3217e55610998c35d1b51e90 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# TODO kill this in favor of unbound
{ config, lib, mylib, ... }: let
cfg = config.tv.dnsmasq;
in {
options.tv.dnsmasq = {
enable = lib.mkEnableOption "tv.dnsmasq";
dhcp-range = lib.mkOption {
type = lib.types.str;
};
interface = lib.mkOption {
type = lib.types.str;
};
address = lib.mkOption {
type = lib.types.str;
};
prefixLength = lib.mkOption {
type = lib.types.addCheck lib.types.int (x: x >= 0 && x <= 32);
};
};
config = lib.mkIf cfg.enable (lib.mkMerge [
{
networking.dhcpcd.denyInterfaces = [ cfg.interface ];
services.dnsmasq.resolveLocalQueries = false;
networking.interfaces.${cfg.interface} = {
ipv4.addresses = [
{
address = cfg.address;
prefixLength = cfg.prefixLength;
}
];
};
services.dnsmasq.enable = true;
services.dnsmasq.extraConfig = ''
bind-interfaces
dhcp-range=${cfg.dhcp-range}
listen-address=${cfg.address}
'';
hrm.nftables.tables.filter.chains.input.rules.dnsmasq = {
order = 1500;
iifname = cfg.interface;
tcp.dport = [ "bootps" "domain" ];
udp.dport = [ "bootps" "domain" ];
verdict = "accept";
};
}
{
# enable forwarding
boot.kernel.sysctl."net.ipv4.ip_forward" = true;
hrm.nftables.tables.filter.chains.forward.rules.dnsmasq = {
iifname = cfg.interface;
verdict = "accept";
};
hrm.nftables.tables.nat.chains.postrouting.rules.dnsmasq = {
verdict = "masquerade";
};
}
]);
}
|