liminix

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

service.nix (1460B)


      1 {
      2   liminix,
      3   dnsmasq,
      4   serviceFns,
      5   lib,
      6   svc,
      7 }:
      8 {
      9   interface,
     10   user,
     11   domain,
     12   group,
     13   ranges,
     14   hosts,
     15   upstreams,
     16   resolvconf,
     17 }:
     18 let
     19   name = "${interface.name}.dnsmasq";
     20   inherit (liminix.services) longrun;
     21   inherit (lib) concatStrings concatStringsSep mapAttrsToList;
     22   hostOpt =
     23     name:
     24     {
     25       mac,
     26       v4,
     27       v6,
     28       leasetime,
     29     }:
     30     let
     31       v6s = concatStrings (map (a: ",[${a}]") v6);
     32     in
     33     "--dhcp-host=${mac},${v4}${v6s},${name},${builtins.toString leasetime}";
     34   autoconfig = svc.ipv6.autoconfig.build {
     35     inherit interface;
     36     role = "router";
     37   };
     38 in
     39 longrun {
     40   inherit name;
     41   dependencies = [
     42     interface
     43     autoconfig
     44   ];
     45   run = ''
     46     ${dnsmasq}/bin/dnsmasq \
     47     --user=${user} \
     48     --domain=${domain} \
     49     --group=${group} \
     50     --interface=$(output ${interface} ifname) \
     51     --bind-interfaces \
     52     ${lib.concatStringsSep " " (builtins.map (r: "--dhcp-range=${r}") ranges)} \
     53     ${lib.concatStringsSep " " (builtins.map (r: "--server=${r}") upstreams)} \
     54     --keep-in-foreground \
     55     --dhcp-authoritative \
     56     ${
     57       if resolvconf != null then
     58         "--resolv-file=$(output_path ${resolvconf} resolv.conf)"
     59       else
     60         "--no-resolv"
     61     } \
     62     ${lib.concatStringsSep " " (mapAttrsToList hostOpt hosts)} \
     63     --no-hosts \
     64     --log-dhcp \
     65     --enable-ra \
     66     --log-facility=- \
     67     --dhcp-leasefile=$(mkstate ${name})/leases \
     68     --pid-file=/run/${name}.pid
     69   '';
     70 }