improve bridge support

instead of a bridge specifiying its members (not ideal if they're
not all always up), the member interfaces specify their primary
This commit is contained in:
Daniel Barlow 2023-02-24 23:49:05 +00:00
parent 8194e909ac
commit 3b75cadb20

View file

@ -1,17 +1,28 @@
{ {
callPackage callPackage
, liminix , liminix
, lib
}: }:
let inherit (liminix.services) oneshot longrun; let
inherit (liminix.services) oneshot longrun;
inherit (lib) concatStringsSep optional;
in { in {
interface = { type, device, dependencies ? [] } @ args: oneshot { interface = { type, device, primary ? null, dependencies ? [] } @ args:
name = "${device}.link"; let ups =
up = "ip link set up dev ${device}"; []
down = "ip link set down dev ${device}"; ++ optional (type == "bridge")
inherit dependencies; "ip link add name ${device} type bridge"
} // { ++ ["ip link set up dev ${device}"]
inherit device; ++ optional (primary != null)
}; "ip link set dev ${device} master ${primary.device}";
in oneshot {
name = "${device}.link";
up = lib.concatStringsSep "\n" ups;
down = "ip link set down dev ${device}";
dependencies = dependencies ++ lib.optional (primary != null) primary;
} // {
inherit device;
};
address = interface: { family, prefixLength, address } @ args: address = interface: { family, prefixLength, address } @ args:
let inherit (builtins) toString; let inherit (builtins) toString;
in oneshot { in oneshot {