liminix

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

route.nix (773B)


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