NixOS/modules/network/firewall.nix
Danilo Reyes 28ef0d8108
Some checks failed
Weekly NixOS Build & Cache / build-and-cache (push) Failing after 1m55s
fixes qbittorrent, nextcloud python update, firewall logic
2025-10-18 10:12:09 -06:00

53 lines
1.4 KiB
Nix

{
lib,
config,
inputs,
...
}:
let
firewallBlacklist = [
"sabnzbd"
"lidarr"
"maloja"
"tranga"
"flame"
"flameSecret"
"ryot"
"drpp"
"metube"
"multi-scrobbler"
"plex-discord-bot"
];
nativeServicesWithOpenFirewall = inputs.self.lib.getServicesWithNativeFirewall config firewallBlacklist;
servicesConfig = lib.listToAttrs (
map (serviceName: {
name = serviceName;
value.openFirewall = config.my.servers.${serviceName}.enable or false;
}) nativeServicesWithOpenFirewall
);
in
{
options.my.network.firewall = {
enabledServicePorts = lib.mkEnableOption "auto-open ports for enabled services";
staticPorts = lib.mkOption {
type = lib.types.listOf lib.types.int;
default = [ ];
description = "Static ports to always open";
};
additionalPorts = lib.mkOption {
type = lib.types.listOf lib.types.int;
default = [ ];
description = "Additional ports to open (like syncthing, gitea, etc.)";
};
};
config = lib.mkIf config.my.network.firewall.enabledServicePorts {
services = servicesConfig;
networking.firewall.allowedTCPPorts =
inputs.self.lib.generateFirewallPorts config nativeServicesWithOpenFirewall lib
++ (lib.optionals config.services.nginx.enable [
config.services.nginx.defaultHTTPListenPort
config.services.nginx.defaultSSLListenPort
]);
};
}