add nics for eths to vms from numbers

This commit is contained in:
James Andariese 2024-07-26 14:28:55 -05:00
parent e8b4512af3
commit 97a0c9035f

View File

@ -1,6 +1,22 @@
{ lib, modulesPath, ... }: { lib, modulesPath, numbers, ... }:
with lib; with lib;
let
makeNic = host: iface:
let { matchMac, iface, media, ... } = numbers.api.hostIface host iface;
in
if media != "eth" then [] else
[
"-nic bridge,id=${iface},br=${iface},model=virtio,mac=${matchMac}"
];
makeNics = host: concatMap (makeNic host) (numbers.api.hostIfaces host);
makeQemuNetworkingOptions = host:
(makeNics host) ++ [
"-net nic,netdev=user.0,model=virtio"
"-netdev user,id=user.0,\${QEMU_NET_OPTS:+,$QEMU_NET_OPTS}"
];
in
{ {
imports = [ imports = [
"${modulesPath}/virtualisation/qemu-vm.nix" "${modulesPath}/virtualisation/qemu-vm.nix"
@ -9,5 +25,6 @@ with lib;
config = { config = {
virtualisation.graphics = false; virtualisation.graphics = false;
virtualisation.qemu.networkingOptions = makeQemuNetworkingOptions config.networking.hostName;
}; };
} }