mirror of
https://github.com/oddlama/nixos-extra-modules.git
synced 2025-10-10 22:00:39 +02:00
feat: allow changing interface name in VM
This commit is contained in:
parent
6a4736e077
commit
2502ff50ab
2 changed files with 27 additions and 15 deletions
|
@ -202,20 +202,28 @@ in {
|
||||||
description = "An attrset correlating the host interface to which the microvm should be attached via macvtap, with its mac address";
|
description = "An attrset correlating the host interface to which the microvm should be attached via macvtap, with its mac address";
|
||||||
type = types.attrsOf (
|
type = types.attrsOf (
|
||||||
types.submodule (submod-iface: {
|
types.submodule (submod-iface: {
|
||||||
options.mac = mkOption {
|
options = {
|
||||||
type = types.net.mac;
|
hostLink = mkOption {
|
||||||
description = "The MAC address for the guest's macvtap interface";
|
type = types.str;
|
||||||
default = let
|
description = "The name of the host side link to which this interface will bind.";
|
||||||
base = "02:${lib.substring 3 5 submod.config.microvm.baseMac}:00:00:00";
|
default = submod-iface.config._module.args.name;
|
||||||
in
|
example = "lan";
|
||||||
(net.mac.assignMacs base 24 [] (
|
};
|
||||||
flatten (
|
mac = mkOption {
|
||||||
flip mapAttrsToList config.guests (
|
type = types.net.mac;
|
||||||
name: value: forEach (attrNames value.microvm.interfaces) (iface: "${name}-${iface}")
|
description = "The MAC address for the guest's macvtap interface";
|
||||||
|
default = let
|
||||||
|
base = "02:${lib.substring 3 5 submod.config.microvm.baseMac}:00:00:00";
|
||||||
|
in
|
||||||
|
(net.mac.assignMacs base 24 [] (
|
||||||
|
flatten (
|
||||||
|
flip mapAttrsToList config.guests (
|
||||||
|
name: value: forEach (attrNames value.microvm.interfaces) (iface: "${name}-${iface}")
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
))
|
||||||
))
|
."${submod.config._module.args.name}-${submod-iface.config._module.args.name}";
|
||||||
."${submod.config._module.args.name}-${submod-iface.config._module.args.name}";
|
};
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
|
@ -47,12 +47,16 @@ in {
|
||||||
|
|
||||||
# MACVTAP bridge to the host's network
|
# MACVTAP bridge to the host's network
|
||||||
interfaces = flip mapAttrsToList guestCfg.microvm.interfaces (
|
interfaces = flip mapAttrsToList guestCfg.microvm.interfaces (
|
||||||
interface: {mac, ...}: {
|
_: {
|
||||||
|
mac,
|
||||||
|
hostLink,
|
||||||
|
...
|
||||||
|
}: {
|
||||||
type = "macvtap";
|
type = "macvtap";
|
||||||
id = "vm-${replaceStrings [":"] [""] mac}";
|
id = "vm-${replaceStrings [":"] [""] mac}";
|
||||||
inherit mac;
|
inherit mac;
|
||||||
macvtap = {
|
macvtap = {
|
||||||
link = interface;
|
link = hostLink;
|
||||||
mode = "bridge";
|
mode = "bridge";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue