From 6f92f8fa8bc1c61e1f19fe2991af6d3b1b57368a Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Wed, 16 Aug 2023 19:44:00 +0100 Subject: [PATCH] merge bridge services into one --- examples/rotuer.nix | 15 +++++-------- modules/bridge/default.nix | 25 ++++++--------------- modules/bridge/primary.nix | 13 ----------- modules/bridge/{members.nix => service.nix} | 13 +++++++---- pkgs/default.nix | 2 +- 5 files changed, 23 insertions(+), 45 deletions(-) delete mode 100644 modules/bridge/primary.nix rename modules/bridge/{members.nix => service.nix} (73%) diff --git a/examples/rotuer.nix b/examples/rotuer.nix index ad43d58..8d88ede 100644 --- a/examples/rotuer.nix +++ b/examples/rotuer.nix @@ -79,18 +79,16 @@ in rec { }; 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 { 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 { pools = { "pool.ntp.org" = ["iburst"]; }; makestep = { threshold = 1.0; limit = 3; }; @@ -208,7 +206,6 @@ in rec { config.hardware.networkInterfaces.lo config.hardware.networkInterfaces.lan int - bridge hostap hostap5 ntp diff --git a/modules/bridge/default.nix b/modules/bridge/default.nix index 7d7e724..fc503c3 100644 --- a/modules/bridge/default.nix +++ b/modules/bridge/default.nix @@ -17,30 +17,19 @@ let in { options = { - system.service.bridge = { - primary = mkOption { - type = liminix.lib.types.serviceDefn; - }; - members = mkOption { - type = liminix.lib.types.serviceDefn; - }; + system.service.bridge = mkOption { + type = liminix.lib.types.serviceDefn; }; }; - config.system.service.bridge = { - primary = liminix.callService ./primary.nix { - ifname = mkOption { - type = types.str; - description = "interface name for the bridge device"; - }; - }; - members = liminix.callService ./members.nix { + config.system.service = { + bridge = liminix.callService ./service.nix { 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"; + ifname = mkOption { + type = types.str; + description = "bridge interface name to create"; }; }; }; diff --git a/modules/bridge/primary.nix b/modules/bridge/primary.nix deleted file mode 100644 index 2ebd92a..0000000 --- a/modules/bridge/primary.nix +++ /dev/null @@ -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"; -} diff --git a/modules/bridge/members.nix b/modules/bridge/service.nix similarity index 73% rename from modules/bridge/members.nix rename to modules/bridge/service.nix index 24a23a5..0c8fc1a 100644 --- a/modules/bridge/members.nix +++ b/modules/bridge/service.nix @@ -3,11 +3,15 @@ , ifwait , lib }: -{ members, primary } : +{ members, ifname } : let inherit (liminix.networking) interface; inherit (liminix.services) bundle oneshot; inherit (lib) mkOption types; + primary = interface { + device = ifname; + type = "bridge"; + }; addif = member : oneshot { name = "add-${member.device}-to-br-${primary.device}"; @@ -15,7 +19,8 @@ let down = "ip link set dev ${member.device} nomaster"; dependencies = [ primary member ]; }; -in bundle { + +in (bundle { name = "bridge-${primary.device}-members"; - contents = map addif members; -} + contents = [ primary ] ++ map addif members; +}) // { device = primary.device; } diff --git a/pkgs/default.nix b/pkgs/default.nix index c841d0c..9efcddf 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -20,7 +20,7 @@ in { }; callService = path : parameters : let pkg = callPackage path {}; - checkTypes = t : p : typeChecked (builtins.tostring path) t p; + checkTypes = t : p : typeChecked (builtins.toString path) t p; in { inherit parameters; build = args : pkg (checkTypes parameters args);