From 3b75cadb20b9f346b8752b39f05e98a67ce75442 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Fri, 24 Feb 2023 23:49:05 +0000 Subject: [PATCH] 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 --- pkgs/liminix-tools/networking/default.nix | 29 ++++++++++++++++------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/pkgs/liminix-tools/networking/default.nix b/pkgs/liminix-tools/networking/default.nix index b809843..b85b866 100644 --- a/pkgs/liminix-tools/networking/default.nix +++ b/pkgs/liminix-tools/networking/default.nix @@ -1,17 +1,28 @@ { callPackage , liminix +, lib }: -let inherit (liminix.services) oneshot longrun; +let + inherit (liminix.services) oneshot longrun; + inherit (lib) concatStringsSep optional; in { - interface = { type, device, dependencies ? [] } @ args: oneshot { - name = "${device}.link"; - up = "ip link set up dev ${device}"; - down = "ip link set down dev ${device}"; - inherit dependencies; - } // { - inherit device; - }; + interface = { type, device, primary ? null, dependencies ? [] } @ args: + let ups = + [] + ++ optional (type == "bridge") + "ip link add name ${device} type bridge" + ++ ["ip link set up dev ${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: let inherit (builtins) toString; in oneshot {