liminix

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

pppoe.nix (1409B)


      1 {
      2   liminix
      3 , lib
      4 , ppp
      5 , pppoe
      6 , writeAshScript
      7 , serviceFns
      8 } :
      9 let
     10   inherit (liminix.services) longrun;
     11   inherit (liminix.lib) typeChecked;
     12   inherit (lib) mkOption types;
     13 
     14   t = {
     15     interface = mkOption {
     16       type = liminix.lib.types.service;
     17       description = "ethernet interface to run PPPoE over";
     18     };
     19     ppp-options = mkOption {
     20       type = types.listOf types.str;
     21       description = "options supplied on ppp command line";
     22     };
     23   };
     24 in
     25 params:
     26 let
     27   inherit (typeChecked "pppoe.nix" t params) interface ppp-options;
     28   name = "${interface.device}.pppoe";
     29   ip-up = writeAshScript "ip-up" {} ''
     30     . ${serviceFns} 
     31     (in_outputs ${name}
     32      echo $1 > ifname
     33      echo $2 > tty
     34      echo $3 > speed
     35      echo $4 > address
     36      echo $5 > peer-address
     37      echo $DNS1 > ns1
     38      echo $DNS2 > ns2
     39     )
     40     echo >/proc/self/fd/10
     41   '';
     42   ip6-up = writeAshScript "ip6-up" {} ''
     43     . ${serviceFns} 
     44     (in_outputs ${name}
     45      echo $4 > ipv6-address
     46      echo $5 > ipv6-peer-address
     47     )
     48     echo >/proc/self/fd/10
     49   '';
     50   ppp-options' = ppp-options ++ [
     51     "ip-up-script" ip-up
     52     "ipv6-up-script" ip6-up
     53     "ipparam" name
     54     "nodetach"
     55     "usepeerdns"
     56     "logfd" "2"
     57   ];
     58 
     59 in
     60 longrun {
     61   inherit name;
     62   run = "${ppp}/bin/pppd pty '${pppoe}/bin/pppoe -I ${interface.device}' ${lib.concatStringsSep " " ppp-options'}" ;
     63   notification-fd = 10;
     64   dependencies = [ interface ];
     65 }