summary refs log tree commit diff
path: root/nixos/modules/tasks/network-interfaces.nix
diff options
context:
space:
mode:
authorWilliam A. Kennington III <william@wkennington.com>2015-01-13 16:10:39 -0800
committerWilliam A. Kennington III <william@wkennington.com>2015-01-14 10:34:28 -0800
commit8e5ef7da54e387238e513e4d9f29f86d1a7f0940 (patch)
tree750f24b96e1135aed3b7ef40b4ae1c92cf571c48 /nixos/modules/tasks/network-interfaces.nix
parent1ec68e0d13cb896525d142ab3d1980ce27fd5368 (diff)
downloadnixpkgs-8e5ef7da54e387238e513e4d9f29f86d1a7f0940.tar
nixpkgs-8e5ef7da54e387238e513e4d9f29f86d1a7f0940.tar.gz
nixpkgs-8e5ef7da54e387238e513e4d9f29f86d1a7f0940.tar.bz2
nixpkgs-8e5ef7da54e387238e513e4d9f29f86d1a7f0940.tar.lz
nixpkgs-8e5ef7da54e387238e513e4d9f29f86d1a7f0940.tar.xz
nixpkgs-8e5ef7da54e387238e513e4d9f29f86d1a7f0940.tar.zst
nixpkgs-8e5ef7da54e387238e513e4d9f29f86d1a7f0940.zip
nixos/network-interfaces: Fix rstp support
Diffstat (limited to 'nixos/modules/tasks/network-interfaces.nix')
-rw-r--r--nixos/modules/tasks/network-interfaces.nix34
1 files changed, 33 insertions, 1 deletions
diff --git a/nixos/modules/tasks/network-interfaces.nix b/nixos/modules/tasks/network-interfaces.nix
index 9f72e0f0d50..71a721abba2 100644
--- a/nixos/modules/tasks/network-interfaces.nix
+++ b/nixos/modules/tasks/network-interfaces.nix
@@ -16,6 +16,35 @@ let
 
   slaveIfs = map (i: cfg.interfaces.${i}) (filter (i: cfg.interfaces ? ${i}) slaves);
 
+  rstpBridges = flip filterAttrs cfg.bridges (_: { rstp, ... }: rstp);
+
+  needsMstpd = rstpBridges != { };
+
+  bridgeStp = optional needsMstpd (pkgs.writeTextFile {
+    name = "bridge-stp";
+    executable = true;
+    destination = "/bin/bridge-stp";
+    text = ''
+      #!${pkgs.stdenv.shell} -e
+      export PATH="${pkgs.mstpd}/bin"
+
+      BRIDGES=(${concatStringsSep " " (attrNames rstpBridges)})
+      for BRIDGE in $BRIDGES; do
+        if [ "$BRIDGE" = "$1" ]; then
+          if [ "$2" = "start" ]; then
+            mstpctl addbridge "$BRIDGE"
+            exit 0
+          elif [ "$2" = "stop" ]; then
+            mstpctl delbridge "$BRIDGE"
+            exit 0
+          fi
+          exit 1
+        fi
+      done
+      exit 1
+    '';
+  });
+
   # We must escape interfaces due to the systemd interpretation
   subsystemDevice = interface:
     "sys-subsystem-net-devices-${escapeSystemdPath interface}.device";
@@ -683,7 +712,7 @@ in
         pkgs.iw
         pkgs.rfkill
         pkgs.openresolv
-      ];
+      ] ++ bridgeStp;
 
     systemd.targets."network-interfaces" =
       { description = "All Network Interfaces";
@@ -731,6 +760,9 @@ in
             ip link set "${i.name}" mtu "${toString i.mtu}"
           '';
       })));
+
+    services.mstpd = mkIf needsMstpd { enable = true; };
+
   };
 
 }