liminix

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

service.nix (1580B)


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