diff options
author | Graham Dennis <gdennis@anduril.com> | 2023-05-22 13:38:52 +1000 |
---|---|---|
committer | Graham Dennis <gdennis@anduril.com> | 2023-05-24 08:54:20 +1000 |
commit | 93502aa3b18db32649814fbb8341ea59ba40df5c (patch) | |
tree | 95c79e88fc6ee292c8b0fe35bb46657dce76b90f /nixos/modules/virtualisation | |
parent | e6e049b7a24decd1f0caee8b035913795697c699 (diff) | |
download | nixlib-93502aa3b18db32649814fbb8341ea59ba40df5c.tar nixlib-93502aa3b18db32649814fbb8341ea59ba40df5c.tar.gz nixlib-93502aa3b18db32649814fbb8341ea59ba40df5c.tar.bz2 nixlib-93502aa3b18db32649814fbb8341ea59ba40df5c.tar.lz nixlib-93502aa3b18db32649814fbb8341ea59ba40df5c.tar.xz nixlib-93502aa3b18db32649814fbb8341ea59ba40df5c.tar.zst nixlib-93502aa3b18db32649814fbb8341ea59ba40df5c.zip |
nixos/qemu-vm: add option for named network interfaces
Adds a new option to the virtualisation modules that enables specifying explicitly named network interfaces in QEMU VMs. The existing `virtualisation.vlans` option is still supported for cases where the name of the network interface is irrelevant.
Diffstat (limited to 'nixos/modules/virtualisation')
-rw-r--r-- | nixos/modules/virtualisation/qemu-vm.nix | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/nixos/modules/virtualisation/qemu-vm.nix b/nixos/modules/virtualisation/qemu-vm.nix index 5f6bf4b39e97..a8ac478aab4c 100644 --- a/nixos/modules/virtualisation/qemu-vm.nix +++ b/nixos/modules/virtualisation/qemu-vm.nix @@ -564,7 +564,8 @@ in virtualisation.vlans = mkOption { type = types.listOf types.ints.unsigned; - default = [ 1 ]; + default = if config.virtualisation.interfaces == {} then [ 1 ] else [ ]; + defaultText = lib.literalExpression ''if config.virtualisation.interfaces == {} then [ 1 ] else [ ]''; example = [ 1 2 ]; description = lib.mdDoc '' @@ -579,6 +580,35 @@ in ''; }; + virtualisation.interfaces = mkOption { + default = {}; + example = { + enp1s0.vlan = 1; + }; + description = lib.mdDoc '' + Network interfaces to add to the VM. + ''; + type = with types; attrsOf (submodule { + options = { + vlan = mkOption { + type = types.ints.unsigned; + description = lib.mdDoc '' + VLAN to which the network interface is connected. + ''; + }; + + assignIP = mkOption { + type = types.bool; + default = false; + description = lib.mdDoc '' + Automatically assign an IP address to the network interface using the same scheme as + virtualisation.vlans. + ''; + }; + }; + }); + }; + virtualisation.writableStore = mkOption { type = types.bool; |