summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/foundation/services/default.nix1
-rw-r--r--modules/foundation/services/networks.nix24
2 files changed, 20 insertions, 5 deletions
diff --git a/modules/foundation/services/default.nix b/modules/foundation/services/default.nix
index 25477b1..f26f9e6 100644
--- a/modules/foundation/services/default.nix
+++ b/modules/foundation/services/default.nix
@@ -11,6 +11,7 @@
default = true;
subnet = "2001:d0c:1::/48";
+ gateway = "2001:d0c:1::1";
driver = "bridge";
};
}
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}
'';