1{
2 lib,
3 stdenv,
4 fetchurl,
5 cups,
6 dpkg,
7 gnused,
8 makeWrapper,
9 ghostscript,
10 coreutils,
11 perl,
12 gnugrep,
13 which,
14 debugLvl ? "0",
15}:
16
17let
18 version = "3.2.0-1";
19 lprdeb = fetchurl {
20 url = "https://download.brother.com/welcome/dlf102692/hl2260dlpr-${version}.i386.deb";
21 hash = "sha256-R+cM2SKc/MP6keo3PUrKXPC6a2dEQQdBunrpNtAHlH0=";
22 };
23
24 cupsdeb = fetchurl {
25 url = "https://download.brother.com/welcome/dlf102693/hl2260dcupswrapper-${version}.i386.deb";
26 hash = "sha256-k6+ulZVoFTpEY6WJ9TO9Rzp2c4dwPqL3NY5/XYJpvOc=";
27 };
28in
29stdenv.mkDerivation {
30 pname = "cups-brother-hl2260d";
31 inherit version;
32
33 nativeBuildInputs = [
34 makeWrapper
35 dpkg
36 ];
37 buildInputs = [
38 cups
39 ghostscript
40 perl
41 ];
42
43 dontPatchELF = true;
44 dontBuild = true;
45
46 unpackPhase = ''
47 mkdir -p $out
48 dpkg-deb -x ${cupsdeb} $out
49 dpkg-deb -x ${lprdeb} $out
50 '';
51
52 patchPhase = ''
53 # Patch lpr
54 INFDIR=$out/opt/brother/Printers/HL2260D/inf
55 LPDDIR=$out/opt/brother/Printers/HL2260D/lpd
56
57 substituteInPlace $LPDDIR/filter_HL2260D \
58 --replace "BR_PRT_PATH =~" "BR_PRT_PATH = \"$out/opt/brother/Printers/HL2260D\"; #" \
59 --replace "PRINTER =~" "PRINTER = \"HL2260D\"; #"
60
61 patchelf --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
62 $INFDIR/braddprinter
63 patchelf --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
64 $LPDDIR/brprintconflsr3
65 patchelf --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
66 $LPDDIR/rawtobr3
67
68 # Patch cupswrapper
69 WRAPPER=$out/opt/brother/Printers/HL2260D/cupswrapper/brother_lpdwrapper_HL2260D
70 PAPER_CFG=$out/opt/brother/Printers/HL2260D/cupswrapper/paperconfigml1
71
72 substituteInPlace $WRAPPER \
73 --replace "basedir =~" "basedir = \"$out/opt/brother/Printers/HL2260D\"; #" \
74 --replace "PRINTER =~" "PRINTER = \"HL2260D\"; #" \
75 --replace "\$DEBUG=0;" "\$DEBUG=${debugLvl};"
76 substituteInPlace $WRAPPER \
77 --replace "\`cp " "\`cp -p " \
78 --replace "\$TEMPRC\`" "\$TEMPRC; chmod a+rw \$TEMPRC\`" \
79 --replace "\`mv " "\`cp -p "
80 # This config script make this assumption that the *.ppd are found in a global location `/etc/cups/ppd`.
81 substituteInPlace $PAPER_CFG \
82 --replace "/etc/cups/ppd" "$out/share/cups/model"
83 '';
84
85 installPhase = ''
86 mkdir -p $out/share/cups/model
87 ln -s $out/opt/brother/Printers/HL2260D/cupswrapper/brother-HL2260D-cups-en.ppd $out/share/cups/model
88
89 mkdir -p $out/lib/cups/filter/
90 makeWrapper \
91 $out/opt/brother/Printers/HL2260D/cupswrapper/brother_lpdwrapper_HL2260D \
92 $out/lib/cups/filter/brother_lpdwrapper_HL2260D \
93 --prefix PATH : ${
94 lib.makeBinPath [
95 coreutils
96 gnugrep
97 gnused
98 ]
99 }
100
101 wrapProgram $out/opt/brother/Printers/HL2260D/lpd/filter_HL2260D \
102 --prefix PATH ":" ${
103 lib.makeBinPath [
104 ghostscript
105 which
106 ]
107 }
108 '';
109
110 meta = with lib; {
111 homepage = "http://www.brother.com/";
112 description = "Brother HL-2260D printer driver";
113 sourceProvenance = with sourceTypes; [ binaryNativeCode ];
114 license = licenses.unfree;
115 platforms = [
116 "x86_64-linux"
117 "i686-linux"
118 ];
119 downloadPage = "https://support.brother.com/g/b/downloadtop.aspx?c=cn_ot&lang=en&prod=hl2260d_cn";
120 maintainers = with maintainers; [ u2x1 ];
121 };
122}