Printing: Difference between revisions

From NixOS Wiki
imported>MasseGuillaume
mNo edit summary
imported>HLandau
No edit summary
Line 1: Line 1:
= Basic configuration =
=Basic configuration=


Add to <code>configuration.nix</code>:
<ol><li>Add to <code>/etc/nixos/configuration.nix</code>:


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
services.printing.enable = true;
{
services.printing.drivers = [ YOUR_DRIVER ];
  ...
  services.printing.enable = true;
  services.printing.drivers = [ YOUR_DRIVER ];
  ...
}
</syntaxhighlight>
</syntaxhighlight>
Replace <code>YOUR_DRIVER</code> with the driver of your printer (eg. <code>pkgs.gutenprintBin</code>). The driver is a regular derivation but should be added to <syntaxhighlight lang="nix" inline>services.printing.drivers</syntaxhighlight>, ''not'' <syntaxhighlight lang="nix" inline>environment.systemPackages</syntaxhighlight>. [https://nixos.org/nixos/packages.html Search] for eg. "print driver".
where <code>YOUR_DRIVER</code> is the driver package appropriate for your printer. Commonly used driver packages include:


* Some printers might be supported by the built-in CUPS drivers
* <tt>pkgs.gutenprint</tt> &mdash; Drivers for many different printers from many different vendors.
* HP: <code>pkgs.hplip</code> or <code>pkgs.hplipWithPlugin</code> depending on your [http://hplipopensource.com/hplip-web/supported_devices/index.html exact model]: Find your model and "continue". Then search for "Driver plug-in" in the page.
* <tt>pkgs.gutenprintBin</tt> &mdash; Additional, binary-only drivers for some printers.
* <tt>pkgs.hplip</tt> &mdash; Drivers for HP printers.
* <tt>pkgs.splix</tt> &mdash; Drivers for printers supporting SPL (Samsung Printer Language).
* Some printers might be supported by built-in CUPS drivers.
* [https://nixos.org/nixos/packages.html Search for other printer drivers in the NixOS package directory.]


Then <code>nixos-rebuild switch</code>. This installs and starts CUPS.
(Add the driver to {{nixos:option|services.printing.drivers}}, '''not''' {{nixos:option|environment.systemPackages}}.)
<li>Rebuild: <syntaxHighlight lang="console">$ sudo nixos-rebuild switch</syntaxHighlight>
CUPS will be started automatically.</li>
<li><p>Navigate to <tt>http://localhost:631/</tt> in a web browser to configure printers. Alternatively, some desktop environments may provide GUI interfaces for adding printers.</p>


Go to http://localhost:631 to add the printer. Note that you need to authenticate as root (or yourself if you have sudo access) when you add the printer. Search the web for eg. "cups add printer" for further help.
<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>


= Setup a shared printer =
=Setting up shared printers=
==Server==


== Server ==
<ol>
<li>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">
{
  ...


Follow the steps in [[#basic-configuration|basic configuration]] but make sure to check "Share This Printer" when adding the printer.
  # 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;


It's probably a good idea to check that printing work locally at the server at this point.
  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.defaultShared = true; # If you want


Add to <code>configuration.nix</code>
  networking.firewall.allowedUDPPorts = [ 631 ];
  networking.firewall.allowedTCPPorts = [ 631 ];


<syntaxhighlight lang="nix">
  ...
# Enable automatic discovery of the printer (from other linux systems with avahi running)
}
services.avahi.enable = true;
</syntaxhighlight></li>
services.avahi.publish.enable = true;
<li>Rebuild: <syntaxhighlight lang="console">$ sudo nixos-rebuild switch</syntaxhighlight></li></ol>
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.defaultShared = true; # If you want
 
networking.firewall.allowedUDPPorts = [ 631 ];
networking.firewall.allowedTCPPorts = [ 631 ];
</syntaxhighlight>
and <code>nixos-rebuild switch</code>.


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.
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.


== Client (linux) ==
{{outdated|Needs checking to rectify uncertainty in instructions}}
 
If you enabled avahi user services in the server config it should be enough to turn on avahi on the client: <syntaxhighlight lang="nix" inline>services.avahi.enable = true</syntaxhighlight>. The printer should be found automatically (at least in the gnome print dialog).
 
Otherwise CUPS (<code>services.printing</code>) should be enabled on the client too and a new network printer should be added to the local CUPS instance (http://localhost:631). Despite what the CUPS interface tell you the url scheme is <code>http://HOSTNAME:631/printers/QUEUE_NAME</code>, where QUEUE_NAME is the name you gave the printer at the server.
 
NB: https might not work due to missing certificates.


Refer to eg. https://wiki.archlinux.org/index.php/CUPS/Printer_sharing for further info.
== Client (Linux) ==


If you enabled {{nixos:option|services.avahi.publish.userServices}} in the server configuration, enabling printing and avahi on the client should be sufficient for the printer to be detected:
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
services = {
{
    avahi = {
  ...
      enable = true;
  services.printing.enable = true;
      nssmdns = true;
  services.avahi.enable = true;
    };
  services.avahi.nssmdns = true;
    printing.enable = true;
}
}
</syntaxhighlight>
</syntaxhighlight>


You can setup CUPS by connection to http://localhost:631/
Alternately, the printer can be added to the client's CUPS daemon by navigating to <tt>http://localhost:631/</tt> in a web browser and adding the remote printer.
 
Click on Administration on the top bar
 
Then add a printer.
 
A list of Discovered Network Printers should be available if you have a network printer.
 
<syntaxhighlight lang="txt">
Discovered Network Printers: Brother HL-5370DW series (Brother HL-5370DW series)
Other Network Printers: LPD/LPR Host or Printer
Internet Printing Protocol (ipp)
Backend Error Handler
Internet Printing Protocol (https)
AppSocket/HP JetDirect
Internet Printing Protocol (ipps)
Internet Printing Protocol (http)
Windows Printer via SAMBA
Continue
</syntaxhighlight>
 
The PPD File should be available from the vendor website. For example the Brother HL-5370DW is available here: http://support.brother.com/g/s/id/linux/en/download_prn.html#HL-5370DW
 
== Client (windows) ==
 
See https://wiki.archlinux.org/index.php/CUPS/Printer_sharing#Sharing_via_IPP for now.


=== Sources ===
==See also==


* [https://github.com/NixOS/nixpkgs/issues/13901 How to properly setup a shared (home) printer? #13901]
* [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 Arch wiki - Printer sharing]
* [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://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]
* [https://web.archive.org/web/20160829175522/https://nixos.org/wiki/Printers Old wiki page]

Revision as of 18:11, 24 October 2017

Basic configuration

  1. Add to /etc/nixos/configuration.nix:
    {
      ...
      services.printing.enable = true;
      services.printing.drivers = [ YOUR_DRIVER ];
      ...
    }
    

    where YOUR_DRIVER is the driver package appropriate for your printer. Commonly used driver packages include:

    • pkgs.gutenprint — Drivers for many different printers from many different vendors.
    • pkgs.gutenprintBin — Additional, binary-only drivers for some printers.
    • pkgs.hplip — Drivers for HP printers.
    • pkgs.splix — Drivers for printers supporting SPL (Samsung Printer Language).
    • Some printers might be supported by built-in CUPS drivers.
    • Search for other printer drivers in the NixOS package directory.

    (Add the driver to services.printing.drivers, not environment.systemPackages.)

  2. Rebuild:
    $ sudo nixos-rebuild switch
    
    CUPS will be started automatically.
  3. Navigate to http://localhost:631/ in a web browser to configure printers. Alternatively, some desktop environments may provide GUI interfaces for adding printers.

    You may need to authenticate when you add the printer. Search the web for e.g. “cups add printer” for further information.

Setting up shared printers

Server

  1. Follow the steps in Basic Configuration, but check “Share This Printer” when adding it to CUPS. If you have already added the printer to CUPS, reconfigure it to make it a shared printer.
  2. You should probably check that printing works locally at this point.
  3. Amend /etc/nixos/configuration.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.defaultShared = true; # If you want
    
      networking.firewall.allowedUDPPorts = [ 631 ];
      networking.firewall.allowedTCPPorts = [ 631 ];
    
      ...
    }
    
  4. Rebuild:
    $ sudo nixos-rebuild switch
    

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.

Client (Linux)

If you enabled services.avahi.publish.userServices in the server configuration, enabling printing and avahi on the client should be sufficient for the printer to be detected:

{
  ...
  services.printing.enable = true;
  services.avahi.enable = true;
  services.avahi.nssmdns = true;
}

Alternately, the printer can be added to the client's CUPS daemon by navigating to http://localhost:631/ in a web browser and adding the remote printer.

See also