about summary refs log tree commit diff
path: root/nixos/modules/tasks/network-interfaces-scripted.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-scripted.nix
parentb56d7a70a7158f81d964a55cfeb78848a067cc7d (diff)
downloadnixlib-5ce70619451a18ba35de9cc9c8ab7af3ee1420a5.tar
nixlib-5ce70619451a18ba35de9cc9c8ab7af3ee1420a5.tar.gz
nixlib-5ce70619451a18ba35de9cc9c8ab7af3ee1420a5.tar.bz2
nixlib-5ce70619451a18ba35de9cc9c8ab7af3ee1420a5.tar.lz
nixlib-5ce70619451a18ba35de9cc9c8ab7af3ee1420a5.tar.xz
nixlib-5ce70619451a18ba35de9cc9c8ab7af3ee1420a5.tar.zst
nixlib-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-scripted.nix')
-rw-r--r--nixos/modules/tasks/network-interfaces-scripted.nix28
1 files changed, 28 insertions, 0 deletions
diff --git a/nixos/modules/tasks/network-interfaces-scripted.nix b/nixos/modules/tasks/network-interfaces-scripted.nix
index e8e2de090b32..19f2be2c4a25 100644
--- a/nixos/modules/tasks/network-interfaces-scripted.nix
+++ b/nixos/modules/tasks/network-interfaces-scripted.nix
@@ -532,6 +532,33 @@ let
             '';
           });
 
+        createGreDevice = n: v: nameValuePair "${n}-netdev"
+          (let
+            deps = deviceDependency v.dev;
+          in
+          { description = "GRE Tunnel Interface ${n}";
+            wantedBy = [ "network-setup.service" (subsystemDevice n) ];
+            bindsTo = deps;
+            partOf = [ "network-setup.service" ];
+            after = [ "network-pre.target" ] ++ deps;
+            before = [ "network-setup.service" ];
+            serviceConfig.Type = "oneshot";
+            serviceConfig.RemainAfterExit = true;
+            path = [ pkgs.iproute2 ];
+            script = ''
+              # Remove Dead Interfaces
+              ip link show "${n}" >/dev/null 2>&1 && ip link delete "${n}"
+              ip link add name "${n}" type ${v.type} \
+                ${optionalString (v.remote != null) "remote \"${v.remote}\""} \
+                ${optionalString (v.local != null) "local \"${v.local}\""} \
+                ${optionalString (v.dev != null) "dev \"${v.dev}\""}
+              ip link set "${n}" up
+            '';
+            postStop = ''
+              ip link delete "${n}" || true
+            '';
+          });
+
         createVlanDevice = n: v: nameValuePair "${n}-netdev"
           (let
             deps = deviceDependency v.interface;
@@ -570,6 +597,7 @@ let
          // mapAttrs' createMacvlanDevice cfg.macvlans
          // mapAttrs' createFouEncapsulation cfg.fooOverUDP
          // mapAttrs' createSitDevice cfg.sits
+         // mapAttrs' createGreDevice cfg.greTunnels
          // mapAttrs' createVlanDevice cfg.vlans
          // {
            network-setup = networkSetup;