liminix

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

dhcpc.nix (1067B)


      1 {
      2   liminix
      3 , writeAshScript
      4 , serviceFns
      5 , lib
      6 } :
      7 { interface }:
      8 let
      9   inherit (liminix.services) longrun;
     10   name = "${interface.name}.dhcpc";
     11   script = writeAshScript "dhcp-notify"  { } ''
     12     . ${serviceFns}
     13     exec 2>&1
     14     action=$1
     15 
     16     set_address() {
     17         ip address replace $ip/$mask dev $interface
     18         (in_outputs ${name}
     19          for i in lease mask ip router siaddr dns serverid subnet opt53 interface ; do
     20             printenv $i > $i
     21          done)
     22     }
     23     case $action in
     24       deconfig)
     25         ip address flush $interface
     26         ip link set up dev $interface
     27         ;;
     28       bound)
     29         # this doesn't actually replace, it adds a new address.
     30         set_address
     31         echo  >/proc/self/fd/10
     32         ;;
     33       renew)
     34         set_address
     35         ;;
     36       nak)
     37         echo "received NAK on $interface"
     38         ;;
     39     esac
     40   '';
     41 in longrun {
     42   inherit name;
     43   run = "/bin/udhcpc -f -i $(output ${interface} ifname) -x hostname:$(cat /proc/sys/kernel/hostname) -s ${script}";
     44   notification-fd = 10;
     45   dependencies = [ interface ];
     46 }