How to configure "hardware.printers.ensurePrinters"?

I don’t understand how to configure hardware.printers.ensurePrinters (NixOS Search) with its associated options. I don’t know what should go into this option and its children like hardware.printers.ensurePrinters.*.name - i don’t even know with what to replace the asterix with…

It would be great if someone could post an example configuration. The Printing article in the wiki doesn’t explain this option unfortunately.

@florianjacob @edolstra @Infinisil @worldofpeace

Example: https://github.com/grahamc/nixos-config/blob/35388280d3b06ada5882d37c5b4f6d3baa43da69/devices/petunia/configuration.nix#L573

1 Like

Ah i see, thank you! :slightly_smiling_face:

Is it corect to write model = "drv:///brlaser.drv/brl2320d.ppd"; or do i need to shorten it? In your configuration it’s a bit different…

I really struggled to find out what value to pass to model for my HP Color LaserJet cp1515n, whose PPD is provided by pkgs.gutenprint.
Tried various values, but my ensure-printers.service just kept on failing and its attempts to configure the printer via lpadmin just resulted in many messages like this in the journal of cups.service:

Jan 22 00:20:12 homeserver cupsd[581485]: [cups-driverd] Unable to open "/nix/store/4mlz5z9z8n4082w9gsrrx188r925bd45-cups-progs/share/cups/model/HP Color LaserJet CP1515n - CUPS+Gutenprint v5.3.4" - No such file or directory
Jan 22 00:20:12 homeserver cupsd[581485]: REQUEST localhost - - "POST / HTTP/1.1" 200 396 CUPS-Get-PPD -
Jan 22 00:20:12 homeserver cupsd[581485]: Hint: Try setting the LogLevel to "debug" to find out more.
Jan 22 00:20:12 homeserver cupsd[581485]: REQUEST localhost - - "POST /admin/ HTTP/1.1" 401 448 CUPS-Add-Modify-Printer successful-ok
Jan 22 00:20:12 homeserver cupsd[581485]: Setting cp1515n device-uri to "dnssd://HP%20Color%20LaserJet%20CP1515n%20(2E144A)._pdl-datastream._tcp.local/" (was "file:///dev/null".)
Jan 22 00:20:12 homeserver cupsd[581485]: Setting cp1515n printer-is-accepting-jobs to 1 (was 0.)
Jan 22 00:20:12 homeserver cupsd[581485]: Setting cp1515n printer-state to 3 (was 5.)
Jan 22 00:20:12 homeserver cupsd[581485]: [cups-driverd] Unable to open "/nix/store/4mlz5z9z8n4082w9gsrrx188r925bd45-cups-progs/share/cups/model/HP Color LaserJet CP1515n - CUPS+Gutenprint v5.3.4" - No such file or directory
Jan 22 00:20:12 homeserver cupsd[581485]: copy_model: empty PPD file
Jan 22 00:20:12 homeserver cupsd[581485]: [Client 89] Returning IPP server-error-internal-error for CUPS-Add-Modify-Printer (ipp://localhost:631/printers/cp1515n) from localhost.
Jan 22 00:20:12 homeserver cupsd[581485]: Hint: Try setting the LogLevel to "debug" to find out more.
Jan 22 00:20:12 homeserver cupsd[581485]: REQUEST localhost - root "POST /admin/ HTTP/1.1" 200 448 CUPS-Add-Modify-Printer server-error-internal-error

I had to:

  • ensure pkgs.gutenprint is listed in services.printing.drivers
  • grep the output of lpinfo -m for the correct model
  • use the resulting gutenprint.5.3:// URL as model

The result looks like this:

hardware.printers.ensurePrinters = [
  {
    name = "cp1515n";
    description = "HP Color LaserJet cp1515n";
    location = "Office desk eliasp";
    deviceUri = "dnssd://HP%20Color%20LaserJet%20CP1515n%20(2E144A)._pdl-datastream._tcp.local/";
    # TODO: replace "5.3" dynamically based on gutenprint version
    model = "gutenprint.5.3://hp-clj_cp1515n/expert";
    ppdOptions = {
      pageSize = "A4";
    };
  }
];