summaryrefslogtreecommitdiff
path: root/nongnu/packages/printers.scm
blob: 6a10da2eb410d0c8ddbda1692995c4fc1e9cbaf4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2021 Petr Hodina <phodina@protonmail.com>
;;; Copyright © 2021 Kahka F
;;; Copyright © 2021 Jonathan Brielmaier <jonathan.brielmaier@web.de>
;;;
;;; This file is not part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (nongnu packages printers)
  #:use-module (gnu packages)
  #:use-module (gnu packages cups)
  #:use-module (guix packages)
  #:use-module (guix utils)
  #:use-module (srfi srfi-1)
  #:use-module (guix download)
  #:use-module (guix build utils))

(define-public hplip-plugin
  (package
   (inherit hplip)
   (name "hplip-plugin")
   (description "Hewlett-Packard printer drivers with nonfree plugin.")
   (source (origin (inherit (package-source hplip))
       (snippet
        (delete '(for-each
            delete-file
            (find-files "." (lambda
              (file stat)
            (elf-file? file))))
          (origin-snippet (package-source hplip))))))
   (inputs (alist-delete "python-pyqt" (package-inputs hplip)))
   (native-inputs
    (append
     `(("hplip-plugin"
  ,(origin
    (method url-fetch)
    (uri (string-append "https://developers.hp.com/sites/default/files/hplip-"
            (package-version hplip) "-plugin.run"))
    (sha256
     (base32
            "1ffqnmmghxqclv66qq14wypfha2xalcrbrjw0dqkmpvbnzwbn49g")))))
     (package-native-inputs hplip)))
   (arguments
    (substitute-keyword-arguments
     (package-arguments hplip)
     ((#:configure-flags cf)
      `(delete "--enable-qt5" ,cf))
     ((#:phases ph)
      `(modify-phases
  ,ph
  (replace
   'fix-hard-coded-file-names
   (lambda* (#:key inputs outputs #:allow-other-keys)
      (let ((out (assoc-ref outputs "out"))
      ;; FIXME: use merged ppds (I think actually only
      ;; drvs need to be merged).
      (cupsdir (assoc-ref inputs "cups-minimal")))
        (substitute* "base/g.py"
         (("'/usr/share;[^']*'")
          (string-append "'" cupsdir "/share'"))
         (("'/etc/hp/hplip.conf'")
          (string-append "'" out
             "/etc/hp/hplip.conf" "'"))
         (("/var/lib/hp")
          (string-append
           out
           "/var/lib/hp")))

        (substitute* "Makefile.in"
         (("[[:blank:]]check-plugin\\.py[[:blank:]]") " ")
         ;; FIXME Use beginning-of-word in regexp.
         (("[[:blank:]]plugin\\.py[[:blank:]]") " ")
         (("/usr/include/libusb-1.0")
          (string-append (assoc-ref inputs "libusb")
             "/include/libusb-1.0"))
         (("hplip_statedir =.*$")
          ;; Don't bail out while trying to create
          ;; /var/lib/hplip.  We can safely change its value
          ;; here because it's hard-coded in the code anyway.
          "hplip_statedir = $(prefix)/var/lib/hp\n")
         (("hplip_confdir = /etc/hp")
          ;; This is only used for installing the default config.
          (string-append "hplip_confdir = " out
             "/etc/hp"))
         (("halpredir = /usr/share/hal/fdi/preprobe/10osvendor")
          ;; We don't use hal.
          (string-append "halpredir = " out
             "/share/hal/fdi/preprobe/10osvendor"))
         (("rulesdir = /etc/udev/rules.d")
          ;; udev rules will be merged by base service.
          (string-append "rulesdir = " out
             "/lib/udev/rules.d"))
         (("rulessystemdir = /usr/lib/systemd/system")
          ;; We don't use systemd.
          (string-append "rulessystemdir = " out
             "/lib/systemd/system"))
         (("/etc/sane.d")
          (string-append out "/etc/sane.d")))

        (substitute* "common/utils.h"
         (("/var/lib/hp")
          (string-append
           out
           "/var/lib/hp")))
        #t)))
  (add-after
   'install-models-dat 'install-plugins
   (lambda* (#:key outputs system inputs #:allow-other-keys)
      (let* ((out (assoc-ref outputs "out"))
       (state-dir (string-append out "/var/lib/hp"))
       (hp-arch (assoc-ref
           '(("i686-linux" . "x86_32")
             ("x86_64-linux" . "x86_64")
             ("armhf-linux" . "arm32")
             ("aarch64-linux" . "aarch64"))
           system)))
        (unless hp-arch
          (error (string-append
            "HPLIP plugin not supported on "
            system)))
        (invoke "sh" (assoc-ref inputs "hplip-plugin")
          "--noexec" "--keep")
        (chdir "plugin_tmp")
        (install-file "plugin.spec"
          (string-append out "/share/hplip/"))

        (for-each
         (lambda (file)
           (install-file
      file
      (string-append out "/share/hplip/data/firmware")))
         (find-files "." "\\.fw.gz$"))

        (install-file "license.txt"
          (string-append out "/share/hplip/data/plugins"))
        (mkdir-p
         (string-append out "/share/hplip/prnt/plugins"))
        (for-each
         (lambda (type plugins)
           (for-each
      (lambda (plugin)
        (let ((file (string-append plugin "-" hp-arch ".so"))
        (dir (string-append out "/share/hplip/"
                type "/plugins")))
          (install-file file dir)
          (chmod (string-append dir "/" file) #o755)
          (symlink (string-append dir "/" file)
             (string-append dir "/" plugin ".so"))))
      plugins))
         '("prnt" "scan")
         '(("lj" "hbpl1")
           ("bb_soap" "bb_marvell" "bb_soapht" "bb_escl")))
        (mkdir-p state-dir)
        (call-with-output-file
      (string-append state-dir "/hplip.state")
          (lambda (port)
      (simple-format port "[plugin]
installed=1
eula=1
version=~A
" ,(package-version hplip))))

        (substitute* (string-append out "/etc/hp/hplip.conf")
         (("/usr") out))
        #t)))))))))