2023-09-01 00:24:23 +02:00
|
|
|
{
|
|
|
|
liminix
|
|
|
|
, ifwait
|
|
|
|
, serviceFns
|
|
|
|
, lib
|
|
|
|
}:
|
|
|
|
{ target, via, interface ? null, metric }:
|
|
|
|
let
|
|
|
|
inherit (liminix.services) oneshot;
|
2023-09-13 19:01:50 +02:00
|
|
|
with_dev = if interface != null then "dev $(output ${interface} ifname)" else "";
|
2023-09-01 00:24:23 +02:00
|
|
|
in oneshot {
|
|
|
|
name = "route-${target}-${builtins.substring 0 12 (builtins.hashString "sha256" "${via}-${if interface!=null then interface.name else ""}")}";
|
|
|
|
up = ''
|
|
|
|
ip route add ${target} via ${via} metric ${toString metric} ${with_dev}
|
|
|
|
'';
|
|
|
|
down = ''
|
|
|
|
ip route del ${target} via ${via} ${with_dev}
|
|
|
|
'';
|
|
|
|
dependencies = [] ++ lib.optional (interface != null) interface;
|
|
|
|
}
|