nixos-servers/nixos/modules/networking/default.nix

137 lines
2.9 KiB
Nix
Raw Normal View History

{ lib, config, ... }:
let cfg = config.lab.networking;
in {
2024-01-07 22:06:27 +00:00
imports = [ ./dmz ];
options.lab.networking = {
allowDMZConnectivity = lib.mkOption {
default = false;
type = lib.types.bool;
description = ''
Whether to create a networking interface on the DMZ bridge.
'';
};
staticDMZIpv4Address = lib.mkOption {
default = "";
type = lib.types.str;
description = ''
Assign a static IPv4 on the DMZ interface.
'';
};
publicIPv4 = lib.mkOption {
type = lib.types.str;
description = ''
Public IPv4 address of our home.
'';
};
dockerSwarmInternalIPv4 = lib.mkOption {
type = lib.types.str;
description = ''
Internal IPv4 address of the Docker Swarm.
'';
};
dmzRouterIPv4 = lib.mkOption {
type = lib.types.str;
description = ''
The router's IPv4 address on the DMZ network.
'';
};
dmzDHCPIPv4 = lib.mkOption {
type = lib.types.str;
description = ''
The IPv4 address of the DHCP server on the DMZ network.
'';
};
dmzBridgeName = lib.mkOption {
default = "bridgedmz";
type = lib.types.str;
description = ''
The name of the DMZ bridge.
'';
};
mainNicNamePattern = lib.mkOption {
default = "en*";
type = lib.types.str;
description = ''
Pattern to match the name of this machine's main NIC.
'';
};
2023-12-30 14:20:16 +00:00
};
config = {
networking = {
domain = "hyp";
firewall = {
enable = true;
checkReversePath = false;
};
nftables.enable = true;
useDHCP = false;
};
systemd.network = {
enable = true;
2023-12-30 14:20:16 +00:00
netdevs = {
"20-vlandmz" = {
vlanConfig.Id = 30;
2023-12-30 14:20:16 +00:00
netdevConfig = {
Kind = "vlan";
Name = "vlandmz";
};
2023-12-30 14:20:16 +00:00
};
"20-bridgedmz" = {
netdevConfig = {
Kind = "bridge";
Name = cfg.dmzBridgeName;
};
2023-12-30 14:20:16 +00:00
};
};
networks = {
"30-main-nic" = {
matchConfig.Name = cfg.mainNicNamePattern;
vlan = [ "vlandmz" ];
2023-12-30 14:20:16 +00:00
networkConfig = {
DHCP = "yes";
};
2023-12-30 14:20:16 +00:00
};
"40-vlandmz" = {
matchConfig.Name = "vlandmz";
linkConfig.RequiredForOnline = "enslaved";
2023-12-30 14:20:16 +00:00
networkConfig = {
IPv6AcceptRA = false;
LinkLocalAddressing = "no";
Bridge = cfg.dmzBridgeName;
};
2023-12-30 14:20:16 +00:00
};
"40-bridgedmz" = {
matchConfig.Name = cfg.dmzBridgeName;
linkConfig.RequiredForOnline = "carrier";
2023-12-30 14:20:16 +00:00
networkConfig = {
IPv6AcceptRA = false;
LinkLocalAddressing = "no";
DHCP = lib.mkIf cfg.allowDMZConnectivity "yes";
Address = lib.mkIf (cfg.staticDMZIpv4Address != "") cfg.staticDMZIpv4Address;
};
2023-12-30 14:20:16 +00:00
};
};
};
};
}