about summary refs log tree commit diff
path: root/nixos/modules/virtualisation
diff options
context:
space:
mode:
authorRyan Lahfa <masterancpp@gmail.com>2023-05-26 15:57:01 +0200
committerGitHub <noreply@github.com>2023-05-26 15:57:01 +0200
commit435237d641c9e195572ac40057fc32d62c42f965 (patch)
tree15e38fe6ced3fda50f9af45086a0cbb58e11d4c4 /nixos/modules/virtualisation
parent1aca05b5e347fb456173d35d39fe131deef9ac23 (diff)
parent8e58daad0227de3886bd073e09e47b0308b53e15 (diff)
downloadnixlib-435237d641c9e195572ac40057fc32d62c42f965.tar
nixlib-435237d641c9e195572ac40057fc32d62c42f965.tar.gz
nixlib-435237d641c9e195572ac40057fc32d62c42f965.tar.bz2
nixlib-435237d641c9e195572ac40057fc32d62c42f965.tar.lz
nixlib-435237d641c9e195572ac40057fc32d62c42f965.tar.xz
nixlib-435237d641c9e195572ac40057fc32d62c42f965.tar.zst
nixlib-435237d641c9e195572ac40057fc32d62c42f965.zip
Merge pull request #233350 from GrahamDennis/grahamdennis/testing-networks
nixos/qemu-vm: add option for named network interfaces
Diffstat (limited to 'nixos/modules/virtualisation')
-rw-r--r--nixos/modules/virtualisation/qemu-vm.nix32
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;