Printing: Difference between revisions

imported>Onny
Further cleanup
imported>Onny
Further cleanup
Line 45: Line 45:


Search for other printer drivers in the NixOS package directory: the official list of packages is [https://search.nixos.org/packages here]. Add the driver to {{nixos:option|services.printing.drivers}}, '''not''' {{nixos:option|environment.systemPackages}}.
Search for other printer drivers in the NixOS package directory: the official list of packages is [https://search.nixos.org/packages here]. Add the driver to {{nixos:option|services.printing.drivers}}, '''not''' {{nixos:option|environment.systemPackages}}.
=== Enable autodiscovery of network printers ===
Most printers manufactured after 2013 support the [https://www.pwg.org/ipp/everywhere.html IPP Everywhere] protocol, i.e. printing without installing drivers. This is notably the case of all WiFi printers marketed as Apple-compatible ([https://support.apple.com/en-ca/HT201311 list]).
To detect these printers, add the following to your system configuration:
<syntaxhighlight lang="nix">
services.avahi = {
  enable = true;
  nssmdns = true;
  openFirewall = true;
}
</syntaxhighlight>
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 145: Line 104:


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).
=== Enable autodiscovery of network printers ===
Most printers manufactured after 2013 support the [https://www.pwg.org/ipp/everywhere.html IPP Everywhere] protocol, i.e. printing without installing drivers. This is notably the case of all WiFi printers marketed as Apple-compatible ([https://support.apple.com/en-ca/HT201311 list]).
To detect these printers, add the following to your system configuration:
<syntaxhighlight lang="nix">
services.avahi = {
  enable = true;
  nssmdns = true;
  openFirewall = true;
}
</syntaxhighlight>
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 ===
Enable network sharing of the default local printer. Note that <code>listenAddresses = [ "*:631" ];</code>  and <code>allowFrom = [ "all" ];</code> will enable anonymous access to your printer on all interfaces, you might want to restrict this.
<syntaxhighlight lang="nix">
services.avahi = {
  enable = true;
  nssmdns = true;
  openFirewall = true;
  publish = {
    enable = true;
    userServices = true;
  };
};
services.printing = {
  listenAddresses = [ "*:631" ];
  allowFrom = [ "all" ];
  browsing = true;
  defaultShared = true;
};
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]].


== Troubleshooting ==
== Troubleshooting ==