Commit 88ae6281d80a

Vincent Demeester <vincent@sbr.pm>
2026-02-02 09:40:59
fix(microvm): add service to attach tap interfaces to bridge
The microvm.nix tap interfaces don't auto-attach to bridges. Add microvm-bridge-{name} services that run after tap-interfaces and attach the tap to the microbr bridge. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 3afcd95
Changed files (1)
modules
modules/microvm/default.nix
@@ -315,5 +315,29 @@ in
     systemd.tmpfiles.rules = mapAttrsToList (
       name: _vmCfg: "d ${cfg.stateDir}/${name} 0755 vincent users -"
     ) cfg.vms;
+
+    # Attach tap interfaces to bridge after they're created
+    systemd.services = mapAttrs' (
+      name: _vmCfg:
+      let
+        tap = tapName name;
+      in
+      nameValuePair "microvm-bridge-${name}" {
+        description = "Attach MicroVM '${name}' tap to bridge";
+        after = [
+          "microvm-tap-interfaces@${name}.service"
+          "network-addresses-${cfg.bridge}.service"
+        ];
+        requires = [ "microvm-tap-interfaces@${name}.service" ];
+        before = [ "microvm@${name}.service" ];
+        partOf = [ "microvm@${name}.service" ];
+        serviceConfig = {
+          Type = "oneshot";
+          RemainAfterExit = true;
+          ExecStart = "${pkgs.iproute2}/bin/ip link set ${tap} master ${cfg.bridge}";
+          ExecStop = "${pkgs.iproute2}/bin/ip link set ${tap} nomaster";
+        };
+      }
+    ) cfg.vms;
   };
 }