nixos/printing: Add openFirewall option (#176539)

Changed files
+24 -1
nixos
modules
services
printing
tests
+23
nixos/modules/services/printing/cupsd.nix
···
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
{
···
apply = concatMapStringsSep "\n" (x: "Allow ${x}");
description = lib.mdDoc ''
From which hosts to allow unconditional access.
+
'';
+
};
+
+
openFirewall = mkOption {
+
type = types.bool;
+
default = false;
+
description = ''
+
Whether to open the firewall for TCP/UDP ports specified in
+
listenAdrresses option.
'';
};
···
'';
security.pam.services.cups = {};
+
+
networking.firewall = let
+
listenPorts = parsePorts cfg.listenAddresses;
+
in mkIf cfg.openFirewall {
+
allowedTCPPorts = listenPorts;
+
allowedUDPPorts = listenPorts;
+
};
};
+1 -1
nixos/tests/printing.nix
···
startWhenNeeded = socket;
listenAddresses = [ "*:631" ];
defaultShared = true;
+
openFirewall = true;
extraConf = ''
<Location />
Order allow,deny
···
</Location>
'';
};
-
networking.firewall.allowedTCPPorts = [ 631 ];
# Add a HP Deskjet printer connected via USB to the server.
hardware.printers.ensurePrinters = [{
name = "DeskjetLocal";