nixos/modules/vm.nix

31 lines
793 B
Nix
Raw Normal View History

2024-07-26 19:28:55 +00:00
{ lib, modulesPath, numbers, ... }:
2024-07-25 17:33:44 +00:00
with lib;
2024-07-26 19:28:55 +00:00
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
2024-07-25 17:33:44 +00:00
{
imports = [
"${modulesPath}/virtualisation/qemu-vm.nix"
./server.nix
];
config = {
virtualisation.graphics = false;
2024-07-26 19:28:55 +00:00
virtualisation.qemu.networkingOptions = makeQemuNetworkingOptions config.networking.hostName;
2024-07-25 17:33:44 +00:00
};
}