Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at devShellTools-shell 361 lines 11 kB view raw
1{ 2 lib, 3 stdenv, 4 fetchurl, 5 replaceVars, 6 pkg-config, 7 autoreconfHook, 8 gobject-introspection, 9 wrapGAppsHook3, 10 cups, 11 zlib, 12 libjpeg, 13 libusb1, 14 python3Packages, 15 sane-backends, 16 dbus, 17 file, 18 ghostscript, 19 usbutils, 20 net-snmp, 21 openssl, 22 perl, 23 net-tools, 24 avahi, 25 bash, 26 util-linux, 27 # To remove references to gcc-unwrapped 28 removeReferencesTo, 29 qt5, 30 withQt5 ? true, 31 withPlugin ? false, 32 withStaticPPDInstall ? false, 33}: 34 35let 36 37 pname = "hplip"; 38 version = "3.25.2"; 39 40 src = fetchurl { 41 url = "mirror://sourceforge/hplip/${pname}-${version}.tar.gz"; 42 hash = "sha256-6HL/KOslF3Balfbhg576HlCnejOq6JBSeN8r2CCRllM="; 43 }; 44 45 plugin = fetchurl { 46 url = "https://www.openprinting.org/download/printdriver/auxfiles/HP/plugins/${pname}-${version}-plugin.run"; 47 hash = "sha256-miz41WYehGVI27tZUjGlRIpctjcpzJPfjR9lLf0WelQ="; 48 }; 49 50 hplipState = replaceVars ./hplip.state { 51 inherit version; 52 }; 53 54 hplipPlatforms = { 55 i686-linux = "x86_32"; 56 x86_64-linux = "x86_64"; 57 armv6l-linux = "arm32"; 58 armv7l-linux = "arm32"; 59 aarch64-linux = "arm64"; 60 }; 61 62 hplipArch = 63 hplipPlatforms.${stdenv.hostPlatform.system} 64 or (throw "HPLIP not supported on ${stdenv.hostPlatform.system}"); 65 66 pluginArches = [ 67 "x86_32" 68 "x86_64" 69 "arm32" 70 "arm64" 71 ]; 72 73in 74 75python3Packages.buildPythonApplication { 76 inherit pname version; 77 format = "other"; 78 79 srcs = [ src ] ++ lib.optional withPlugin plugin; 80 81 unpackCmd = lib.optionalString withPlugin '' 82 if ! [[ "$curSrc" =~ -plugin\.run$ ]]; then return 1; fi # fallback to regular unpackCmdHooks 83 84 # Unpack plugin shar 85 sh "$curSrc" --noexec --keep 86 ''; 87 88 sourceRoot = "${pname}-${version}"; 89 90 buildInputs = [ 91 libjpeg 92 cups 93 libusb1 94 sane-backends 95 dbus 96 file 97 ghostscript 98 net-snmp 99 openssl 100 perl 101 zlib 102 avahi 103 ] 104 ++ lib.optionals withQt5 [ 105 qt5.qtwayland 106 ]; 107 108 nativeBuildInputs = [ 109 pkg-config 110 removeReferencesTo 111 autoreconfHook 112 gobject-introspection 113 wrapGAppsHook3 114 ] 115 ++ lib.optional withQt5 qt5.wrapQtAppsHook; 116 117 pythonPath = 118 with python3Packages; 119 [ 120 dbus 121 pillow 122 pygobject3 123 reportlab 124 usbutils 125 dbus-python 126 distro 127 distutils 128 ] 129 ++ lib.optionals withQt5 [ 130 pyqt5 131 pyqt5-sip 132 ]; 133 134 makeWrapperArgs = [ 135 "--prefix" 136 "PATH" 137 ":" 138 "${net-tools}/bin" 139 ]; 140 141 patches = [ 142 # HPLIP's getSystemPPDs() function relies on searching for PPDs below common FHS 143 # paths, and hp-setup crashes if none of these paths actually exist (which they 144 # don't on NixOS). Add the equivalent NixOS path, /var/lib/cups/path/share. 145 # See: https://github.com/NixOS/nixpkgs/issues/21796 146 ./hplip-3.20.11-nixos-cups-ppd-search-path.patch 147 148 # Remove all ImageProcessor functionality since that is closed source 149 (fetchurl { 150 url = "https://web.archive.org/web/20230226174550/https://sources.debian.org/data/main/h/hplip/3.22.10+dfsg0-1/debian/patches/0028-Remove-ImageProcessor-binary-installs.patch"; 151 hash = "sha256-tNYccuwrcx5WCe7ULk8r8J6MVcUytGspiW64zAvO0qI="; 152 }) 153 ]; 154 155 postPatch = '' 156 # https://github.com/NixOS/nixpkgs/issues/44230 157 substituteInPlace createPPD.sh \ 158 --replace-fail ppdc "${cups}/bin/ppdc" \ 159 --replace-fail "gzip -c" "gzip -cn" 160 161 # HPLIP hardcodes absolute paths everywhere. Nuke from orbit. 162 find . -type f -exec sed -i \ 163 -e s,/etc/hp,$out/etc/hp,g \ 164 -e s,/etc/sane.d,$out/etc/sane.d,g \ 165 -e s,/usr/include/libusb-1.0,${libusb1.dev}/include/libusb-1.0,g \ 166 -e s,/usr/share/hal/fdi/preprobe/10osvendor,$out/share/hal/fdi/preprobe/10osvendor,g \ 167 -e s,/usr/lib/systemd/system,$out/lib/systemd/system,g \ 168 -e s,/var/lib/hp,$out/var/lib/hp,g \ 169 -e s,/usr/bin/perl,${perl}/bin/perl,g \ 170 -e s,/usr/bin/file,${file}/bin/file,g \ 171 -e s,/usr/bin/gs,${ghostscript}/bin/gs,g \ 172 -e s,/usr/share/cups/fonts,${ghostscript.fonts}/share/fonts,g \ 173 -e "s,ExecStart=/usr/bin/python /usr/bin/hp-config_usb_printer,ExecStart=$out/bin/hp-config_usb_printer,g" \ 174 -e s,Exec=/usr/bin/hp-uiscan,Exec=hp-uiscan,g \ 175 -e s,Icon=/usr/share/icons/Humanity/devices/48/printer.svg,Icon=printer,g \ 176 -e s,Icon=@abs_datadir@/hplip/data/images/128x128/hp_logo.png,Icon=hp_logo,g \ 177 {} + 178 179 echo 'AUTOMAKE_OPTIONS = foreign' >> Makefile.am 180 ''; 181 182 configureFlags = 183 let 184 out = placeholder "out"; 185 in 186 [ 187 "--with-hpppddir=${out}/share/cups/model/HP" 188 "--with-cupsfilterdir=${out}/lib/cups/filter" 189 "--with-cupsbackenddir=${out}/lib/cups/backend" 190 "--with-icondir=${out}/share/applications" 191 "--with-systraydir=${out}/xdg/autostart" 192 "--with-mimedir=${out}/etc/cups" 193 "--enable-policykit" 194 "--disable-qt4" 195 196 # remove ImageProcessor usage, it causes segfaults, see 197 # https://bugs.launchpad.net/hplip/+bug/1788706 198 # https://bugs.launchpad.net/hplip/+bug/1787289 199 "--disable-imageProcessor-build" 200 ] 201 ++ lib.optional withStaticPPDInstall "--enable-cups-ppd-install" 202 ++ lib.optional withQt5 "--enable-qt5"; 203 204 # Prevent 'ppdc: Unable to find include file "<font.defs>"' which prevent 205 # generation of '*.ppd' files. 206 # This seems to be a 'ppdc' issue when the tool is run in a hermetic sandbox. 207 # Could not find how to fix the problem in 'ppdc' so this is a workaround. 208 CUPS_DATADIR = "${cups}/share/cups"; 209 210 makeFlags = 211 let 212 out = placeholder "out"; 213 in 214 [ 215 "halpredir=${out}/share/hal/fdi/preprobe/10osvendor" 216 "rulesdir=${out}/etc/udev/rules.d" 217 "policykit_dir=${out}/share/polkit-1/actions" 218 "policykit_dbus_etcdir=${out}/etc/dbus-1/system.d" 219 "policykit_dbus_sharedir=${out}/share/dbus-1/system-services" 220 "PYTHONEXECDIR=${out}/lib/python${lib.versions.majorMinor python3Packages.python.version}/site-packages" 221 "hplip_confdir=${out}/etc/hp" 222 "hplip_statedir=${out}/var/lib/hp" 223 ]; 224 225 postConfigure = '' 226 # don't save timestamp, in order to improve reproducibility 227 substituteInPlace Makefile \ 228 --replace "GZIP_ENV = --best" "GZIP_ENV = --best -n" 229 ''; 230 231 enableParallelBuilding = true; 232 enableParallelInstalling = false; 233 234 env = { 235 NIX_CFLAGS_COMPILE = toString [ 236 "-Wno-error=implicit-int" 237 "-Wno-error=implicit-function-declaration" 238 "-Wno-error=return-mismatch" 239 "-Wno-error=int-conversion" 240 "-Wno-error=incompatible-pointer-types" 241 ]; 242 }; 243 244 # 245 # Running `hp-diagnose_plugin -g` can be used to diagnose 246 # issues with plugins. 247 # 248 postInstall = '' 249 for resolution in 16x16 32x32 64x64 128x128 256x256; do 250 mkdir -p $out/share/icons/hicolor/$resolution/apps 251 ln -s $out/share/hplip/data/images/$resolution/hp_logo.png \ 252 $out/share/icons/hicolor/$resolution/apps/hp_logo.png 253 done 254 '' 255 + lib.optionalString withPlugin '' 256 pushd $NIX_BUILD_TOP/plugin_tmp 257 258 cp plugin.spec $out/share/hplip/ 259 260 mkdir -p $out/share/hplip/data/firmware 261 cp *.fw.gz $out/share/hplip/data/firmware 262 263 mkdir -p $out/share/hplip/data/plugins 264 cp license.txt $out/share/hplip/data/plugins 265 266 mkdir -p $out/share/hplip/prnt/plugins 267 for plugin in lj hbpl1; do 268 cp $plugin-${hplipArch}.so $out/share/hplip/prnt/plugins 269 chmod 0755 $out/share/hplip/prnt/plugins/$plugin-${hplipArch}.so 270 ln -s $out/share/hplip/prnt/plugins/$plugin-${hplipArch}.so \ 271 $out/share/hplip/prnt/plugins/$plugin.so 272 done 273 274 mkdir -p $out/share/hplip/scan/plugins 275 for plugin in bb_soap bb_marvell bb_soapht bb_escl; do 276 cp $plugin-${hplipArch}.so $out/share/hplip/scan/plugins 277 chmod 0755 $out/share/hplip/scan/plugins/$plugin-${hplipArch}.so 278 ln -s $out/share/hplip/scan/plugins/$plugin-${hplipArch}.so \ 279 $out/share/hplip/scan/plugins/$plugin.so 280 done 281 282 mkdir -p $out/share/hplip/fax/plugins 283 for plugin in fax_marvell; do 284 cp $plugin-${hplipArch}.so $out/share/hplip/fax/plugins 285 chmod 0755 $out/share/hplip/fax/plugins/$plugin-${hplipArch}.so 286 ln -s $out/share/hplip/fax/plugins/$plugin-${hplipArch}.so \ 287 $out/share/hplip/fax/plugins/$plugin.so 288 done 289 290 mkdir -p $out/var/lib/hp 291 cp ${hplipState} $out/var/lib/hp/hplip.state 292 293 popd 294 ''; 295 296 # The installed executables are just symlinks into $out/share/hplip, 297 # but wrapPythonPrograms ignores symlinks. We cannot replace the Python 298 # modules in $out/share/hplip with wrapper scripts because they import 299 # each other as libraries. Instead, we emulate wrapPythonPrograms by 300 # 1. Calling patchPythonProgram on the original script in $out/share/hplip 301 # 2. Making our own wrapper pointing directly to the original script. 302 dontWrapPythonPrograms = true; 303 # We also avoid double (or triple in case qt5 support is added) wrapping 304 dontWrapGApps = true; 305 dontWrapQtApps = true; 306 preFixup = '' 307 buildPythonPath "$out $pythonPath" 308 309 for bin in $out/bin/*; do 310 py=$(readlink -m $bin) 311 rm $bin 312 echo "patching \`$py'..." 313 patchPythonScript "$py" 314 echo "wrapping \`$bin'..." 315 ${if withQt5 then "makeQtWrapper" else "makeWrapper"} "$py" "$bin" \ 316 --prefix PATH ':' "$program_PATH" \ 317 --set PYTHONNOUSERSITE "true" \ 318 $makeWrapperArgs "''${gappsWrapperArgs[@]}" 319 done 320 ''; 321 322 postFixup = '' 323 substituteInPlace $out/etc/hp/hplip.conf --replace /usr $out 324 # Patch udev rules: 325 # with plugin, they upload firmware to printers, 326 # without plugin, they complain about the missing plugin. 327 substituteInPlace $out/etc/udev/rules.d/56-hpmud.rules \ 328 --replace {,${bash}}/bin/sh \ 329 --replace /usr/bin/nohup "" \ 330 --replace {,${util-linux}/bin/}logger \ 331 --replace {/usr,$out}/bin 332 remove-references-to -t ${stdenv.cc.cc} $(readlink -f $out/lib/*.so) 333 ''; 334 335 # There are some binaries there, which reference gcc-unwrapped otherwise. 336 stripDebugList = [ 337 "share/hplip" 338 "lib/cups/backend" 339 "lib/cups/filter" 340 python3Packages.python.sitePackages 341 "lib/sane" 342 ]; 343 344 meta = { 345 description = "Print, scan and fax HP drivers for Linux"; 346 homepage = "https://developers.hp.com/hp-linux-imaging-and-printing"; 347 downloadPage = "https://sourceforge.net/projects/hplip/files/hplip/"; 348 license = 349 if withPlugin then 350 lib.licenses.unfree 351 else 352 with lib.licenses; 353 [ 354 mit 355 bsd2 356 gpl2Plus 357 ]; 358 platforms = lib.attrNames hplipPlatforms; 359 maintainers = with lib.maintainers; [ ttuegel ]; 360 }; 361}