pytrainer: unpin python 3.10
[NixPkgs.git] / pkgs / by-name / cu / cups-brother-hl3170cdw / package.nix
blob5450997a5afcdb2ee25a1dd57ce1dc33ca6afad1
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}";
5   version = "1.1.4-0";
6   lprVersion = "1.1.2-1";
8   model = "hl3170cdw";
9   cupsFileNo = "006743";
10   lprFileNo = "007056";
12   src = fetchurl {
13     url = "https://download.brother.com/welcome/dlf${cupsFileNo}/${model}_cupswrapper_GPL_source_${version}.tar.gz";
14     hash = "sha256-E3GSwiMRkuiCIJYkDozoYUPfOqvopPqPPQt1uaMDEAU=";
15   };
17   lprdeb = fetchurl {
18     url = "https://download.brother.com/welcome/dlf${lprFileNo}/${model}lpr-${lprVersion}.i386.deb";
19     hash = "sha256-N1GjQHth5k4qhbfWLInzub9DcNsee4gKc3EW2WIfrko=";
20   };
22   nativeBuildInputs = [ makeWrapper dpkg ];
24   preUnpack = ''
25     dpkg-deb -x ${lprdeb} $out
26   '';
28   prePatch = ''
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]"
34   '';
36   makeFlags = [ "-C brcupsconfig" ];
38   installPhase = ''
39     runHook preInstall
41     # cups install
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
48     sh lpdwrapperbuilder
49     chmod +x lpdwrapper
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/
59     runHook postInstall
60   '';
62   preFixup = ''
63     # lpr fixup
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"
92     # cups fixup
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 ] }
100   '';
102   meta = with lib; {
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 ];
110   };