NIXOS wiki: syntax error installing HP printer with HPplugin

Maybe making once a video how to install printers on NixOS? For the rest, great system, but I need my HP printer-scanner, so back to Arco Linux.

Driver-based printing

  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.hplipWithPlugin — Drivers for HP printers, with the proprietary plugin. Use

NIXPKGS_ALLOW_UNFREE=1 nix-shell -p hplipWithPlugin --run ‘sudo -E hp-setup’ =syntax error
to add the printer, regular CUPS UI doesn’t seem to work.

  • pkgs.postscript-lexmark — Postscript drivers for Lexmark
  • — Proprietary Samsung Drivers
  • pkgs.splix — Drivers for printers supporting SPL (Samsung Printer Language).
  • pkgs.brlaser — Drivers for some Brother printers
  • pkgs.brgenml1lpr and pkgs.brgenml1cupswrapper — Generic drivers for more Brother printers [1]
  • pkgs.cnijfilter2 — Drivers for some Canon Pixma devices (Proprietary driver)
  • Some printers might be supported by built-in CUPS drivers.
  • Search for other printer drivers in the NixOS package directory: the official list of packages is here but does not list unfree packages (which is the case of many printer drivers). To list unfree packages, see The appropriate FAQ entry for installing unfree packages.(Add the driver to services.printing.drivers , not environment.systemPackages .)
  1. 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, for example system-config-printer .You may need to authenticate when you add the printer. Search the web for e.g. “cups add printer” for further information.

1 Like

This is essentially useless as a report. What did you actually do? What was the syntax error? Did you try to understand and solve the problem on your own? How did that go?

You basically just said “it doesn’t work”, and copy-pasted the directions you had already linked. I can do absolutely nothing with that.

The passive-aggressive bit about switching back to another distro isn’t helping, either. Switch if you like, but there’s no need to tell (threaten?) us about it.


Printers are nasty beasts, and each time I have to install mine again, for whatever reason, eg. because reinstalling the system, I have to redo constantly changing imperative steps to make the driver and CUPS aware of each other and the printer.

The last time I had to run hp-setup in GUI mode until it crashes to get the connection string for the printer, run hp-setup in interactive CLI-mode providing the connection string from GUI mode, until that crashed, and re run in non-interactive mode again providing yet additional arguments that I learned from the interactive mode.

After that I had to open the cups webpage, use its interface to provide said connection string, reboot once, then I was able to do a test print.

And I do not remember anymore how I managed to get the scanner working over WiFi, but that has been yet another adventure…

I also have a Samsung printer via USB. Installing it is much easier, but I have to redo that regularly, as for some reason it is somehow wired through a hardcoded store-path, which I am unable to dynamicalize…

So whenever that storepath ceases to exist (or becomes incompatible by other means) I have to remove the printer from cups, reboot, manually add the printer in cups again, reboot.

It is tedious and annyoing, and always happens when I need to print quickly but can’t just reboot…

Therefore my usualy workflow for printing became to send the documents via mail or a cloudstorage to my mobile or the company provided work laptop and use those to print and scan.

The HP though will not be a problem anymore soon. It has seen its best days, and it doesn’t print anymore as (I think) the printhead died after ~10 years. So I will continue to use it as a scanner until we have a replacement or even the scanner dies…

And on other Linuxes I also always had problems using the HP. Not as big problems as using it on Windows though… Indeed the best experience printing to HP has been on Android so far…

1 Like

I have a HP printer that doesn’t like printing as well.

I use the pkgs.hplipWithPlugin driver so:

printing = {
  enable = true;
  drivers = [ pkgs.hplipWithPlugin ];

I find I have to select the driver in CUPS, and use sockets - the jetdirect option.

Stick with it! - it’s worth it…


Hi, Tejing,
I clearly mentioned in my post it goes about a syntax error and I did note where that syntax error is.

This is what I added in configuration.nix,

NIXPKGS_ALLOW_UNFREE=1 nix-shell -p hplipWithPlugin --run ‘sudo -E hp-setup’

which gives syntax error when sudo nixos-rebuild switch

Question of agression, I really need my printer, and I was therefore forced to go back to Arco.
A person has to do what a person has to do.
There is no agression in this.

BTW I see lots of problems with HPprinters if I research Google.
Nixos has to be aware of this. Is already years like that.

Greetings (without agression)

I could not have guessed that from your original post, though I do now see that it was mixed in there.

Anyway, it makes perfect sense for that to give a syntax error, as that is not a nixos option setting, but a shell command. If I’m reading that correctly, you’re supposed to run that command after having added the associated services.printing.drivers option and rebuilt.

Hi, Tejing,

You are right.
Thing is, I did that.

services.printing.drivers = NIXPKGS_ALLOW_UNFREE=1 nix-shell -p hplipWithPlugin --run ‘sudo -E hp-setup’

services.printing.enabled = true was already active.

I installed also sane-frontend and sane-backend, cups, xsane…I also think I need f.e. foomatic.

But I have another idea that might work, and that is simply installing by sudo nix-env -i hplipWithPlugin
I think that might work. OK, on User, but that is ok.
I give that I try when I get back from work.
I let you know if I succeed.



Wait a moment…
Does I need to
services.printing.drivers = NIXPKGS_ALLOW_UNFREE=1 nix-shell -p hplipWithPlugin --run ‘sudo -E hp-setup’

services.printing.drivers = [NIXPKGS_ALLOW_UNFREE=1 nix-shell -p hplipWithPlugin --run ‘sudo -E hp-setup’]

because the wiki states services.printer.drivers = [your driver]

Will try that too. You never know.


I am not understanding your latest line.

NIXPKGS_ALLOW_UNFREE=1 is an environment variable that allows Nix to install unfree software - and 99,9% of time the configuration of printers need many closed source programs.

nix-shell -p hplipWithPlugin opens a Bash shell with a customized environment where you can find hplipWithPlugin package installed. Inside that shell you usually run interactive commands, and after exiting it the hplipWithPlugin package disappears.

nix-shell -p hplipWithPlugin--run 'sudo -E hp-setup' opens the Bash shell as described above, but it runs the command sudo -E hp-setup and, after its executions, exits the shell.

By opening the page,

pkgs.hplipWithPlugin — Drivers for HP printers, with the proprietary plugin. Use

NIXPKGS_ALLOW_UNFREE=1 nix-shell -p hplipWithPlugin --run ‘sudo -E hp-setup’

to add the printer, regular CUPS UI doesn’t seem to work.

It means that you must edit configuration.nix including services.printing.drivers = [ pkgs.hplipWithPlugin ]; and, after that, running the magic command above to add the printer.

A bit of personal story: I never used printers on Linux, but from 2004 till now I hear the same complains about them, regardless of distro. Printer manufacturers are a bit hostile, they rarely help open source developers…

1 Like


drivers = [ pkgs.hplip ]; or whatever. Like I did here:

After that addition and rebuilding/switching to that config, you are supposed to run the already mentioned command NIXPKGS_ALLOW_UNFREE=1 nix-shell -p hplipWithPlugin --run ‘sudo -E hp-setup'.

1 Like

I believe you want instead:

nixpkgs.config.allowUnfree = true;   # this is from
services.printing.drivers = [ pkgs.hplipWithPlugin ];

In your example you are mixing “imperative” command into “declarative” configuration. The nix-shell command should be run in terminal, and in configuration you should specify only package name, hplipWithPlugin.

Anderson Torres and all,

Thank you for your help.
I will test it tomorrow (sleepy now), but I think it worked.
He installed as done on other distros, with the only error “avahi-browse not installed”.
But that is for tomorrow.
I let you all know if my tests were succesfull. And I will, in return, make a video how I did it. So see YT.
To help others.

If this works, I am finally done distro hopping…So happy I will be, cause distro hopping is loosing time…
And Nixos will become my daily driver!


Just a quick reminder that for me using JetDirect (port 9100) I didn’t need the avahi stuff which simplified a lot (that seems complicated with IPv6 issues…YMMV)

So, friends. I am sorry to say that even if my printer now worked, other issues emerged. I receive now syntax errors on the sound confguration, while not even changing the sound configuration. Well, the syntax errors just do not stop. And my scanner does not work. It is problem after problem and honestly, I had it. I will continue to follow the project, but I will go for another distro. This really hurts as I really believe, this project has future if the devs succeed in maken NixOS more user friendly. DT was right. He declared in his video that even if he could do it, Nixos was frustrating to configure. I should have listened. Thank you all for helping me, but NixOS is not for me. Love you all.

It is apparent that you are the source of the syntax errors: terminating expressions with semicolons is non-optional. The syntax errors do not stop because, in evaluation, only one error is shown at a time. Based on your previously shared code, you seem to have been eliding semicolons. While you have fixed one error, there are many syntax errors (missing semicolons) you seem to have written into your configuration. For your review:

Just came to confirm that for an old HP LaserJet 1005 the following makes the printer visible in GNOME and perfectly usable:

services.printing = {
  enable = true;
  drivers = [ pkgs.hplipWithPlugin ];
  1. QT_QPA_PLATFORM=xcb NIXPKGS_ALLOW_UNFREE=1 nix-shell -p hplipWithPlugin --run 'sudo -E hp-setup'
  2. Configure the printer using the UI invoked by the previous command.
  3. (optional) Double check in Printer Manager (a GNOME application provided out of the box by default acting as a CUPS front-end) that the printer is there.

such a shame @gekxxx

gave up so easily…

but hey… that happens…

it’s a shame to lose them to windows, but hey… hopefully one day they will be back.