From 93e04bb8349cb936259eb7a8d9baf62e7977841b Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Sat, 5 Aug 2023 14:08:02 +0100 Subject: [PATCH] convert bridge service to serviceDefn --- examples/rotuer.nix | 4 ++-- modules/bridge/default.nix | 27 +++++++++++++++++++++------ modules/bridge/members.nix | 16 +--------------- modules/bridge/primary.nix | 11 +---------- 4 files changed, 25 insertions(+), 33 deletions(-) diff --git a/examples/rotuer.nix b/examples/rotuer.nix index 324d518..ac7576e 100644 --- a/examples/rotuer.nix +++ b/examples/rotuer.nix @@ -78,12 +78,12 @@ in rec { }; services.int = - let iface = svc.bridge.primary { ifname = "int"; }; + let iface = svc.bridge.primary.build { ifname = "int"; }; in address iface { family = "inet4"; address ="10.8.0.1"; prefixLength = 16; }; - services.bridge = svc.bridge.members { + services.bridge = svc.bridge.members.build { primary = services.int; members = with config.hardware.networkInterfaces; [ wlan_24 lan wlan_5 diff --git a/modules/bridge/default.nix b/modules/bridge/default.nix index 27329cd..173a39c 100644 --- a/modules/bridge/default.nix +++ b/modules/bridge/default.nix @@ -2,21 +2,36 @@ let inherit (lib) mkOption types; inherit (pkgs.liminix.services) oneshot; + inherit (pkgs) liminix; in { options = { system.service.bridge = { primary = mkOption { - type = types.functionTo pkgs.liminix.lib.types.service; + type = liminix.lib.types.serviceDefn; }; members = mkOption { - type = types.functionTo pkgs.liminix.lib.types.service; + type = liminix.lib.types.serviceDefn; }; }; }; - config = { - system.service.bridge.primary = pkgs.callPackage ./primary.nix {}; - system.service.bridge.members = pkgs.callPackage ./members.nix {}; - kernel.config.BRIDGE = "y"; + 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 { + 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"; + }; + }; }; + config.kernel.config.BRIDGE = "y"; } diff --git a/modules/bridge/members.nix b/modules/bridge/members.nix index 537877d..24a23a5 100644 --- a/modules/bridge/members.nix +++ b/modules/bridge/members.nix @@ -3,25 +3,11 @@ , ifwait , lib }: +{ members, primary } : 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}"; diff --git a/modules/bridge/primary.nix b/modules/bridge/primary.nix index 11ced24..2ebd92a 100644 --- a/modules/bridge/primary.nix +++ b/modules/bridge/primary.nix @@ -2,20 +2,11 @@ liminix , lib }: +{ ifname } : 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";