merge bridge services into one

This commit is contained in:
Daniel Barlow 2023-08-16 19:44:00 +01:00
parent a019e59a80
commit 6f92f8fa8b
5 changed files with 23 additions and 45 deletions

View file

@ -79,18 +79,16 @@ in rec {
}; };
services.int = services.int =
let iface = svc.bridge.primary.build { ifname = "int"; }; let iface = svc.bridge.build {
ifname = "int";
members = with config.hardware.networkInterfaces; [
wlan_24 lan wlan_5
];
};
in address iface { in address iface {
family = "inet4"; address ="10.8.0.1"; prefixLength = 16; family = "inet4"; address ="10.8.0.1"; prefixLength = 16;
}; };
services.bridge = svc.bridge.members.build {
primary = services.int;
members = with config.hardware.networkInterfaces; [
wlan_24 lan wlan_5
];
};
services.ntp = svc.ntp.build { services.ntp = svc.ntp.build {
pools = { "pool.ntp.org" = ["iburst"]; }; pools = { "pool.ntp.org" = ["iburst"]; };
makestep = { threshold = 1.0; limit = 3; }; makestep = { threshold = 1.0; limit = 3; };
@ -208,7 +206,6 @@ in rec {
config.hardware.networkInterfaces.lo config.hardware.networkInterfaces.lo
config.hardware.networkInterfaces.lan config.hardware.networkInterfaces.lan
int int
bridge
hostap hostap
hostap5 hostap5
ntp ntp

View file

@ -17,30 +17,19 @@ let
in in
{ {
options = { options = {
system.service.bridge = { system.service.bridge = mkOption {
primary = mkOption { type = liminix.lib.types.serviceDefn;
type = liminix.lib.types.serviceDefn;
};
members = mkOption {
type = liminix.lib.types.serviceDefn;
};
}; };
}; };
config.system.service.bridge = { config.system.service = {
primary = liminix.callService ./primary.nix { bridge = liminix.callService ./service.nix {
ifname = mkOption {
type = types.str;
description = "interface name for the bridge device";
};
};
members = liminix.callService ./members.nix {
members = mkOption { members = mkOption {
type = types.listOf liminix.lib.types.service; type = types.listOf liminix.lib.types.service;
description = "interfaces to add to the bridge"; description = "interfaces to add to the bridge";
}; };
primary = mkOption { ifname = mkOption {
type = liminix.lib.types.service; type = types.str;
description = "bridge interface to add them to"; description = "bridge interface name to create";
}; };
}; };
}; };

View file

@ -1,13 +0,0 @@
{
liminix
, lib
}:
{ ifname } :
let
inherit (liminix.networking) interface;
inherit (liminix.lib) typeChecked;
inherit (lib) mkOption types;
in interface {
device = ifname;
type = "bridge";
}

View file

@ -3,11 +3,15 @@
, ifwait , ifwait
, lib , lib
}: }:
{ members, primary } : { members, ifname } :
let 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;
primary = interface {
device = ifname;
type = "bridge";
};
addif = member : addif = member :
oneshot { oneshot {
name = "add-${member.device}-to-br-${primary.device}"; name = "add-${member.device}-to-br-${primary.device}";
@ -15,7 +19,8 @@ let
down = "ip link set dev ${member.device} nomaster"; down = "ip link set dev ${member.device} nomaster";
dependencies = [ primary member ]; dependencies = [ primary member ];
}; };
in bundle {
in (bundle {
name = "bridge-${primary.device}-members"; name = "bridge-${primary.device}-members";
contents = map addif members; contents = [ primary ] ++ map addif members;
} }) // { device = primary.device; }

View file

@ -20,7 +20,7 @@ in {
}; };
callService = path : parameters : callService = path : parameters :
let pkg = callPackage path {}; let pkg = callPackage path {};
checkTypes = t : p : typeChecked (builtins.tostring path) t p; checkTypes = t : p : typeChecked (builtins.toString path) t p;
in { in {
inherit parameters; inherit parameters;
build = args : pkg (checkTypes parameters args); build = args : pkg (checkTypes parameters args);