Unable to install HP printer with proprietary driver despite setting allowUnfree = true in /etc/nixos/configuration.nix

Sorry about all the edits, but I’m trying to figure out how to make this post more legible…

I am new to NixOS and have been trying to install a couple of HP printers just using the NixOS standard plasma desktop environment.
When I try running:

nix run nixpkgs.hplipWithPlugin -c sudo hp-setup

it returns:

error: Package ‘hplip-3.19.12’ in /nix/var/nix/profiles/per-user/root/channels/nixos/pkgs/misc/drivers/hplip/default.nix:222 has an unfree license (‘unfree’), refusing to evaluate.

a) For nixos-rebuild you can set
{ nixpkgs.config.allowUnfree = true; }
in configuration.nix to override this.

b) For nix-env, nix-build, nix-shell or any other Nix command you can add
{ allowUnfree = true; }
to ~/.config/nixpkgs/config.nix.

(use ‘–show-trace’ to show detailed location information)

I checked /etc/nixos/configuration.nix and it has:

nixpkgs.config = {
allowUnfree = true;
};

I found a post that has addresses allowing Unfree packages

allowUnfree in configuration.nix doesn't enable instantiating unfree packages · Issue #4766 · NixOS/nixpkgs · GitHub
allowUnfree in configuration.nix doesn’t enable instantiating unfree packages #4766

but it relates to ~/.nixpkgs/config.nix; not to the system level (configuration.nix) with

sudo -i nixos-rebuild switch

Am I missing something obvious? I hope so… :worried:
I would really appreciate any help anyone could offer.
Thanks. :slightly_smiling_face:

IIRC allowUnfree in configuration.nix is only for installations through configuration.nix.

For nix run I usually do NIXPKGS_ALLOW_UNFREE=1 (I might misrember exact name of the environment variable)

Thank you for responding. :smiley:

I was hoping to install the printers through configuration.nix so all users could have access to them.
Is that not possible?

But you did nix run

Yes, I typed:

See the fifth line in my first post and then the error message I got starting a couple of lines down from there.
Maybe there was something wrong with how I typed it?

As I said, I do not think that nix run is influenced by the setting that you set in configuration.nix. Especially not if you run it as your user.

Also, using nix run is not installing for everyone through configuration.nix.

As far as I remember (can’t access my homes computer config right now, as I’m in the office), I just added pkgs.hplip to services.printing.drivers and then ran sudo hp-setup -i (or something like that for terminal mode) which then crashed shortly after printing the URL of the printer, which I then was able to use to configure CUPS through the web-UI in a imperative way.

If I don’t forget it, I’ll take a look at my config again when I’m back home and the kids are sleeping.

I figured out part of my problem.
I’m doing the setup in VirtualBox before I move it onto bare metal and I did not have the network set to bridged.

When I fixed that, I was able to use your advice to get one of the printers working through the web-UI.

The other printer (an HP LaserJet Pro P1102w) requires a proprietary plugin from HP. Grrr… That one always drives me nuts. LOL

I tried typing “hp-plugin -i” in the terminal emulator. Everything looked like it was going to work, but then it gave me an error:

Creating directory plugin_tmp
Verifying archive integrity… All good.
Uncompressing HPLIP 3.19.12 Plugin Self Extracting Archive…
/home/user/.hplip/hplip-3.19.12-plugin.run: ./hplip-plugin-install: /bin/bash: bad interpreter: No such file or directory
error: Python gobject/dbus may be not installed

Done.

pythonFull, python3Full, and dbus are all installed.
Also bash is installed;

which bash

returns:

/run/current-system/sw/bin/bash

I also tried installing

python38Packages.pygobject3

and

python27Packages.pygobject2

to no avail.

So I’m not sure what is missing.
Any additional thoughts would be more than welcome.
Thanks for helping.

Study the error carefully, it complains that a certain interpreter is not available, it seems as if the file complaining does come from a script in your homefolder, it is probably not managed by nix, but something else. Find that file and change the shebang to /usr/bin/env bash that should work as a quick fix.

Unfortunately, I cannot find any scripts in my home directory. It’s brand new and I haven’t put any in there yet. I even tried grepping for #! (both with and without escaping them). I don’t see anything executable either.

I also did an

updatedb

and then

locate hplip-plugin-install

which returned nothing.

locate hplip-3.19.12-plugin

returned

/nix/store/baj03vr1kvan03cchh63ij74dj8jq9js-hplip-3.19.12-plugin.run.drv
/nix/var/log/nix/drvs/ba/j03vr1kvan03cchh63ij74dj8jq9js-hplip-3.19.12-plugin.run.drv.bz2

The first file looked like a nix expression/derivation and the second was a binary file.

If you have any other ideas, they are more than welcome.
Thanks.

I’m beginning to suspect the #!/bin/bash may be in the
HPLIP 3.19.12 Plugin Self Extracting Archive.
In which case, I have no idea how to get to it. :anguished:

This is what the error says, so yes, due to the nesting its probably that hplib-plugin-install has been created/extracted from the hplip-3.19.12-plugin.run in which case I also have no clue how to continue, except for trying either an FHSenv (which though might fail to install the printer into the regular system) or temporarily creating /bin/bash linking to your profiles bash, which in itself is dirty enough to not do it…

Also its very likely that after installation again, other expected pathes might be hardcoded and lead to breakage later on…

Here is what I have in my configuration:

{
  services.printing = {
    enable = true;
    drivers = with pkgs; [ hplip ];
  };

  programs.system-config-printer.enable = true;
}

Thanks for helping me. I really appreciate it.

Hi Damien,

Thanks for the response. I have that in mine as well. Unfortunately, I think the problem is with how HP wrote their proprietary plugin. I think they expected and hard-coded for a standard file hierarchy.

There has been very recent changes to HP tools in nixpkgs. If you are using nixos-unstable channel you might want to try them.

That looks interesting. I am using stable, but I will have to try it. Thanks for pointing it out!

I’m a little confused on this too, I understand now the distinction between the (system-level) /etc/nixos/configuration.nix and the (user-level) config.nix, but on a fresh install, I don’t have a config.nix anywhere in my home folder. Is it supposed to be created manually?

For that matter I don’t have a ~/.config/nixpkgs directory either, nor a ~/.nixpkgs. The former of which was specified by the error from nix-env, and the latter I’m not sure where @meolar got that from?.. I’m still learning so might’ve missed something in the manual about the user-level setup, I’ve been mostly focusing on the system stuff so far.

You might want to ask your question on a dedicated thread to get more people finding it.

Thank you, I discovered you do have to create it yourself. And that part is in the manual, my bad (there are too many “sections” of manuals, it’s really confusing)

And I figured I shouldn’t clog up the forum for a relatively simple question, doesn’t this one get bumped to the front page if I reply?