liminix

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

service.nix (1355B)


      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 =
     22     name:
     23     {
     24       mac,
     25       v4,
     26       v6,
     27       leasetime,
     28     }:
     29     let
     30       v6s = concatStrings (map (a: ",[${a}]") v6);
     31     in
     32     "--dhcp-host=${mac},${v4}${v6s},${name},${builtins.toString leasetime}";
     33 in
     34 longrun {
     35   inherit name;
     36   dependencies = [ interface ];
     37   run = ''
     38     ${dnsmasq}/bin/dnsmasq \
     39     --user=${user} \
     40     --domain=${domain} \
     41     --group=${group} \
     42     --interface=$(output ${interface} ifname) \
     43     ${lib.concatStringsSep " " (builtins.map (r: "--dhcp-range=${r}") ranges)} \
     44     ${lib.concatStringsSep " " (builtins.map (r: "--server=${r}") upstreams)} \
     45     --keep-in-foreground \
     46     --dhcp-authoritative \
     47     ${
     48       if resolvconf != null then
     49         "--resolv-file=$(output_path ${resolvconf} resolv.conf)"
     50       else
     51         "--no-resolv"
     52     } \
     53     ${lib.concatStringsSep " " (mapAttrsToList hostOpt hosts)} \
     54     --no-hosts \
     55     --log-dhcp \
     56     --enable-ra \
     57     --log-facility=- \
     58     --dhcp-leasefile=$(mkstate ${name})/leases \
     59     --pid-file=/run/${name}.pid
     60   '';
     61   # --log-debug \
     62   # --log-queries \
     63 
     64 }