implement route as module-based-service

This commit is contained in:
Daniel Barlow
2023-08-31 23:24:23 +01:00
parent 44c1fb7632
commit 3609d8d5ee
3 changed files with 48 additions and 10 deletions

20
modules/network/route.nix Normal file
View File

@@ -0,0 +1,20 @@
{
liminix
, ifwait
, serviceFns
, lib
}:
{ target, via, interface ? null, metric }:
let
inherit (liminix.services) oneshot;
with_dev = if interface != null then "dev $(input ${interface} ifname)" else "";
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;
}