2
0
Files
liminix/modules/dnsmasq/service.nix
T

71 lines
1.4 KiB
Nix
Raw Normal View History

2022-09-28 21:33:18 +01:00
{
2025-02-10 21:55:08 +00:00
liminix,
dnsmasq,
serviceFns,
lib,
svc,
2022-09-28 21:33:18 +01:00
}:
{
2025-02-10 21:55:08 +00:00
interface,
user,
domain,
group,
ranges,
hosts,
upstreams,
resolvconf,
}:
2022-09-28 21:33:18 +01:00
let
2023-08-27 23:20:58 +01:00
name = "${interface.name}.dnsmasq";
2022-09-28 21:33:18 +01:00
inherit (liminix.services) longrun;
2023-09-04 22:06:53 +01:00
inherit (lib) concatStrings concatStringsSep mapAttrsToList;
2025-02-10 21:55:08 +00:00
hostOpt =
name:
{
mac,
v4,
v6,
leasetime,
}:
let
v6s = concatStrings (map (a: ",[${a}]") v6);
in
"--dhcp-host=${mac},${v4}${v6s},${name},${builtins.toString leasetime}";
autoconfig = svc.ipv6.autoconfig.build {
inherit interface;
role = "router";
};
2023-07-14 22:53:25 +01:00
in
longrun {
2022-09-28 21:33:18 +01:00
inherit name;
dependencies = [
interface
autoconfig
];
2022-09-28 21:33:18 +01:00
run = ''
${dnsmasq}/bin/dnsmasq \
--user=${user} \
--domain=${domain} \
--group=${group} \
2023-08-27 23:20:58 +01:00
--interface=$(output ${interface} ifname) \
2026-05-03 00:23:53 -07:00
--bind-interfaces \
2022-09-28 21:33:18 +01:00
${lib.concatStringsSep " " (builtins.map (r: "--dhcp-range=${r}") ranges)} \
${lib.concatStringsSep " " (builtins.map (r: "--server=${r}") upstreams)} \
--keep-in-foreground \
--dhcp-authoritative \
2025-02-10 21:55:08 +00:00
${
if resolvconf != null then
"--resolv-file=$(output_path ${resolvconf} resolv.conf)"
else
"--no-resolv"
} \
2023-09-04 22:06:53 +01:00
${lib.concatStringsSep " " (mapAttrsToList hostOpt hosts)} \
--no-hosts \
2022-09-28 21:33:18 +01:00
--log-dhcp \
--enable-ra \
--log-facility=- \
2024-02-13 21:54:45 +00:00
--dhcp-leasefile=$(mkstate ${name})/leases \
2022-09-28 21:33:18 +01:00
--pid-file=/run/${name}.pid
'';
}