Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/printing: Add openFirewall option #176539

Merged
merged 1 commit into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions nixos/modules/services/printing/cupsd.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
onny marked this conversation as resolved.
Show resolved Hide resolved
extractPort = addr: builtins.elemAt (builtins.tail (splitAddress addr)) 0;
onny marked this conversation as resolved.
Show resolved Hide resolved
toInt = str: lib.strings.toInt str;
onny marked this conversation as resolved.
Show resolved Hide resolved
in
builtins.map (address: toInt (extractPort address)) addresses;

in

{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 ];
Expand Down
2 changes: 1 addition & 1 deletion nixos/tests/printing.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ import ./make-test-python.nix (
startWhenNeeded = socket;
listenAddresses = [ "*:631" ];
defaultShared = true;
openFirewall = true;
extraConf = ''
<Location />
Order allow,deny
Allow from all
</Location>
'';
};
networking.firewall.allowedTCPPorts = [ 631 ];
# Add a HP Deskjet printer connected via USB to the server.
hardware.printers.ensurePrinters = [{
name = "DeskjetLocal";
Expand Down