forked from DGNum/liminix
shell-customization #4
4 changed files with 51 additions and 22 deletions
|
@ -20,6 +20,7 @@ in
|
||||||
system.service.bridge = {
|
system.service.bridge = {
|
||||||
primary = mkOption { type = liminix.lib.types.serviceDefn; };
|
primary = mkOption { type = liminix.lib.types.serviceDefn; };
|
||||||
members = mkOption { type = liminix.lib.types.serviceDefn; };
|
members = mkOption { type = liminix.lib.types.serviceDefn; };
|
||||||
|
ready = mkOption { type = liminix.lib.types.serviceDefn; };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
config.system.service.bridge = {
|
config.system.service.bridge = {
|
||||||
|
@ -46,6 +47,19 @@ in
|
||||||
description = "interfaces to add to the bridge";
|
description = "interfaces to add to the bridge";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# TODO: generalize it outside
|
||||||
|
ready = config.system.callService ./ready.nix {
|
||||||
|
primary = mkOption {
|
||||||
|
type = liminix.lib.types.service;
|
||||||
|
description = "primary bridge interface";
|
||||||
|
};
|
||||||
|
|
||||||
|
members = mkOption {
|
||||||
|
type = liminix.lib.types.service;
|
||||||
|
description = "members service";
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
config.kernel.config = {
|
config.kernel.config = {
|
||||||
BRIDGE = "y";
|
BRIDGE = "y";
|
||||||
|
|
|
@ -10,26 +10,19 @@ let
|
||||||
inherit (liminix.networking) interface;
|
inherit (liminix.networking) interface;
|
||||||
inherit (liminix.services) bundle oneshot;
|
inherit (liminix.services) bundle oneshot;
|
||||||
inherit (lib) mkOption types;
|
inherit (lib) mkOption types;
|
||||||
addif = member :
|
addif = member : oneshot {
|
||||||
# how do we get sight of services from here? maybe we need to
|
name = "${primary.name}.member.${member.name}";
|
||||||
# implement ifwait as a regualr derivation instead of a
|
up = ''
|
||||||
# servicedefinition
|
echo "attaching $(output ${member} ifname) to $(output ${primary} ifname) bridge"
|
||||||
svc.ifwait.build {
|
ip link set dev $(output ${member} ifname) master $(output ${primary} ifname)
|
||||||
state = "running";
|
'';
|
||||||
interface = member;
|
down = ''
|
||||||
dependencies = [ primary member ];
|
echo "detaching $(output ${member} ifname) from any bridge"
|
||||||
service = oneshot {
|
ip link set dev $(output ${member} ifname) nomaster
|
||||||
name = "${primary.name}.member.${member.name}";
|
'';
|
||||||
up = ''
|
|
||||||
echo "attaching $(output ${member} ifname) to $(output ${primary} ifname) bridge"
|
dependencies = [ primary member ];
|
||||||
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
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
};
|
|
||||||
in bundle {
|
in bundle {
|
||||||
name = "${primary.name}.members";
|
name = "${primary.name}.members";
|
||||||
contents = map addif members;
|
contents = map addif members;
|
||||||
|
|
|
@ -14,9 +14,13 @@ in oneshot rec {
|
||||||
"ip link add name ${ifname} type bridge"
|
"ip link add name ${ifname} type bridge"
|
||||||
else
|
else
|
||||||
"ip link add name ${ifname} address $(output ${macAddressFromInterface} ether) type bridge"}
|
"ip link add name ${ifname} address $(output ${macAddressFromInterface} ether) type bridge"}
|
||||||
${liminix.networking.ifup name ifname}
|
|
||||||
|
(in_outputs ${name}
|
||||||
|
echo ${ifname} > ifname
|
||||||
|
cat /sys/class/net/${ifname}/address > ether
|
||||||
|
)
|
||||||
'';
|
'';
|
||||||
down = "ip link set down dev ${ifname}";
|
down = "ip link delete ${ifname}";
|
||||||
|
|
||||||
dependencies = optional (macAddressFromInterface != null) macAddressFromInterface;
|
dependencies = optional (macAddressFromInterface != null) macAddressFromInterface;
|
||||||
}
|
}
|
||||||
|
|
18
modules/bridge/ready.nix
Normal file
18
modules/bridge/ready.nix
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
{
|
||||||
|
liminix
|
||||||
|
, ifwait
|
||||||
|
, lib
|
||||||
|
}:
|
||||||
|
{ primary, members } :
|
||||||
|
let
|
||||||
|
inherit (liminix.services) oneshot;
|
||||||
|
in oneshot {
|
||||||
|
name = "${primary.name}.oper";
|
||||||
|
up = ''
|
||||||
|
ip link set up dev $(output ${primary} ifname)
|
||||||
|
${ifwait}/bin/ifwait -v $(output ${primary} ifname) running
|
||||||
|
'';
|
||||||
|
down = "ip link set down dev $(output ${primary} ifname)";
|
||||||
|
|
||||||
|
dependencies = [ members ];
|
||||||
|
}
|
Loading…
Reference in a new issue