From 1580857fde37af0dfe619753cee4f0a80f3b2148 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Sun, 27 Aug 2023 23:38:59 +0100 Subject: [PATCH] extract common "interface up" code to a string so that bridge service can use it --- pkgs/liminix-tools/networking/default.nix | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pkgs/liminix-tools/networking/default.nix b/pkgs/liminix-tools/networking/default.nix index f0349b4..bb39bcd 100644 --- a/pkgs/liminix-tools/networking/default.nix +++ b/pkgs/liminix-tools/networking/default.nix @@ -3,10 +3,20 @@ , liminix , ifwait , lib +, serviceFns }: let inherit (liminix.services) oneshot longrun; inherit (lib) concatStringsSep optional; + ifup = name : ifname : '' + . ${serviceFns} + ${ifwait}/bin/ifwait -v ${ifname} present + ip link set up dev ${ifname} + (in_outputs ${name} + echo ${ifname} > ifname + ) + ''; + in { interface = { type ? "hardware", device, link ? null, primary ? null, id ? null, dependencies ? [] } @ args: let name = "${device}.link"; @@ -16,8 +26,7 @@ in { "ip link add name ${device} type bridge" ++ optional (type == "vlan") "ip link add link ${link} name ${device} type vlan id ${id}" - ++ ["${ifwait}/bin/ifwait -v ${device} present"] - ++ ["ip link set up dev ${device}"] + ++ [(ifup name device)] ++ optional (primary != null) "ip link set dev ${device} master ${primary.device}"; in oneshot { @@ -26,6 +35,7 @@ in { down = "ip link set down dev ${device}"; dependencies = dependencies ++ lib.optional (primary != null) primary; }; + inherit ifup; address = interface: { family, dependencies ? [], prefixLength, address } @ args: let inherit (builtins) toString; in oneshot {