Printing: Difference between revisions

From NixOS Wiki
imported>Makefu
initial batch of nixos-users
 
imported>Fadenb
m Syntax highlighting
Line 3: Line 3:
Add to <code>configuration.nix</code>:
Add to <code>configuration.nix</code>:


<pre>services.printing.enable = true;
<syntaxhighlight lang="nix">
services.printing.drivers = [ YOUR_DRIVER ];</pre>
services.printing.enable = true;
Replace <code>YOUR_DRIVER</code> with the driver of your printer. The driver is a regular derivation but should be added to <code>services.printing.drivers</code>, ''not'' <code>environment.systemPackages</code>. [https://nixos.org/nixos/packages.html Search] for eg. &quot;print driver&quot;.
services.printing.drivers = [ YOUR_DRIVER ];
</syntaxhighlight>
Replace <code>YOUR_DRIVER</code> with the driver of your printer. 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".


* Some printers might be supported by the built-in CUPS drivers
* Some printers might be supported by the built-in CUPS drivers
Line 24: Line 26:
Add to <code>configuration.nix</code>
Add to <code>configuration.nix</code>


<pre># Enable automatic discovery of the printer (from other linux systems with avahi running)
<syntaxhighlight lang="nix">
# Enable automatic discovery of the printer (from other linux systems with avahi running)
services.avahi.enable = true;
services.avahi.enable = true;
services.avahi.publish.enable = true;
services.avahi.publish.enable = true;
Line 30: Line 33:


services.printing.browsing = true;
services.printing.browsing = true;
services.printing.listenAddresses = [ &quot;*:631&quot; ]; # Not 100% sure this is needed and you might want to restrict to the local network
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
services.printing.defaultShared = true; # If you want


networking.firewall.allowedUDPPorts = [ 631 ];
networking.firewall.allowedUDPPorts = [ 631 ];
networking.firewall.allowedTCPPorts = [ 631 ];</pre>
networking.firewall.allowedTCPPorts = [ 631 ];
</syntaxhighlight>
and <code>nixos-rebuild switch</code>.
and <code>nixos-rebuild switch</code>.


Note: I ''think'' I had to check &quot;Share printers connected to this system&quot; and &quot;Allow printing from the internet&quot; 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) ==
== Client (linux) ==


If you enabled avahi user services in the server config it should be enough to turn on avahi on the client: <code>services.avahi.enable = true</code>. The printer should be found automatically (at least in the gnome print dialog).
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.
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.

Revision as of 13:15, 27 August 2017

Basic configuration

Add to configuration.nix:

services.printing.enable = true;
services.printing.drivers = [ YOUR_DRIVER ];

Replace YOUR_DRIVER with the driver of your printer. The driver is a regular derivation but should be added to services.printing.drivers, not environment.systemPackages. Search for eg. "print driver".

  • Some printers might be supported by the built-in CUPS drivers
  • HP: hplip or hplipWithPlugin depending on your exact model: Find your model and "continue". Then search for "Driver plug-in" in the page.

Then nixos-rebuild switch. This install and starts CUPS.

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.

Setup a shared printer

Server

Follow the steps in basic configuration but make sure to check "Share This Printer" when adding the printer.

It's probably a good idea to check that printing work locally at the server at this point.

Add to 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 ];

and 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 avahi user services in the server config it should be enough to turn on avahi on the client: services.avahi.enable = true. The printer should be found automatically (at least in the gnome print dialog).

Otherwise CUPS (services.printing) 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 http://HOSTNAME:631/printers/QUEUE_NAME, 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 (windows)

See https://wiki.archlinux.org/index.php/CUPS/Printer_sharing#Sharing_via_IPP for now.

Sources