feat(networking): add onlinkGateway option for static IP configuration

This commit is contained in:
emmatherock committed 2026-08-13 21:34:30 -03:00
1 parent 7a276567c6
commit 40f0dc0d45
2 files changed
+19 -1

No files matched your search

+3
View File
@@ -5,6 +5,7 @@
./hardware-configuration.nix ./hardware-configuration.nix
../../modules/profiles/server.nix ../../modules/profiles/server.nix
../../modules/system/home-profile.nix ../../modules/system/home-profile.nix
../../modules/system/nix-ld.nix
../../modules/system/packages.nix ../../modules/system/packages.nix
]; ];
@@ -19,7 +20,9 @@
prefixLength = 27; prefixLength = 27;
gateway = "23.175.41.225"; gateway = "23.175.41.225";
nameservers = [ "1.1.1.1" "1.0.0.1" ]; nameservers = [ "1.1.1.1" "1.0.0.1" ];
onlinkGateway = true;
}; };
extraTcpPorts = [ 80 443 ]; extraTcpPorts = [ 80 443 ];
extraUdpPorts = [ 51822 ]; extraUdpPorts = [ 51822 ];
sshAllowUsers = [ "emmatherock" ]; sshAllowUsers = [ "emmatherock" ];
+16 -1
View File
@@ -63,6 +63,11 @@ in
default = [ "1.1.1.1" "8.8.8.8" ]; default = [ "1.1.1.1" "8.8.8.8" ];
description = "DNS nameservers to use."; description = "DNS nameservers to use.";
}; };
onlinkGateway = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether the gateway lies outside the interface's subnet, requiring the onlink flag on the default route.";
};
}; };
}); });
default = null; default = null;
@@ -133,9 +138,19 @@ in
address = cfg.staticIp.address; address = cfg.staticIp.address;
prefixLength = cfg.staticIp.prefixLength; prefixLength = cfg.staticIp.prefixLength;
}]; }];
defaultGateway = cfg.staticIp.gateway;
nameservers = cfg.staticIp.nameservers; nameservers = cfg.staticIp.nameservers;
}) })
(lib.mkIf (cfg.staticIp != null && !cfg.staticIp.onlinkGateway) {
defaultGateway = cfg.staticIp.gateway;
})
(lib.mkIf (cfg.staticIp != null && cfg.staticIp.onlinkGateway) {
interfaces.${cfg.staticIp.interface}.ipv4.routes = [{
address = "0.0.0.0";
prefixLength = 0;
via = cfg.staticIp.gateway;
options.onlink = "true";
}];
})
(lib.mkIf cfg.wireguard.enable { (lib.mkIf cfg.wireguard.enable {
wireguard.interfaces."wg-${cfg.hostName}" = { wireguard.interfaces."wg-${cfg.hostName}" = {
ips = cfg.wireguard.ips; ips = cfg.wireguard.ips;