38 lines
770 B
Nix
Executable file
38 lines
770 B
Nix
Executable file
{
|
|
config,
|
|
lib,
|
|
...
|
|
}: let
|
|
attrSet = lib.lists.imap1 (i: v: {
|
|
name = v;
|
|
index = i;
|
|
}) (builtins.attrNames config.microvm.vms);
|
|
in {
|
|
config.systemd.network.networks = builtins.listToAttrs (builtins.map ({
|
|
name,
|
|
index,
|
|
}: {
|
|
name = "30-vm${toString index}";
|
|
value = {
|
|
matchConfig.Name = "vm${toString index}";
|
|
address = [
|
|
"10.0.0.0/32"
|
|
];
|
|
routes = [
|
|
{
|
|
Destination = "10.0.0.${toString index}/32";
|
|
}
|
|
];
|
|
networkConfig = {IPv4Forwarding = true;};
|
|
};
|
|
})
|
|
attrSet);
|
|
|
|
# NAT (make vms accessible in host)
|
|
config.networking.nat = {
|
|
enable = true;
|
|
internalIPs = ["10.0.0.0/24"];
|
|
externalInterface = "enp2s0";
|
|
};
|
|
}
|