diff --git a/nixos/vm/config.nix b/nixos/vm/config.nix index f521cd0..0aeaf3d 100644 --- a/nixos/vm/config.nix +++ b/nixos/vm/config.nix @@ -29,7 +29,7 @@ let ''; }; - mkMacvtap = macvtapName: macvtapCfg: + mkMacvtap = macvtapName: macvtapVmCfg: let macvtapNetworkCfg = config.vmix.networks.${netCfg.name}.bridges.macvtaps.${macvtapName}; macvtapInterfaceName = "mt-${vmCfg.name}-${macvtapNetworkCfg.uplink.iface}"; @@ -37,9 +37,10 @@ let { name = macvtapName; iface = macvtapInterfaceName; - mac = macvtapCfg.mac; + mac = macvtapVmCfg.mac; create = '' ip link add link ${macvtapNetworkCfg.uplink.iface} name ${macvtapInterfaceName} type macvtap mode bridge + ${lib.optionalString (macvtapVmCfg.mac != null) "ip link set dev ${macvtapInterfaceName} address ${macvtapVmCfg.mac}"} ip link set ${macvtapInterfaceName} netns ${netName}.vmix ip netns exec ${netName}.vmix ip link set dev ${macvtapInterfaceName} up ''; diff --git a/nixos/vm/options.nix b/nixos/vm/options.nix index 6a982a9..4055bde 100644 --- a/nixos/vm/options.nix +++ b/nixos/vm/options.nix @@ -151,7 +151,8 @@ with lib; description = "Enable the MACVTap interface."; }; mac = mkOption { - type = types.str; + type = types.nullOr types.str; + default = null; description = "MAC address for the MACVTap interface."; }; };