liminix

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

link.nix (630B)


      1 {
      2   liminix
      3 , ifwait
      4 , serviceFns
      5 , lib
      6 }:
      7 {
      8   ifname
      9 , devpath ? null
     10 , mtu} :
     11 # if devpath is supplied, we rename the interface at that
     12 # path to have the specified name.
     13 let
     14   inherit (liminix.services) longrun oneshot;
     15   inherit (lib) concatStringsSep;
     16   name = "${ifname}.link";
     17   rename = if devpath != null
     18            then ''
     19              oldname=$(cd /sys${devpath} && cd net/ && echo *)
     20              ip link set ''${oldname} name ${ifname}
     21            ''
     22            else "";
     23 in oneshot {
     24   inherit name;
     25   up = ''
     26     ${rename}
     27     ${liminix.networking.ifup name ifname}
     28   '';
     29   down = "ip link set down dev ${ifname}";
     30 }