service.nix (1285B)
1 { 2 liminix 3 , dnsmasq 4 , serviceFns 5 , lib 6 }: 7 { 8 interface 9 , user 10 , domain 11 , group 12 , ranges 13 , hosts 14 , upstreams 15 , resolvconf 16 }: 17 let 18 name = "${interface.name}.dnsmasq"; 19 inherit (liminix.services) longrun; 20 inherit (lib) concatStrings concatStringsSep mapAttrsToList; 21 hostOpt = name : { mac, v4, v6, leasetime } @ attrs: 22 let v6s = concatStrings (map (a : ",[${a}]") v6); 23 in "--dhcp-host=${mac},${v4}${v6s},${name},${builtins.toString leasetime}"; 24 in 25 longrun { 26 inherit name; 27 dependencies = [ interface ]; 28 run = '' 29 . ${serviceFns} 30 ${dnsmasq}/bin/dnsmasq \ 31 --user=${user} \ 32 --domain=${domain} \ 33 --group=${group} \ 34 --interface=$(output ${interface} ifname) \ 35 ${lib.concatStringsSep " " (builtins.map (r: "--dhcp-range=${r}") ranges)} \ 36 ${lib.concatStringsSep " " (builtins.map (r: "--server=${r}") upstreams)} \ 37 --keep-in-foreground \ 38 --dhcp-authoritative \ 39 ${if resolvconf != null then "--resolv-file=$(output_path ${resolvconf} resolv.conf)" else "--no-resolv"} \ 40 ${lib.concatStringsSep " " (mapAttrsToList hostOpt hosts)} \ 41 --no-hosts \ 42 --log-dhcp \ 43 --enable-ra \ 44 --log-debug \ 45 --log-queries \ 46 --log-facility=- \ 47 --dhcp-leasefile=/run/${name}.leases \ 48 --pid-file=/run/${name}.pid 49 ''; 50 }