liminix/modules/bridge/members.nix
Raito Bezarius 0fb671023c feat(services): introduce structured bundles
Structured bundles keep their original contents as a `passthru` field
named `components`.

This enable users to depend on a specific piece of the bundle instead of
the whole bundle.

Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
2024-09-05 14:54:12 +02:00

28 lines
744 B
Nix

{
liminix
, ifwait
, lib
, svc
}:
{ members, primary } :
let
inherit (liminix.services) structuredBundle oneshot;
inherit (lib) mapAttrs;
addif = name: { dependencies ? [ ], member }: oneshot {
name = "${primary.name}.member.${name}";
up = ''
echo "attaching $(output ${member} ifname) to $(output ${primary} ifname) bridge"
ip link set dev $(output ${member} ifname) master $(output ${primary} ifname)
'';
down = ''
echo "detaching $(output ${member} ifname) from any bridge"
ip link set dev $(output ${member} ifname) nomaster
'';
dependencies = [ primary member ] ++ dependencies;
};
in structuredBundle {
name = "${primary.name}.members";
contents = mapAttrs addif members;
}