summary refs log tree commit diff
path: root/modules/foundation/services/networks.nix
diff options
context:
space:
mode:
Diffstat (limited to 'modules/foundation/services/networks.nix')
-rw-r--r--modules/foundation/services/networks.nix24
1 files changed, 19 insertions, 5 deletions
diff --git a/modules/foundation/services/networks.nix b/modules/foundation/services/networks.nix
index e9adf6b..72e5b48 100644
--- a/modules/foundation/services/networks.nix
+++ b/modules/foundation/services/networks.nix
@@ -60,6 +60,16 @@ in
               default = null;
             };
 
+            gateway = mkOption {
+              type = types.nullOr types.str;
+              description = ''
+                IPv6 gateway for this network.
+                Should match the subnet.
+              '';
+              example = "2001:d0c:123::1";
+              default = null;
+            };
+
             driver = mkOption {
               type = types.str;
               default = "bridge";
@@ -160,10 +170,10 @@ in
 
     systemd.services =
       let
-        subnetOffset = 100;
-        subnetByIndex =
-          i:
-          "${cfg.defaultSubnetPrefix}:${toString (subnetOffset + i)}::/${toString cfg.defaultSubnetLength}";
+        prefixOffset = 100;
+        prefixByIndex = i: "${cfg.defaultSubnetPrefix}:${toString (prefixOffset + i)}";
+        subnetByIndex = i: "${prefixByIndex i}::/${toString cfg.defaultSubnetLength}";
+        gatewayByIndex = i: "${prefixByIndex i}::1";
 
         # this could be moved out into library functions, it's pretty useful.
         # mapAttrsIndexed' :: (Int -> String -> AttrSet -> { name:: String; value :: Any; }) -> AttrSet -> AttrSet
@@ -182,6 +192,7 @@ in
             docker = getExe pkgs.docker;
             options = concatStringsSep " " network.options;
             subnet = if network.subnet == null then subnetByIndex index else network.subnet;
+            gateway = if network.gateway == null then gatewayByIndex index else network.gateway;
           in
           {
             description = "Docker service network '${name}'";
@@ -205,8 +216,11 @@ in
                 ${docker} network create \
                   --ipv6 \
                   --subnet=${subnet} \
+                  --gateway=${gateway} \
                   --driver=${network.driver} \
-                  ${optionalString (network.mtu != null) "--opt com.docker.network.driver.mtu=${toString network.mtu}"} \
+                  ${
+                    optionalString (network.mtu != null) "--opt com.docker.network.driver.mtu=${toString network.mtu}"
+                  } \
                   ${options} \
                   ${name}
               '';