1 {lib, stdenv, fetchurl, dpkg, makeWrapper, gnused, coreutils, psutils, gnugrep, ghostscript, file, a2ps, gawk, which, pkgsi686Linux }:
3 stdenv.mkDerivation rec {
4 pname = "cups-brother-${model}";
6 lprVersion = "1.1.2-1";
13 url = "https://download.brother.com/welcome/dlf${cupsFileNo}/${model}_cupswrapper_GPL_source_${version}.tar.gz";
14 hash = "sha256-E3GSwiMRkuiCIJYkDozoYUPfOqvopPqPPQt1uaMDEAU=";
18 url = "https://download.brother.com/welcome/dlf${lprFileNo}/${model}lpr-${lprVersion}.i386.deb";
19 hash = "sha256-N1GjQHth5k4qhbfWLInzub9DcNsee4gKc3EW2WIfrko=";
22 nativeBuildInputs = [ makeWrapper dpkg ];
25 dpkg-deb -x ${lprdeb} $out
29 substituteInPlace brcupsconfig/brcups_commands.h \
30 --replace-fail "brprintconf[30]=\"" "brprintconf[130]=\"$out/usr/bin/"
32 substituteInPlace brcupsconfig/brcupsconfig.c \
33 --replace-fail "exec[300]" "exec[400]"
36 makeFlags = [ "-C brcupsconfig" ];
42 dir=$out/opt/brother/Printers/${model}
44 # Extract the true brother_lpdwrapper_MODEL filter embedded in cupswrapperMODEL by
45 # slicing out the relevant parts for the writing the embedded file, then running that.
46 sed -n -e '/tmp_filter=/c\tmp_filter=lpdwrapper' -e ' 1,/device_model=/p ; /<<!ENDOFWFILTER/,/!ENDOFWFILTER/p ; ' \
47 cupswrapper/cupswrapper${model} > lpdwrapperbuilder
50 mkdir -p $out/lib/cups/filter
51 cp lpdwrapper $out/lib/cups/filter/brother_lpdwrapper_${model}
53 mkdir -p $out/share/cups/model/Brother
54 cp PPD/brother_${model}_printer_en.ppd $out/share/cups/model/Brother/brother_${model}_printer_en.ppd
56 mkdir -p $dir/cupswrapper/
57 cp brcupsconfig/brcupsconfpt1 $dir/cupswrapper/
64 interpreter=${pkgsi686Linux.glibc.out}/lib/ld-linux.so.2
66 substituteInPlace $dir/lpd/filter${model} \
67 --replace-fail /opt "$out/opt"
68 substituteInPlace $dir/inf/setupPrintcapij \
69 --replace-fail /opt "$out/opt" \
70 --replace-fail printcap.local printcap
72 wrapProgram $dir/lpd/filter${model} \
73 --prefix PATH ":" ${ lib.makeBinPath [ ghostscript a2ps file gnused coreutils ] }
75 wrapProgram $dir/inf/setupPrintcapij \
76 --prefix PATH ":" ${ lib.makeBinPath [ coreutils gnused ] }
78 wrapProgram $dir/lpd/psconvertij2 \
79 --prefix PATH ":" ${ lib.makeBinPath [ ghostscript gnused coreutils gawk which ] }
81 patchelf --set-interpreter "$interpreter" "$dir/lpd/br${model}filter"
82 patchelf --set-interpreter "$interpreter" "$out/usr/bin/brprintconf_${model}"
84 wrapProgram $dir/lpd/br${model}filter \
85 --set LD_PRELOAD "${pkgsi686Linux.libredirect}/lib/libredirect.so" \
86 --set NIX_REDIRECTS "/opt=$out/opt"
88 wrapProgram $out/usr/bin/brprintconf_${model} \
89 --set LD_PRELOAD "${pkgsi686Linux.libredirect}/lib/libredirect.so" \
90 --set NIX_REDIRECTS "/opt=$out/opt"
93 substituteInPlace $out/lib/cups/filter/brother_lpdwrapper_${model} \
94 --replace-fail /opt/brother/Printers/${model} "$dir" \
95 --replace-fail /usr/bin/psnup "${psutils}/bin/psnup" \
96 --replace-fail /usr/share/cups/model/Brother "$out/share/cups/model/Brother"
98 wrapProgram $out/lib/cups/filter/brother_lpdwrapper_${model} \
99 --prefix PATH ":" ${ lib.makeBinPath [ coreutils psutils gnused gnugrep ] }
103 homepage = "https://www.brother.com/";
104 description = "Brother ${model} printer driver";
105 sourceProvenance = with sourceTypes; [ binaryNativeCode fromSource ];
106 license = with licenses; [ unfree gpl2Plus ];
107 platforms = [ "x86_64-linux" "i686-linux" ];
108 downloadPage = "https://support.brother.com/g/b/downloadlist.aspx?c=us&lang=en&prod=${model}_all&os=128";
109 maintainers = with maintainers; [ luna_1024 ];