nixos: set QEMU network options directly
Configure QEMU devices as drivers are configuration.
This commit is contained in:
parent
56e66ea842
commit
4d1d37a1ed
|
@ -48,7 +48,6 @@ let
|
||||||
-name ${config.system.name} \
|
-name ${config.system.name} \
|
||||||
-m ${toString config.virtualisation.memorySize} \
|
-m ${toString config.virtualisation.memorySize} \
|
||||||
-smp ${toString config.virtualisation.cores} \
|
-smp ${toString config.virtualisation.cores} \
|
||||||
${concatStringsSep " " config.virtualisation.qemu.networkingOptions} \
|
|
||||||
${toString config.virtualisation.qemu.options} \
|
${toString config.virtualisation.qemu.options} \
|
||||||
${
|
${
|
||||||
if config.hardware.genode.usb.storage.enable then
|
if config.hardware.genode.usb.storage.enable then
|
||||||
|
@ -128,7 +127,7 @@ in {
|
||||||
};
|
};
|
||||||
|
|
||||||
virtualisation.vlans = mkOption {
|
virtualisation.vlans = mkOption {
|
||||||
default = [ 1 ];
|
default = [ ];
|
||||||
example = [ 1 2 ];
|
example = [ 1 2 ];
|
||||||
description = ''
|
description = ''
|
||||||
Virtual networks to which the VM is connected. Each
|
Virtual networks to which the VM is connected. Each
|
||||||
|
@ -189,20 +188,42 @@ in {
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
networkingOptions = mkOption {
|
nics = mkOption {
|
||||||
default = [
|
description = "QEMU network devices.";
|
||||||
"-net nic,netdev=user.0,model=virtio"
|
default = { };
|
||||||
"-netdev user,id=user.0\${QEMU_NET_OPTS:+,$QEMU_NET_OPTS}"
|
type = with lib.types;
|
||||||
];
|
attrsOf (submodule {
|
||||||
type = types.listOf types.str;
|
options = {
|
||||||
description = ''
|
netdev = mkOption {
|
||||||
Networking-related command-line options that should be passed to qemu.
|
type = submodule {
|
||||||
The default is to use userspace networking (slirp).
|
options = {
|
||||||
|
kind = mkOption {
|
||||||
If you override this option, be advised to keep
|
type = str;
|
||||||
''${QEMU_NET_OPTS:+,$QEMU_NET_OPTS} (as seen in the default)
|
default = "user";
|
||||||
to keep the default runtime behaviour.
|
};
|
||||||
'';
|
settings = mkOption {
|
||||||
|
type = attrsOf str;
|
||||||
|
default = { };
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
device = mkOption {
|
||||||
|
type = submodule {
|
||||||
|
options = {
|
||||||
|
kind = mkOption {
|
||||||
|
type = str;
|
||||||
|
default = "virtio-net-pci";
|
||||||
|
};
|
||||||
|
settings = mkOption {
|
||||||
|
type = attrsOf str;
|
||||||
|
default = { };
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
diskInterface = mkOption {
|
diskInterface = mkOption {
|
||||||
|
@ -280,6 +301,15 @@ in {
|
||||||
])
|
])
|
||||||
(mkIf (cfg.bios != null) [ "-bios ${cfg.bios}/bios.bin" ])
|
(mkIf (cfg.bios != null) [ "-bios ${cfg.bios}/bios.bin" ])
|
||||||
(mkIf (!cfg.graphics) [ "-nographic" ])
|
(mkIf (!cfg.graphics) [ "-nographic" ])
|
||||||
|
(let
|
||||||
|
toFlags = bind:
|
||||||
|
{ kind, settings }:
|
||||||
|
lib.strings.concatStringsSep "," ([ "${kind},${bind}" ]
|
||||||
|
++ (lib.attrsets.mapAttrsToList (k: v: "${k}=${v}") settings));
|
||||||
|
in lib.attrsets.mapAttrsToList (id: nic: [
|
||||||
|
"-netdev ${toFlags "id=${id}" nic.netdev}"
|
||||||
|
"-device ${toFlags "netdev=${id}" nic.device}"
|
||||||
|
]) cfg.qemu.nics)
|
||||||
];
|
];
|
||||||
|
|
||||||
system.build.vm = pkgs.runCommand "nixos-vm" { preferLocalBuild = true; } ''
|
system.build.vm = pkgs.runCommand "nixos-vm" { preferLocalBuild = true; } ''
|
||||||
|
|
Loading…
Reference in New Issue