diff options
author | Jonas Heinrich <onny@project-insanity.org> | 2023-11-05 16:01:20 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-05 16:01:20 +0100 |
commit | 35128eb6f81381da2a38094d6b3976c61d792489 (patch) | |
tree | 2045acfe89840fe177de0bae5edd1b008f047342 /nixos/modules | |
parent | 315e3635bf17229eb5f8da66c755de83960f0e36 (diff) |
nixos/printing: Add openFirewall option (#176539)
Diffstat (limited to 'nixos/modules')
-rw-r--r-- | nixos/modules/services/printing/cupsd.nix | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/nixos/modules/services/printing/cupsd.nix b/nixos/modules/services/printing/cupsd.nix index 279b26bb8957..25367f8e61d4 100644 --- a/nixos/modules/services/printing/cupsd.nix +++ b/nixos/modules/services/printing/cupsd.nix @@ -108,6 +108,13 @@ let containsGutenprint = pkgs: length (filterGutenprint pkgs) > 0; getGutenprint = pkgs: head (filterGutenprint pkgs); + parsePorts = addresses: let + splitAddress = addr: lib.strings.splitString ":" addr; + extractPort = addr: builtins.elemAt (builtins.tail (splitAddress addr)) 0; + toInt = str: lib.strings.toInt str; + in + builtins.map (address: toInt (extractPort address)) addresses; + in { @@ -172,6 +179,15 @@ in ''; }; + openFirewall = mkOption { + type = types.bool; + default = false; + description = '' + Whether to open the firewall for TCP/UDP ports specified in + listenAdrresses option. + ''; + }; + bindirCmds = mkOption { type = types.lines; internal = true; @@ -463,6 +479,13 @@ in security.pam.services.cups = {}; + networking.firewall = let + listenPorts = parsePorts cfg.listenAddresses; + in mkIf cfg.openFirewall { + allowedTCPPorts = listenPorts; + allowedUDPPorts = listenPorts; + }; + }; meta.maintainers = with lib.maintainers; [ matthewbauer ]; |