summary refs log tree commit diff
path: root/nixos/modules
diff options
context:
space:
mode:
authorrnhmjoj <rnhmjoj@inventati.org>2018-01-31 05:51:09 +0100
committerrnhmjoj <rnhmjoj@inventati.org>2018-01-31 05:51:09 +0100
commit46c158a32f1b920fe0280c7aea3f42670ece7473 (patch)
tree9c20825e60c1b14666b73325b0627f0418eb3aa5 /nixos/modules
parentdc52fc6dda00c4f3e275e56a5f4f0386260e4063 (diff)
downloadnixlib-46c158a32f1b920fe0280c7aea3f42670ece7473.tar
nixlib-46c158a32f1b920fe0280c7aea3f42670ece7473.tar.gz
nixlib-46c158a32f1b920fe0280c7aea3f42670ece7473.tar.bz2
nixlib-46c158a32f1b920fe0280c7aea3f42670ece7473.tar.lz
nixlib-46c158a32f1b920fe0280c7aea3f42670ece7473.tar.xz
nixlib-46c158a32f1b920fe0280c7aea3f42670ece7473.tar.zst
nixlib-46c158a32f1b920fe0280c7aea3f42670ece7473.zip
nixos/networking-interfaces: set default value for virtualType
Diffstat (limited to 'nixos/modules')
-rw-r--r--nixos/modules/tasks/network-interfaces-scripted.nix4
-rw-r--r--nixos/modules/tasks/network-interfaces-systemd.nix24
-rw-r--r--nixos/modules/tasks/network-interfaces.nix10
3 files changed, 17 insertions, 21 deletions
diff --git a/nixos/modules/tasks/network-interfaces-scripted.nix b/nixos/modules/tasks/network-interfaces-scripted.nix
index 1f424f84c6e0..63d07832d105 100644
--- a/nixos/modules/tasks/network-interfaces-scripted.nix
+++ b/nixos/modules/tasks/network-interfaces-scripted.nix
@@ -230,9 +230,7 @@ let
               RemainAfterExit = true;
             };
             script = ''
-              ip tuntap add dev "${i.name}" \
-              ${optionalString (i.virtualType != null) "mode ${i.virtualType}"} \
-              user "${i.virtualOwner}"
+              ip tuntap add dev "${i.name}" mode "${i.virtualType}" user "${i.virtualOwner}"
             '';
             postStop = ''
               ip link del ${i.name} || true
diff --git a/nixos/modules/tasks/network-interfaces-systemd.nix b/nixos/modules/tasks/network-interfaces-systemd.nix
index a365a01bfb1e..5d72ad0f1bde 100644
--- a/nixos/modules/tasks/network-interfaces-systemd.nix
+++ b/nixos/modules/tasks/network-interfaces-systemd.nix
@@ -74,21 +74,17 @@ in
         networks."99-main" = genericNetwork mkDefault;
       }
       (mkMerge (flip map interfaces (i: {
-        netdevs = mkIf i.virtual (
-          let
-            devType = if i.virtualType != null then i.virtualType
-              else (if hasPrefix "tun" i.name then "tun" else "tap");
-          in {
-            "40-${i.name}" = {
-              netdevConfig = {
-                Name = i.name;
-                Kind = devType;
-              };
-              "${devType}Config" = optionalAttrs (i.virtualOwner != null) {
-                User = i.virtualOwner;
-              };
+        netdevs = mkIf i.virtual ({
+          "40-${i.name}" = {
+            netdevConfig = {
+              Name = i.name;
+              Kind = i.virtualType;
             };
-          });
+            "${i.virtualType}Config" = optionalAttrs (i.virtualOwner != null) {
+              User = i.virtualOwner;
+            };
+          };
+        });
         networks."40-${i.name}" = mkMerge [ (genericNetwork mkDefault) {
           name = mkDefault i.name;
           DHCP = mkForce (dhcpStr
diff --git a/nixos/modules/tasks/network-interfaces.nix b/nixos/modules/tasks/network-interfaces.nix
index b7e85e402aa9..2a17ae934f8a 100644
--- a/nixos/modules/tasks/network-interfaces.nix
+++ b/nixos/modules/tasks/network-interfaces.nix
@@ -273,11 +273,13 @@ let
       };
 
       virtualType = mkOption {
-        default = null;
-        type = with types; nullOr (enum [ "tun" "tap" ]);
+        default = if hasPrefix "tun" name then "tun" else "tap";
+        defaultText = ''if hasPrefix "tun" name then "tun" else "tap"'';
+        type = with types; enum [ "tun" "tap" ];
         description = ''
-          The explicit type of interface to create. Accepts tun or tap strings.
-          Also accepts null to implicitly detect the type of device.
+          The type of interface to create.
+          The default is TUN for an interface name starting
+          with "tun", otherwise TAP.
         '';
       };