2024-12-15 17:22:36 -06:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}: let
|
2025-01-04 18:07:36 -06:00
|
|
|
cfg = config.network;
|
2024-12-15 17:22:36 -06:00
|
|
|
in {
|
2025-01-04 18:07:36 -06:00
|
|
|
options.network = {
|
2024-12-15 17:22:36 -06:00
|
|
|
firewall = {
|
2025-01-04 18:27:42 -06:00
|
|
|
enable = lib.mkEnableOption "system firewall";
|
2024-12-15 17:22:36 -06:00
|
|
|
tcpPorts = {
|
2025-01-04 18:27:42 -06:00
|
|
|
ssh.enable = lib.mkEnableOption "SSH service port (22)";
|
|
|
|
web.enable = lib.mkEnableOption "common web service ports (80, 443)";
|
|
|
|
smtp.enable = lib.mkEnableOption "SMTP service ports (25, 465, 587)";
|
|
|
|
imap.enable = lib.mkEnableOption "IMAP service ports (143, 993)";
|
|
|
|
mysql.enable = lib.mkEnableOption "MySQL service port (3306)";
|
|
|
|
mssql.enable = lib.mkEnableOption "Microsoft SQL Server service port (1433)";
|
|
|
|
postgres.enable = lib.mkEnableOption "Postgres service port (5432)";
|
2024-12-15 17:22:36 -06:00
|
|
|
allowedPorts = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.port;
|
|
|
|
default = [];
|
|
|
|
description = "List of custom TCP ports to open";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
udpPorts = {
|
2025-01-04 18:27:42 -06:00
|
|
|
dns.enable = lib.mkEnableOption "DNS service port (53)";
|
|
|
|
ntp.enable = lib.mkEnableOption "NTP service port (123)";
|
2024-12-15 17:22:36 -06:00
|
|
|
allowedPorts = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.port;
|
|
|
|
default = [];
|
|
|
|
description = "List of custom UDP ports to open";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
networkManager = {
|
2025-01-04 18:27:42 -06:00
|
|
|
enable = lib.mkEnableOption "NetworkManager for network connection management";
|
2024-12-15 17:22:36 -06:00
|
|
|
extraPlugins = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.package;
|
|
|
|
default = [];
|
|
|
|
description = "Additional NetworkManager plugins to install";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
config = {
|
2025-01-04 18:27:42 -06:00
|
|
|
networking.firewall = {
|
2024-12-15 17:22:36 -06:00
|
|
|
enable = cfg.firewall.enable;
|
2025-01-04 18:27:42 -06:00
|
|
|
allowedTCPPorts = lib.flatten [
|
|
|
|
(lib.optionals cfg.firewall.tcpPorts.ssh.enable [22])
|
|
|
|
(lib.optionals cfg.firewall.tcpPorts.web.enable [80 443])
|
|
|
|
(lib.optionals cfg.firewall.tcpPorts.smtp.enable [25 465 587])
|
|
|
|
(lib.optionals cfg.firewall.tcpPorts.imap.enable [143 993])
|
|
|
|
(lib.optionals cfg.firewall.tcpPorts.mysql.enable [3306])
|
|
|
|
(lib.optionals cfg.firewall.tcpPorts.mssql.enable [1433])
|
|
|
|
(lib.optionals cfg.firewall.tcpPorts.postgres.enable [5432])
|
|
|
|
cfg.firewall.tcpPorts.allowedPorts
|
|
|
|
];
|
|
|
|
allowedUDPPorts = lib.flatten [
|
|
|
|
(lib.optionals cfg.firewall.udpPorts.dns.enable [53])
|
|
|
|
(lib.optionals cfg.firewall.udpPorts.ntp.enable [123])
|
|
|
|
cfg.firewall.udpPorts.allowedPorts
|
|
|
|
];
|
2024-12-15 17:22:36 -06:00
|
|
|
};
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|