liminix

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

dhcpc.nix (1092B)


      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 || true) > $i
     21          done
     22          touch state)
     23     }
     24     case $action in
     25       deconfig)
     26         ip address flush $interface
     27         ip link set up dev $interface
     28         ;;
     29       bound)
     30         # this doesn't actually replace, it adds a new address.
     31         set_address
     32         # echo  >/proc/self/fd/10
     33         ;;
     34       renew)
     35         set_address
     36         ;;
     37       nak)
     38         echo "received NAK on $interface"
     39         ;;
     40     esac
     41   '';
     42 in
     43 longrun {
     44   inherit name;
     45   run = "exec /bin/udhcpc -n -A 15 -f -i $(output ${interface} ifname) -x hostname:$(cat /proc/sys/kernel/hostname) -s ${script}";
     46   dependencies = [ interface ];
     47 }