summary refs log tree commit diff
path: root/nixos/modules/tasks/network-interfaces.nix
diff options
context:
space:
mode:
authorMatthew Leach <dev@mattleach.net>2021-12-07 15:44:00 +0000
committerMatthew Leach <dev@mattleach.net>2021-12-07 15:44:00 +0000
commit5ce70619451a18ba35de9cc9c8ab7af3ee1420a5 (patch)
treead2a16676a6113aca9b223c7a914cf60ee863b9a /nixos/modules/tasks/network-interfaces.nix
parentb56d7a70a7158f81d964a55cfeb78848a067cc7d (diff)
downloadnixpkgs-5ce70619451a18ba35de9cc9c8ab7af3ee1420a5.tar
nixpkgs-5ce70619451a18ba35de9cc9c8ab7af3ee1420a5.tar.gz
nixpkgs-5ce70619451a18ba35de9cc9c8ab7af3ee1420a5.tar.bz2
nixpkgs-5ce70619451a18ba35de9cc9c8ab7af3ee1420a5.tar.lz
nixpkgs-5ce70619451a18ba35de9cc9c8ab7af3ee1420a5.tar.xz
nixpkgs-5ce70619451a18ba35de9cc9c8ab7af3ee1420a5.tar.zst
nixpkgs-5ce70619451a18ba35de9cc9c8ab7af3ee1420a5.zip
nixos/networking: add options for configuring a GRE tunnel
Add `networking.greTunnels` option that allows a GRE tunnel to be
configured in NixOS.
Diffstat (limited to 'nixos/modules/tasks/network-interfaces.nix')
-rw-r--r--nixos/modules/tasks/network-interfaces.nix61
1 files changed, 61 insertions, 0 deletions
diff --git a/nixos/modules/tasks/network-interfaces.nix b/nixos/modules/tasks/network-interfaces.nix
index 49901cda848..62a90c2b462 100644
--- a/nixos/modules/tasks/network-interfaces.nix
+++ b/nixos/modules/tasks/network-interfaces.nix
@@ -9,6 +9,7 @@ let
   interfaces = attrValues cfg.interfaces;
   hasVirtuals = any (i: i.virtual) interfaces;
   hasSits = cfg.sits != { };
+  hasGres = cfg.greTunnels != { };
   hasBonds = cfg.bonds != { };
   hasFous = cfg.fooOverUDP != { }
     || filterAttrs (_: s: s.encapsulation != null) cfg.sits != { };
@@ -996,6 +997,65 @@ in
       });
     };
 
+    networking.greTunnels = mkOption {
+      default = { };
+      example = literalExpression ''
+        {
+          greBridge = {
+            remote = "10.0.0.1";
+            local = "10.0.0.22";
+            dev = "enp4s0f0";
+            type = "tap";
+          };
+        }
+      '';
+      description = ''
+        This option allows you to define Generic Routing Encapsulation (GRE) tunnels.
+      '';
+      type = with types; attrsOf (submodule {
+        options = {
+
+          remote = mkOption {
+            type = types.nullOr types.str;
+            default = null;
+            example = "10.0.0.1";
+            description = ''
+              The address of the remote endpoint to forward traffic over.
+            '';
+          };
+
+          local = mkOption {
+            type = types.nullOr types.str;
+            default = null;
+            example = "10.0.0.22";
+            description = ''
+              The address of the local endpoint which the remote
+              side should send packets to.
+            '';
+          };
+
+          dev = mkOption {
+            type = types.nullOr types.str;
+            default = null;
+            example = "enp4s0f0";
+            description = ''
+              The underlying network device on which the tunnel resides.
+            '';
+          };
+
+          type = mkOption {
+            type = with types; enum [ "tun" "tap" ];
+            default = "tap";
+            example = "tap";
+            apply = v: if v == "tun" then "gre" else "gretap";
+            description = ''
+              Whether the tunnel routes layer 2 (tap) or layer 3 (tun) traffic.
+            '';
+          };
+        };
+      });
+    };
+
     networking.vlans = mkOption {
       default = { };
       example = literalExpression ''
@@ -1225,6 +1285,7 @@ in
     boot.kernelModules = [ ]
       ++ optional hasVirtuals "tun"
       ++ optional hasSits "sit"
+      ++ optional hasGres "gre"
       ++ optional hasBonds "bonding"
       ++ optional hasFous "fou";