2024-12-15 17:22:36 -06:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}: let
|
2024-12-23 14:35:36 -06:00
|
|
|
cfg = config.networking;
|
2024-12-15 17:22:36 -06:00
|
|
|
in {
|
2024-12-23 14:35:36 -06:00
|
|
|
options.networking = {
|
2024-12-15 17:22:36 -06:00
|
|
|
# Firewall Configuration
|
|
|
|
firewall = {
|
2024-12-23 14:35:36 -06:00
|
|
|
enable = lib.mkEnableOption {
|
2024-12-15 17:22:36 -06:00
|
|
|
type = lib.types.bool;
|
|
|
|
default = true;
|
|
|
|
description = "Enable system firewall";
|
|
|
|
};
|
|
|
|
|
|
|
|
tcpPorts = {
|
|
|
|
# Predefined, default common service ports
|
|
|
|
ssh = {
|
2024-12-23 14:35:36 -06:00
|
|
|
enable = lib.mkEnableOption {
|
2024-12-15 17:22:36 -06:00
|
|
|
type = lib.types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Open SSH service port (22)";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
web = {
|
2024-12-23 14:35:36 -06:00
|
|
|
enable = lib.mkEnableOption {
|
2024-12-15 17:22:36 -06:00
|
|
|
type = lib.types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Open common web service ports (80, 443)";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
smtp = {
|
2024-12-23 14:35:36 -06:00
|
|
|
enable = lib.mkEnableOption {
|
2024-12-15 17:22:36 -06:00
|
|
|
type = lib.types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Open SMTP service ports (25, 465, 587)";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
imap = {
|
2024-12-23 14:35:36 -06:00
|
|
|
enable = lib.mkEnableOption {
|
2024-12-15 17:22:36 -06:00
|
|
|
type = lib.types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Open IMAP service ports (143, 993)";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
mysql = {
|
2024-12-23 14:35:36 -06:00
|
|
|
enable = lib.mkEnableOption {
|
2024-12-15 17:22:36 -06:00
|
|
|
type = lib.types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Open MySQL service port (3306)";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
mssql = {
|
2024-12-23 14:35:36 -06:00
|
|
|
enable = lib.mkEnableOption {
|
2024-12-15 17:22:36 -06:00
|
|
|
type = lib.types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Open Microsoft SQL Server service port (1433)";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
postgres = {
|
2024-12-23 14:35:36 -06:00
|
|
|
enable = lib.mkEnableOption {
|
2024-12-15 17:22:36 -06:00
|
|
|
type = lib.types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Open Postgres service port (5432)";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
allowedPorts = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.port;
|
|
|
|
default = [];
|
|
|
|
description = "List of custom TCP ports to open";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
udpPorts = {
|
|
|
|
dns = {
|
2024-12-23 14:35:36 -06:00
|
|
|
enable = lib.mkEnableOption {
|
2024-12-15 17:22:36 -06:00
|
|
|
type = lib.types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Open DNS service port (53)";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
ntp = {
|
2024-12-23 14:35:36 -06:00
|
|
|
enable = lib.mkEnableOption {
|
2024-12-15 17:22:36 -06:00
|
|
|
type = lib.types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Open NTP service port (123)";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
allowedPorts = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.port;
|
|
|
|
default = [];
|
|
|
|
description = "List of custom UDP ports to open";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
networkManager = {
|
2024-12-23 14:35:36 -06:00
|
|
|
enable = lib.mkEnableOption {
|
2024-12-15 17:22:36 -06:00
|
|
|
type = lib.types.bool;
|
|
|
|
default = true;
|
|
|
|
description = "Enable NetworkManager for network connection management";
|
|
|
|
};
|
|
|
|
|
|
|
|
extraPlugins = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.package;
|
|
|
|
default = [];
|
|
|
|
description = "Additional NetworkManager plugins to install";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
|
|
|
networking.firewall = {
|
|
|
|
enable = cfg.firewall.enable;
|
|
|
|
|
|
|
|
allowedTCPPorts =
|
|
|
|
(
|
|
|
|
lib.optionals
|
|
|
|
cfg.firewall.tcpPorts.ssh.enable [22]
|
|
|
|
cfg.firewall.tcpPorts.web.enable [80 443]
|
|
|
|
cfg.firewall.tcpPorts.smtp.enable [25 465 587]
|
|
|
|
cfg.firewall.tcpPorts.imap.enable [143 993]
|
|
|
|
cfg.firewall.tcpPorts.mysql.enable [3306]
|
|
|
|
cfg.firewall.tcpPorts.mssql.enable [1433]
|
|
|
|
cfg.firewall.tcpPorts.postgres.enable [5432]
|
|
|
|
)
|
|
|
|
++ cfg.firewall.tcpPorts.allowedPorts;
|
|
|
|
|
|
|
|
allowedUDPPorts =
|
|
|
|
(
|
|
|
|
lib.optionals
|
|
|
|
cfg.firewall.udpPorts.dns.enable [53]
|
|
|
|
cfg.firewall.udpPorts.ntp.enable [123]
|
|
|
|
)
|
|
|
|
++ cfg.firewall.udpPorts.allowedPorts;
|
|
|
|
};
|
|
|
|
|
|
|
|
networking.networkmanager = {
|
2025-01-04 17:56:53 -06:00
|
|
|
enable = lib.mkForce cfg.networkManager.enable;
|
2024-12-15 17:22:36 -06:00
|
|
|
packages = cfg.networkManager.extraPlugins;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|