Printing: Difference between revisions

imported>IgorM
m Fixed highlighting in console examples
imported>Onny
First work on major cleanup of the page
Line 1: Line 1:
==IPP everywhere capable printer==
Printing in NixOS is done via the <code>services.printing</code> module, to configure the local printing services which is provided by the software [https://openprinting.github.io/projects/00-cups CUPS]. Setting up physical printer devices is done using <code>hardware.printers</code> option.
 
== Installation ==
 
To enable the local print service on your machine, simply add following lines to your configuration
 
<syntaxhighlight lang="nix">
services.printing.enable = true;
</syntaxhighlight>
 
== Usage ==
 
After enabling the printing service you'll be able to configure and add network printers via http://localhost:631.
 
Depending on your desktop environment, there are several graphical tools available which will connect to this backend service and allow you a more convenient printer management.
 
== Configuration ==
 
=== 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]).
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:
To detect these printers, add the following to your system configuration:
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{
services.avahi = {
  ...
   enable = true;
  services.printing.enable = true; # enables printing support via the CUPS daemon
   nssmdns = true;
   services.avahi.enable = true; # runs the Avahi daemon
   openFirewall = true;
   services.avahi.nssmdns = true; # enables the mDNS NSS plug-in
   services.avahi.openFirewall = true; # opens the firewall for UDP port 5353
  ...
}
}
</nowiki>}}
</nowiki>}}
After running <code>nixos-rebuild switch</code>, detected printers should appear automatically.


== Driver-based printing ==
Discovery is done via the opened UDP port <code>5353</code>. Printers should get automatically detected and visible in your printer configuration client.
 
=== Driver-based printing ===
<ol><li>Add to <code>/etc/nixos/configuration.nix</code>:
<ol><li>Add to <code>/etc/nixos/configuration.nix</code>:


Line 49: Line 66:
<p>You may need to authenticate when you add the printer. Search the web for e.g. &#8220;cups add printer&#8221; for further information.</p></li></ol>
<p>You may need to authenticate when you add the printer. Search the web for e.g. &#8220;cups add printer&#8221; for further information.</p></li></ol>


=== With a raw PPD ===
==== With a raw PPD ====
===== Provide the PPD imperatively =====
====== Provide the PPD imperatively ======
If no driver is found for your printer, even when <code>services.printing.drivers</code> is correctly populated (see above),
If no driver is found for your printer, even when <code>services.printing.drivers</code> is correctly populated (see above),
you can try to give cups a PPD file.  
you can try to give cups a PPD file.  
Line 57: Line 74:
* add the printer with <code>system-config-printer</code> (for example) and at the 'choose driver' screen choose 'provide PPD file'
* add the printer with <code>system-config-printer</code> (for example) and at the 'choose driver' screen choose 'provide PPD file'


===== Provide the PPD declaratively =====
====== Provide the PPD declaratively ======


You can also declaratively add the PPD as a new driver by creating a simple derivation. You just need to create a derivation that puts the PPD file in <code>$out/share/cups/model/yourfile.ppd</code> (you can also put it in a subfolder like <code>$out/share/cups/model/HP/yourfile.ppd</code> to limit conflicts between ppd having the same name). Note that the name of the file does not change the way cups will list it as the model/manufacturer is written inside the (text) ppd.
You can also declaratively add the PPD as a new driver by creating a simple derivation. You just need to create a derivation that puts the PPD file in <code>$out/share/cups/model/yourfile.ppd</code> (you can also put it in a subfolder like <code>$out/share/cups/model/HP/yourfile.ppd</code> to limit conflicts between ppd having the same name). Note that the name of the file does not change the way cups will list it as the model/manufacturer is written inside the (text) ppd.