Printing

From NixOS Wiki
Revision as of 18:12, 24 October 2017 by imported>HLandau

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