NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.33k stars 13.57k forks source link

hplip broken on 16.09 #19469

Closed ericsagnes closed 7 years ago

ericsagnes commented 7 years ago

Issue description

hp-setup returns error when run.

Steps to reproduce

Run hp-setup from latest nixos-16.09

$ hp-setup
Traceback (most recent call last):
  File "/nix/store/byhr0cq87gflppackr7vxrxn8nhw0frs-hplip-3.16.5/share/hplip/setup.py", line 48, in <module>
    from base import device, utils, tui, models, module, services, os_utils
  File "/nix/store/byhr0cq87gflppackr7vxrxn8nhw0frs-hplip-3.16.5/share/hplip/base/device.py", line 42, in <module>
    from . import status
  File "/nix/store/byhr0cq87gflppackr7vxrxn8nhw0frs-hplip-3.16.5/share/hplip/base/status.py", line 33, in <module>
    import cupsext
ImportError: No module named cupsext

cc hplip maintainers @jgeerds @nckx

Technical details

cmfwyp commented 7 years ago

This might be related to the recent Python 3 changes in Nixpkgs: http://hplipopensource.com/node/372. Also, 3.16.5 is not the latest hplip version.

Mic92 commented 7 years ago

@ericsagnes

does the following work for you?

diff --git a/pkgs/misc/drivers/hplip/default.nix b/pkgs/misc/drivers/hplip/default.nix
index bf0af6b..e718b43 100644
--- a/pkgs/misc/drivers/hplip/default.nix
+++ b/pkgs/misc/drivers/hplip/default.nix
@@ -1,6 +1,6 @@
 { stdenv, fetchurl, substituteAll
 , pkgconfig
-, cups, zlib, libjpeg, libusb1, pythonPackages, sane-backends, dbus, usbutils
+, cups, zlib, libjpeg, libusb1, python3Packages, sane-backends, dbus, usbutils
 , net_snmp, openssl, polkit
 , bash, coreutils, utillinux
 , qtSupport ? true, qt4
@@ -10,16 +10,16 @@
 let

   name = "hplip-${version}";
-  version = "3.16.5";
+  version = "3.16.9";

   src = fetchurl {
     url = "mirror://sourceforge/hplip/${name}.tar.gz";
-    sha256 = "1nay65q1zmx2jxiwn66n7mlr73azacz5097gw98kqqf90dh522f6";
+    sha256 = "19lp6xfm7ixfdkd77l7s89mph33qb0614gshsvfkqh51pakz536c";
   };

   plugin = fetchurl {
     url = "http://www.openprinting.org/download/printdriver/auxfiles/HP/plugins/${name}-plugin.run";
-    sha256 = "15qrcd3ndnxri6pfdfmsjyv2f3zfkig80yghs76jbsm106rp8g3q";
+    sha256 = "17ww6hickvhl3j1i4kawh87sr07jqgg6cwhilwqbafwlvmwsp53k";
   };

   hplipState =
@@ -54,8 +54,8 @@ stdenv.mkDerivation {
     libjpeg
     cups
     libusb1
-    pythonPackages.python
-    pythonPackages.wrapPython
+    python3Packages.python
+    python3Packages.wrapPython
     sane-backends
     dbus
     net_snmp
@@ -68,10 +68,10 @@ stdenv.mkDerivation {
     pkgconfig
   ];

-  pythonPath = with pythonPackages; [
+  pythonPath = with python3Packages; [
     dbus
     pillow
-    pygobject2
+    pygobject3
     recursivePthLoader
     reportlab
     usbutils
@@ -149,31 +149,18 @@ stdenv.mkDerivation {
     rm $out/etc/udev/rules.d/56-hpmud.rules
   '';

-  fixupPhase = ''
+  preFixup = ''
     # Wrap the user-facing Python scripts in $out/bin without turning the
-    # ones in $out /share into shell scripts (they need to be importable).
+    # ones in $out /share into shell scripts (they need to be importable)
     # Note that $out/bin contains only symlinks to $out/share.
     for bin in $out/bin/*; do
       py=`readlink -m $bin`
-      rm $bin
-      cp $py $bin
-      wrapPythonProgramsIn $bin "$out $pythonPath"
-      sed -i "s@$(dirname $bin)/[^ ]*@$py@g" $bin
+      new_name="$(dirname $py)/$(basename $bin)"
+      cp "$py" "$new_name"
+      ln -sf "$new_name" "$bin"
+      chmod -x "$py"
     done
-
-    # Remove originals. Knows a little too much about wrapPythonProgramsIn.
-    rm -f $out/bin/.*-wrapped
-
-    # Merely patching shebangs in $out/share does not cause trouble.
-    for i in $out/share/hplip{,/*}/*.py; do
-      substituteInPlace $i \
-        --replace /usr/bin/python \
-        ${pythonPackages.python}/bin/${pythonPackages.python.executable} \
-        --replace "/usr/bin/env python" \
-        ${pythonPackages.python}/bin/${pythonPackages.python.executable}
-    done
-
-    wrapPythonProgramsIn $out/lib "$out $pythonPath"
+    wrapPythonProgramsIn "$out" "$out $pythonPath"

     substituteInPlace $out/etc/hp/hplip.conf --replace /usr $out
   '' + stdenv.lib.optionalString (!withPlugin) ''

I use it like this:

# /etc/nixos/configuration.nix
nixpkgs.config = {
  packagesOverrides = pkgs: rec {
    hplip = pkgs.hplip.override {                                                                                                                                          
      withPlugin = true;                                                                                                                                                   
    };
  };
};

printing = {
  enable = true;
  drivers = [ pkgs.hplip ];
}
ericsagnes commented 7 years ago

Thanks! This make hp-setup work, but it fails finding the printer.

Running hp-check shows a bunch of missing dependencies that might be the cause:

------------------------
| General Dependencies |
------------------------

 python3-pil          PIL - Python Imaging Library (required for commandline scanning with hp-scan) OPTIONAL        -               1.1.7           OK         -
 error: libcrypto     libcrypto - OpenSSL cryptographic library                    REQUIRED        -               -               MISSING    'libcrypto needs to be installed'
 error: libusb        libusb - USB library                                         REQUIRED        -               1.0             MISSING    'libusb needs to be installed'
 python3-pyqt4        PyQt 4- Qt interface for Python (for Qt version 4.x)         REQUIRED        4.0             4.11.3          OK         -
 error: libjpeg       libjpeg - JPEG library                                       REQUIRED        -               -               MISSING    'libjpeg needs to be installed'
 python3-pyqt4-dbus   PyQt 4 DBus - DBus Support for PyQt4                         OPTIONAL        4.0             4.11.3          OK         -
 python3X             Python 2.2 or greater - Python programming language          REQUIRED        2.2             3.5.2           OK         -
 python3-dbus         Python DBus - Python bindings for DBus                       REQUIRED        0.80.0          1.2.4           OK         -
 error: python3-devel Python devel - Python development files                      REQUIRED        2.2             3.5.2           MISSING    'python3-devel needs to be installed'
 error: sane          SANE - Scanning library                                      REQUIRED        -               1.0.25          MISSING    'sane needs to be installed'
 python3-xml          Python XML libraries                                         REQUIRED        -               2.1.1           OK         -
 error: cups-devel    CUPS devel- Common Unix Printing System development files    REQUIRED        -               -               MISSING    'cups-devel needs to be installed'
 error: cups-image    CUPS image - CUPS image development files                    REQUIRED        -               -               MISSING    'cups-image needs to be installed'
 error: libpthread    libpthread - POSIX threads library                           REQUIRED        -               b'2.24'         MISSING    'libpthread needs to be installed'
 error: cups-ddk      CUPS DDK - CUPS driver development kit                       OPTIONAL        -               -               MISSING    'cups-ddk needs to be installed'
 error: libnetsnmp-devel libnetsnmp-devel - SNMP networking library development files REQUIRED        5.0.9           -               MISSING    'libnetsnmp-devel needs to be installed'
 error: python3-notify2 Python libnotify - Python bindings for the libnotify Desktop notifications OPTIONAL        -               -               MISSING    'python3-notify2 needs to be installed'
 error: sane-devel    SANE - Scanning library development files                    REQUIRED        -               1.0.25          MISSING    'sane-devel needs to be installed'
 python3-reportlab    Reportlab - PDF library for Python                           OPTIONAL        2.0             3.2.0           OK         -

--------------
| COMPILEDEP |
--------------

 error: make          make - GNU make utility to maintain groups of programs       REQUIRED        3.0             -               MISSING    'make needs to be installed'
 error: libtool       libtool - Library building support services                  REQUIRED        -               -               MISSING    'libtool needs to be installed'
 error: gcc           gcc - GNU Project C and C++ Compiler                         REQUIRED        -               -               MISSING    'gcc needs to be installed'

-------------------------
| External Dependencies |
-------------------------

 error: cups          CUPS - Common Unix Printing System                           REQUIRED        1.1             -               INCOMPAT   'CUPS may not be installed or not running'
 error: dbus          DBus - Message bus system                                    REQUIRED        -               1.10.10         MISSING    'DBUS may not be installed or not running'
 xsane                xsane - Graphical scanner frontend for SANE                  OPTIONAL        0.9             0.999           OK         -
 scanimage            scanimage - Shell scanning program                           OPTIONAL        1.0             1.0.25          OK         -
 error: avahi-utils   avahi-utils                                                  OPTIONAL        -               -               MISSING    'avahi-utils needs to be installed'
 error: policykit     PolicyKit - Administrative policy framework                  OPTIONAL        -               0.113           MISSING    'policykit needs to be installed'
 error: gs            GhostScript - PostScript and PDF language interpreter and previewer REQUIRED        7.05            -               MISSING    'gs needs to be installed'
 network              network -wget                                                OPTIONAL        -               1.18            OK         -

---------------------
| Python Extentions |
---------------------

 hpmudext             IO-Extension                                                 REQUIRED        -               3.16.9          OK         -
 cupsext              CUPS-Extension                                               REQUIRED        -               3.16.9          OK         -

----------------------
| Scan Configuration |
----------------------

 scanext              Scan-SANE-Extension                                          REQUIRED        -               3.16.9          OK         -
'/nix/store/18i6cmf6l6qcq2ip1a1ds0vyp549bf6j-hplip-3.16.9/etc/sane.d/dll.conf' not found.
'/etc/sane.d/dll.d/hpaio' not found.
'/etc/sane.d/dll.d/hplip' not found.
error: 'hpaio' not found in SANE conf files. Is SANE installed?
 error: hpaio         HPLIP-SANE-Backend                                           REQUIRED        -               3.16.9          MISSING    'hpaio not found in /nix/store/18i6cmf6l6qcq2ip1a1ds0vyp549bf6j-hplip-3.16.9/etc/sane.d/dll.conf.
 hpaio needs to be added in this file.'
Mic92 commented 7 years ago

@ericsagnes feel free to add those. For my hp-setup also seems not be necessary, I just use its drivers via cups.

FRidh commented 7 years ago

That's an old expression. We need to get rid of pythonPath, and use python.withPackages instead.

FRidh commented 7 years ago

We need to get rid of pythonPath, and use python.withPackages instead.

Though maybe not, because hplip provides Python modules itself.