liminix

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

address.nix (748B)


      1 {
      2   liminix,
      3   serviceFns,
      4   lib,
      5 }:
      6 {
      7   interface,
      8   family,
      9   address,
     10   prefixLength,
     11 }:
     12 let
     13   inherit (liminix.services) oneshot;
     14   # rather depending on the assumption that nobody will
     15   # ever add two addresses which are the same but with different
     16   # prefixes, or the same but different protocols
     17   name = "${interface.name}.a.${address}";
     18   up = ''
     19     dev=$(output ${interface} ifname)
     20     ip address add ${address}/${toString prefixLength} dev $dev
     21     (in_outputs ${name}
     22      echo ${address} > address
     23      echo ${toString prefixLength} > prefix-length
     24      echo ${family} > family
     25      echo $dev > ifname
     26     )
     27   '';
     28 in
     29 oneshot {
     30   inherit name up;
     31   down = "true"; # this has been broken for ~ ages
     32   dependencies = [ interface ];
     33 }