anvil-editor: init at 0.4
[NixPkgs.git] / pkgs / misc / cups / drivers / hll3230cdw / default.nix
blobaff134d7a33a826b3c6b9e6e57079dc274a56dc3
1 { stdenv, lib, fetchurl, perl, gnused, dpkg, makeWrapper, autoPatchelfHook, libredirect }:
3 stdenv.mkDerivation rec {
4   pname = "cups-brother-hll3230cdw";
5   version = "1.0.2";
6   src = fetchurl {
7     url = "https://download.brother.com/welcome/dlf103925/hll3230cdwpdrv-${version}-0.i386.deb";
8     sha256 = "9d49abc584bf22bc381510618a34107ead6ab14562b51831fefd6009947aa5a9";
9   };
11   nativeBuildInputs = [ dpkg makeWrapper autoPatchelfHook ];
13   buildInputs = [ perl gnused libredirect ];
15   unpackPhase = "dpkg-deb -x $src .";
17   installPhase = ''
18     runHook preInstall
20     mkdir -p "$out"
21     cp -pr opt "$out"
22     cp -pr usr/bin "$out/bin"
23     rm "$out/opt/brother/Printers/hll3230cdw/cupswrapper/cupswrapperhll3230cdw"
25     mkdir -p "$out/lib/cups/filter" "$out/share/cups/model"
27     ln -s "$out/opt/brother/Printers/hll3230cdw/cupswrapper/brother_lpdwrapper_hll3230cdw" \
28       "$out/lib/cups/filter/brother_lpdwrapper_hll3230cdw"
29     ln -s "$out/opt/brother/Printers/hll3230cdw/cupswrapper/brother_hll3230cdw_printer_en.ppd" \
30       "$out/share/cups/model/brother_hll3230cdw_printer_en.ppd"
32     runHook postInstall
33   '';
35   # Fix global references and replace auto discovery mechanism
36   # with hardcoded values.
37   #
38   # The configuration binary 'brprintconf_hll3230cdw' and lpd filter
39   # 'brhll3230cdwfilter' has hardcoded /opt format strings.  There isn't
40   # sufficient space in the binaries to substitute a path in the store, so use
41   # libredirect to get it to see the correct path.  The configuration binary
42   # also uses this format string to print configuration locations.  Here the
43   # wrapper output is processed to point into the correct location in the
44   # store.
46   postFixup = ''
47     substituteInPlace $out/opt/brother/Printers/hll3230cdw/lpd/filter_hll3230cdw \
48       --replace "my \$BR_PRT_PATH =" "my \$BR_PRT_PATH = \"$out/opt/brother/Printers/hll3230cdw/\"; #" \
49       --replace "PRINTER =~" "PRINTER = \"hll3230cdw\"; #"
51     substituteInPlace $out/opt/brother/Printers/hll3230cdw/cupswrapper/brother_lpdwrapper_hll3230cdw \
52       --replace "PRINTER =~" "PRINTER = \"hll3230cdw\"; #" \
53       --replace "my \$basedir = \`readlink \$0\`" "my \$basedir = \"$out/opt/brother/Printers/hll3230cdw/\""
55     wrapProgram $out/bin/brprintconf_hll3230cdw \
56       --set LD_PRELOAD "${libredirect}/lib/libredirect.so" \
57       --set NIX_REDIRECTS /opt=$out/opt
59     wrapProgram $out/opt/brother/Printers/hll3230cdw/lpd/brhll3230cdwfilter \
60       --set LD_PRELOAD "${libredirect}/lib/libredirect.so" \
61       --set NIX_REDIRECTS /opt=$out/opt
63     substituteInPlace $out/bin/brprintconf_hll3230cdw \
64       --replace \"\$"@"\" \"\$"@\" | LD_PRELOAD= ${gnused}/bin/sed -E '/^(function list :|resource file :).*/{s#/opt#$out/opt#}'"
65   '';
67   meta = with lib; {
68     description = "Brother HL-L3230CDW printer driver";
69     license = licenses.unfree;
70     sourceProvenance = with sourceTypes; [ binaryNativeCode ];
71     maintainers = with maintainers; [ aplund ];
72     platforms = [ "x86_64-linux" "i686-linux" ];
73     homepage = "http://www.brother.com/";
74     downloadPage = "https://support.brother.com/g/b/downloadend.aspx?c=us&lang=en&prod=hll3230cdw_us_eu_as&os=128&dlid=dlf103925_000&flang=4&type3=10283";
75   };