extract common "interface up" code to a string

so that bridge service can use it
This commit is contained in:
Daniel Barlow 2023-08-27 23:38:59 +01:00
parent 04b59536d8
commit 1580857fde

View file

@ -3,10 +3,20 @@
, liminix , liminix
, ifwait , ifwait
, lib , lib
, serviceFns
}: }:
let let
inherit (liminix.services) oneshot longrun; inherit (liminix.services) oneshot longrun;
inherit (lib) concatStringsSep optional; 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 { in {
interface = { type ? "hardware", device, link ? null, primary ? null, id ? null, dependencies ? [] } @ args: interface = { type ? "hardware", device, link ? null, primary ? null, id ? null, dependencies ? [] } @ args:
let name = "${device}.link"; let name = "${device}.link";
@ -16,8 +26,7 @@ in {
"ip link add name ${device} type bridge" "ip link add name ${device} type bridge"
++ optional (type == "vlan") ++ optional (type == "vlan")
"ip link add link ${link} name ${device} type vlan id ${id}" "ip link add link ${link} name ${device} type vlan id ${id}"
++ ["${ifwait}/bin/ifwait -v ${device} present"] ++ [(ifup name device)]
++ ["ip link set up dev ${device}"]
++ optional (primary != null) ++ optional (primary != null)
"ip link set dev ${device} master ${primary.device}"; "ip link set dev ${device} master ${primary.device}";
in oneshot { in oneshot {
@ -26,6 +35,7 @@ in {
down = "ip link set down dev ${device}"; down = "ip link set down dev ${device}";
dependencies = dependencies ++ lib.optional (primary != null) primary; dependencies = dependencies ++ lib.optional (primary != null) primary;
}; };
inherit ifup;
address = interface: { family, dependencies ? [], prefixLength, address } @ args: address = interface: { family, dependencies ? [], prefixLength, address } @ args:
let inherit (builtins) toString; let inherit (builtins) toString;
in oneshot { in oneshot {