liminix

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

route.nix (599B)


      1 {
      2   liminix
      3 , ifwait
      4 , serviceFns
      5 , lib
      6 }:
      7 { target, via, interface ? null, metric }:
      8 let
      9   inherit (liminix.services) oneshot;
     10   with_dev = if interface != null then "dev $(output ${interface} ifname)" else "";
     11 in oneshot {
     12   name = "route-${target}-${builtins.substring 0 12 (builtins.hashString "sha256" "${via}-${if interface!=null then interface.name else ""}")}";
     13   up = ''
     14     ip route add ${target} via ${via} metric ${toString metric} ${with_dev}
     15   '';
     16   down = ''
     17     ip route del ${target} via ${via} ${with_dev}
     18   '';
     19   dependencies = [] ++ lib.optional (interface != null) interface;
     20 }