summary refs log tree commit diff
path: root/nixos/modules/tasks/network-interfaces.nix
diff options
context:
space:
mode:
authorWilliam A. Kennington III <william@wkennington.com>2014-08-23 18:38:29 -0700
committerWilliam A. Kennington III <william@wkennington.com>2014-08-30 08:20:14 -0700
commit1c08efb8ab258856c6b2cb8794bdc03c96c2b8c9 (patch)
tree4c8a597f2fc6f401ed2d9a9f552c4971ae2d3938 /nixos/modules/tasks/network-interfaces.nix
parentb7d2aff1030d66a218b396f5f2ca872a7186e323 (diff)
downloadnixpkgs-1c08efb8ab258856c6b2cb8794bdc03c96c2b8c9.tar
nixpkgs-1c08efb8ab258856c6b2cb8794bdc03c96c2b8c9.tar.gz
nixpkgs-1c08efb8ab258856c6b2cb8794bdc03c96c2b8c9.tar.bz2
nixpkgs-1c08efb8ab258856c6b2cb8794bdc03c96c2b8c9.tar.lz
nixpkgs-1c08efb8ab258856c6b2cb8794bdc03c96c2b8c9.tar.xz
nixpkgs-1c08efb8ab258856c6b2cb8794bdc03c96c2b8c9.tar.zst
nixpkgs-1c08efb8ab258856c6b2cb8794bdc03c96c2b8c9.zip
nixos/network-interfaces: Allow explicit virtual interface type setting
Diffstat (limited to 'nixos/modules/tasks/network-interfaces.nix')
-rw-r--r--nixos/modules/tasks/network-interfaces.nix32
1 files changed, 23 insertions, 9 deletions
diff --git a/nixos/modules/tasks/network-interfaces.nix b/nixos/modules/tasks/network-interfaces.nix
index ac3a55332e4..985e76cd708 100644
--- a/nixos/modules/tasks/network-interfaces.nix
+++ b/nixos/modules/tasks/network-interfaces.nix
@@ -138,8 +138,6 @@ let
           Whether this interface is virtual and should be created by tunctl.
           This is mainly useful for creating bridges between a host a virtual
           network such as VPN or a virtual machine.
-
-          Defaults to tap device, unless interface contains "tun" in its name.
         '';
       };
 
@@ -151,6 +149,15 @@ let
         '';
       };
 
+      virtualType = mkOption {
+        default = null;
+        type = types.nullOr (types.addCheck types.str (v: v == "tun" || v == "tap"));
+        description = ''
+          The explicit type of interface to create. Accepts tun or tap strings.
+          Also accepts null to implicitly detect the type of device.
+        '';
+      };
+
       proxyARP = mkOption {
         default = false;
         type = types.bool;
@@ -673,18 +680,25 @@ in
                 '');
           };
 
-        createTunDevice = i: nameValuePair "${i.name}"
+        createTunDevice = i: nameValuePair "${i.name}-tun"
           { description = "Virtual Network Interface ${i.name}";
             requires = [ "dev-net-tun.device" ];
             after = [ "dev-net-tun.device" ];
             wantedBy = [ "network.target" ];
             requiredBy = [ "sys-subsystem-net-devices-${i.name}.device" ];
-            serviceConfig =
-              { Type = "oneshot";
-                RemainAfterExit = true;
-                ExecStart = "${pkgs.tunctl}/bin/tunctl -t '${i.name}' -u '${i.virtualOwner}'";
-                ExecStop = "${pkgs.tunctl}/bin/tunctl -d '${i.name}'";
-              };
+            path = [ pkgs.iproute ];
+            serviceConfig = {
+              Type = "oneshot";
+              RemainAfterExit = true;
+            };
+            script = ''
+              ip tuntap add dev "${i.name}" \
+              ${optionalString (i.virtualType != null) "mode ${i.virtualType}"} \
+              user "${i.virtualOwner}"
+            '';
+            postStop = ''
+              ip link del ${i.name}
+            '';
           };
 
         createBridgeDevice = n: v: