forked from DGNum/liminix
extract bridge to module-based services
This commit is contained in:
parent
86e73317ee
commit
9b70fd62f6
4 changed files with 88 additions and 23 deletions
|
@ -37,14 +37,10 @@ in rec {
|
||||||
../modules/dnsmasq
|
../modules/dnsmasq
|
||||||
../modules/firewall
|
../modules/firewall
|
||||||
../modules/hostapd
|
../modules/hostapd
|
||||||
|
../modules/bridge
|
||||||
];
|
];
|
||||||
rootfsType = "jffs2";
|
rootfsType = "jffs2";
|
||||||
hostname = "rotuer";
|
hostname = "rotuer";
|
||||||
kernel = {
|
|
||||||
config = {
|
|
||||||
BRIDGE = "y";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
services.hostap = svc.hostapd {
|
services.hostap = svc.hostapd {
|
||||||
interface = config.hardware.networkInterfaces.wlan_24;
|
interface = config.hardware.networkInterfaces.wlan_24;
|
||||||
|
@ -87,26 +83,16 @@ in rec {
|
||||||
};
|
};
|
||||||
|
|
||||||
services.int =
|
services.int =
|
||||||
let iface = interface {
|
let iface = svc.bridge.primary {
|
||||||
type = "bridge";
|
ifname = "int";
|
||||||
device = "int";
|
|
||||||
};
|
};
|
||||||
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 =
|
services.bridge = svc.bridge.members {
|
||||||
let
|
|
||||||
primary = services.int;
|
primary = services.int;
|
||||||
addif = dev: oneshot {
|
members = with config.hardware.networkInterfaces; [
|
||||||
name = "add-${dev.device}-to-bridge";
|
|
||||||
up = "${ifwait}/bin/ifwait -v ${dev.device} running && ip link set dev ${dev.device} master ${primary.device}";
|
|
||||||
down = "ip link set dev ${dev} nomaster";
|
|
||||||
dependencies = [ primary dev ];
|
|
||||||
};
|
|
||||||
in bundle {
|
|
||||||
name = "bridge-members";
|
|
||||||
contents = with config.hardware.networkInterfaces; map addif [
|
|
||||||
wlan_24 lan wlan_5
|
wlan_24 lan wlan_5
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
22
modules/bridge/default.nix
Normal file
22
modules/bridge/default.nix
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
{ lib, pkgs, config, ...}:
|
||||||
|
let
|
||||||
|
inherit (lib) mkOption types;
|
||||||
|
inherit (pkgs.liminix.services) oneshot;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
system.service.bridge = {
|
||||||
|
primary = mkOption {
|
||||||
|
type = types.functionTo pkgs.liminix.lib.types.service;
|
||||||
|
};
|
||||||
|
members = mkOption {
|
||||||
|
type = types.functionTo pkgs.liminix.lib.types.service;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
config = {
|
||||||
|
system.service.bridge.primary = pkgs.callPackage ./primary.nix {};
|
||||||
|
system.service.bridge.members = pkgs.callPackage ./members.nix {};
|
||||||
|
kernel.config.BRIDGE = "y";
|
||||||
|
};
|
||||||
|
}
|
35
modules/bridge/members.nix
Normal file
35
modules/bridge/members.nix
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
{
|
||||||
|
liminix
|
||||||
|
, ifwait
|
||||||
|
, lib
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
inherit (liminix.networking) interface;
|
||||||
|
inherit (liminix.services) bundle oneshot;
|
||||||
|
inherit (liminix.lib) typeChecked;
|
||||||
|
inherit (lib) mkOption types;
|
||||||
|
t = {
|
||||||
|
members = mkOption {
|
||||||
|
type = types.listOf liminix.lib.types.service;
|
||||||
|
description = "interfaces to add to the bridge";
|
||||||
|
};
|
||||||
|
primary = mkOption {
|
||||||
|
type = liminix.lib.types.service;
|
||||||
|
description = "bridge interface to add them to";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in
|
||||||
|
params:
|
||||||
|
let
|
||||||
|
inherit (typeChecked "bridge-members" t params) members primary;
|
||||||
|
addif = member :
|
||||||
|
oneshot {
|
||||||
|
name = "add-${member.device}-to-br-${primary.device}";
|
||||||
|
up = "${ifwait}/bin/ifwait ${member.device} running && ip link set dev ${member.device} master ${primary.device}";
|
||||||
|
down = "ip link set dev ${member.device} nomaster";
|
||||||
|
dependencies = [ primary member ];
|
||||||
|
};
|
||||||
|
in bundle {
|
||||||
|
name = "bridge-${primary.device}-members";
|
||||||
|
contents = map addif members;
|
||||||
|
}
|
22
modules/bridge/primary.nix
Normal file
22
modules/bridge/primary.nix
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
{
|
||||||
|
liminix
|
||||||
|
, lib
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
inherit (liminix.networking) interface;
|
||||||
|
inherit (liminix.lib) typeChecked;
|
||||||
|
inherit (lib) mkOption types;
|
||||||
|
t = {
|
||||||
|
ifname = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
description = "interface name for the bridge device";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in
|
||||||
|
params:
|
||||||
|
let
|
||||||
|
inherit (typeChecked "bridge" t params) ifname;
|
||||||
|
in interface {
|
||||||
|
device = ifname;
|
||||||
|
type = "bridge";
|
||||||
|
}
|
Loading…
Reference in a new issue