From d347234e82ae758974d1184b3d0550d3974a29d4 Mon Sep 17 00:00:00 2001 From: Jack O'Sullivan Date: Tue, 21 Nov 2023 11:18:17 +0000 Subject: [PATCH] nixos/home/routing-common: Move mstpd config to separate file --- nixos/boxes/home/routing-common/default.nix | 55 +++------------------ nixos/boxes/home/routing-common/mstpd.nix | 53 ++++++++++++++++++++ 2 files changed, 60 insertions(+), 48 deletions(-) create mode 100644 nixos/boxes/home/routing-common/mstpd.nix diff --git a/nixos/boxes/home/routing-common/default.nix b/nixos/boxes/home/routing-common/default.nix index 069b254..590e4d9 100644 --- a/nixos/boxes/home/routing-common/default.nix +++ b/nixos/boxes/home/routing-common/default.nix @@ -59,27 +59,18 @@ in let inherit (lib) mkIf mkMerge mkForce; inherit (lib.my) networkdAssignment; - - # TODO: Move into nixpkgs - mstpd = pkgs.mstpd.overrideAttrs { - patches = [ ./mstpd.patch ]; - }; in { - imports = [ (import ./dns.nix index) ]; + imports = map (m: import m index) [ + ./mstpd.nix + ./dns.nix + ]; config = { environment = { - systemPackages = [ - pkgs.ethtool - mstpd + systemPackages = with pkgs; [ + ethtool ]; - etc = { - "bridge-stp.conf".text = '' - MANAGE_MSTPD=n - MSTP_BRIDGES=lan - ''; - }; }; services = { @@ -95,43 +86,11 @@ in openFirewall = true; }; - networkd-dispatcher = { - enable = true; - rules = { - configure-mstpd = { - onState = [ "routable" ]; - script = '' - #!${pkgs.runtimeShell} - if [ $IFACE = "lan" ]; then - ${mstpd}/sbin/mstpctl setforcevers $IFACE rstp - fi - ''; - }; - }; - }; + networkd-dispatcher.enable = true; }; networking.domain = "h.${pubDomain}"; - systemd = { - services = { - mstpd = { - description = "MSTP daemon"; - before = [ "network-pre.target" ]; - serviceConfig = { - Type = "forking"; - ExecStart = "${mstpd}/sbin/bridge-stp restart"; - ExecReload = "${mstpd}/sbin/bridge-stp restart_config"; - PIDFile = "/run/mstpd.pid"; - Restart = "always"; - PrivateTmp = true; - ProtectHome = true; - }; - wantedBy = [ "multi-user.target" ]; - }; - }; - }; - systemd.network = { wait-online.enable = false; config = { diff --git a/nixos/boxes/home/routing-common/mstpd.nix b/nixos/boxes/home/routing-common/mstpd.nix new file mode 100644 index 0000000..05727f9 --- /dev/null +++ b/nixos/boxes/home/routing-common/mstpd.nix @@ -0,0 +1,53 @@ +index: { lib, pkgs, ... }: +let + # TODO: Move into nixpkgs + mstpd = pkgs.mstpd.overrideAttrs { + patches = [ ./mstpd.patch ]; + }; +in +{ + environment = { + systemPackages = [ + mstpd + ]; + etc = { + "bridge-stp.conf".text = '' + MANAGE_MSTPD=n + MSTP_BRIDGES=lan + ''; + }; + }; + + services = { + networkd-dispatcher.rules = { + configure-mstpd = { + onState = [ "routable" ]; + script = '' + #!${pkgs.runtimeShell} + if [ $IFACE = "lan" ]; then + ${mstpd}/sbin/mstpctl setforcevers $IFACE rstp + fi + ''; + }; + }; + }; + + systemd = { + services = { + mstpd = { + description = "MSTP daemon"; + before = [ "network-pre.target" ]; + serviceConfig = { + Type = "forking"; + ExecStart = "${mstpd}/sbin/bridge-stp restart"; + ExecReload = "${mstpd}/sbin/bridge-stp restart_config"; + PIDFile = "/run/mstpd.pid"; + Restart = "always"; + PrivateTmp = true; + ProtectHome = true; + }; + wantedBy = [ "multi-user.target" ]; + }; + }; + }; +}