Printing: Difference between revisions

imported>Onny
Further cleanup
imported>Onny
Further cleanup
Line 60: Line 60:


Discovery is done via the opened UDP port <code>5353</code>. Printers should get automatically detected and visible in your printer configuration client.
Discovery is done via the opened UDP port <code>5353</code>. Printers should get automatically detected and visible in your printer configuration client.
=== Printer sharing ===
If you want to share a local printer on the network, follow the steps in [[#basic-configuration|Basic Configuration]], but check &#8220;Share This Printer&#8221; when adding it to CUPS. If you have already added the printer to CUPS, reconfigure it to make it a shared printer.</li>
<syntaxhighlight lang="nix">
services.avahi = {
  enable = true;
  publish = {
    enable = true;
    userServices = true;
  };
};
services.printing = {
  browsing = true;
  listenAddresses = [ "*:631" ];
  allowFrom = [ "all" ];  # this gives access to anyone on the interface you might want to limit it see the official documentation
  defaultShared = true; # If you want
};
networking.firewall = {
  allowedTCPPorts = [ 631 ];
  allowedUDPPorts = [ 631 ];
};
</syntaxhighlight>
Once printer sharing is enabled, it could be additionally advertised in the home network via the Samba protocol, [[Samba#Printer_sharing|see]].


==== With a raw PPD ====
==== With a raw PPD ====
Line 120: Line 146:
For debugging purpose, it may be interesting to note that the data folder used by cups (containing the drivers and more) can be obtained by looking in the environment <code>$CUPS_DATADIR</code> (the contents of <code>$out/share/cups/</code> contained in your drivers are linked in this folder).
For debugging purpose, it may be interesting to note that the data folder used by cups (containing the drivers and more) can be obtained by looking in the environment <code>$CUPS_DATADIR</code> (the contents of <code>$out/share/cups/</code> contained in your drivers are linked in this folder).


==Setting up shared printers==
== Troubleshooting ==
 
===Server===
 
<ol>
<li>If you want to share a local printer on the network, follow the steps in [[#basic-configuration|Basic Configuration]], but check &#8220;Share This Printer&#8221; when adding it to CUPS. If you have already added the printer to CUPS, reconfigure it to make it a shared printer.</li>
<li>You should probably check that printing works locally at this point.</li>
<li>Amend <tt>/etc/nixos/configuration.nix</tt>:
<syntaxhighlight lang="nix">
{
  ...
 
  # Enable automatic discovery of the printer from other Linux systems with avahi running.
  services.avahi.enable = true;
  services.avahi.publish.enable = true;
  services.avahi.publish.userServices = true;
  services.printing.browsing = true;
  services.printing.listenAddresses = [ "*:631" ]; # Not 100% sure this is needed and you might want to restrict to the local network
  services.printing.allowFrom = [ "all" ]; # this gives access to anyone on the interface you might want to limit it see the official documentation
  services.printing.defaultShared = true; # If you want
 
  networking.firewall.allowedUDPPorts = [ 631 ];
  networking.firewall.allowedTCPPorts = [ 631 ];
 
  ...
}
</syntaxhighlight></li>
<li>Rebuild: <syntaxhighlight lang="console">$ sudo nixos-rebuild switch</syntaxhighlight></li></ol>
 
Note: I ''think'' I had to check "Share printers connected to this system" and "Allow printing from the internet" at http://192.168.11.9:631/admin but I'm not sure.
 
{{outdated|Needs checking to rectify uncertainty in instructions}}
 
Once printer sharing is enabled, it could be additionally advertised in the home network via the Samba protocol, [[Samba#Printer_sharing|see]].
 
===See also===
 
* [https://github.com/NixOS/nixpkgs/issues/13901 How to properly setup a shared (home) printer? #13901]
* [https://wiki.archlinux.org/index.php/CUPS/Printer_sharing Printer sharing (Arch Linux wiki)]
* [https://github.com/NixOS/nixpkgs/issues/23993 Little Printing/CUPS Documentation for Configuration as a Print Server #23993]
* [https://web.archive.org/web/20160829175522/https://nixos.org/wiki/Printers Old wiki page]
 
[[Category:Configuration]][[Category:Hardware]]
 
==Troubleshooting==


=== Adding network printer "Name or service not known" ===
=== Adding network printer "Name or service not known" ===
Line 260: Line 242:


Now watch the cups logs for errors like <code>No such file or directory</code>
Now watch the cups logs for errors like <code>No such file or directory</code>
[[Category:Printing]]
[[Category:Hardware]]