generated from nix-community/nur-packages-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hll6400dw.nix
197 lines (167 loc) · 4.71 KB
/
hll6400dw.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
{ lib
, stdenv
, fetchurl
, dpkg
, makeWrapper
, autoPatchelfHook
, coreutils
, ghostscript
, gnugrep
, gnused
, which
, perl
}:
let
make = "brother";
model = "hll6400dw";
version = "3.5.1-1";
modelUpper = lib.strings.toUpper model;
modelDir = modelUpper;
reldir = "opt/brother/Printers/${modelDir}";
srcs = {
driver = rec {
# https://download.brother.com/welcome/dlf102432/hll6400dwlpr-3.5.1-1.i386.deb
inherit model version reldir;
suffix = "lpr";
dlf = "dlf102432";
url = "https://download.brother.com/welcome/${dlf}/${model}${suffix}-${version}.i386.deb";
sha256 = "sha256-dWB0fQuvLPs8FJMR8J8L2uoMfXAo/4lukJ2SXTjRx2E=";
};
wrapper = rec {
# https://download.brother.com/welcome/dlf102433/hll6400dwcupswrapper-3.5.1-1.i386.deb
inherit model version reldir;
suffix = "cupswrapper";
dlf = "dlf102433";
url = "https://download.brother.com/welcome/${dlf}/${model}${suffix}-${version}.i386.deb";
sha256 = "sha256-qLgPvS630nm6Kcefr5nTGn2fYNUfivlXTZArS5OLb4k=";
};
};
fixupPerlScripts = ''
fixupPerlScripts() {
local path=$1
local basedir=$2
local modelDir=$3
shift 3
for script in "$@"; do
echo "fixupPerlScripts: fixing script: $script"
sed -i '
s|^my $basedir\s*=.*;$|my $basedir = "'$basedir'";|;
s|^$basedir\s*=~.*;$||;
s|^my $PRINTER\s*=.*;$|my $PRINTER = "'$modelDir'";|;
s|^$PRINTER\s*=~.*;$||;
' $script
wrapProgram $script \
--prefix PATH : $path \
--set LANG C
done
}
'';
platformDirMap = {
"x86_64-linux" = "x86_64";
"i686-linux" = "i686";
"armv7l-linux" = "armv7l";
};
platformDir = platformDirMap.${stdenv.hostPlatform.system};
in
stdenv.mkDerivation rec {
inherit version;
pname = "${make}-${model}-${suffix}";
inherit (srcs.wrapper) suffix;
src = fetchurl {
inherit (srcs.wrapper) url sha256;
};
inherit (driver) nativeBuildInputs buildInputs unpackPhase;
runtimeDeps = [
coreutils
gnugrep
gnused
];
driver = stdenv.mkDerivation rec {
inherit version;
pname = "${make}-${model}-${suffix}";
inherit (srcs.driver) suffix;
src = fetchurl {
inherit (srcs.driver) url sha256;
};
nativeBuildInputs = [
dpkg
makeWrapper
autoPatchelfHook
];
buildInputs = [
perl
];
runtimeDeps = [
coreutils
ghostscript
gnugrep
gnused
which
];
unpackPhase = "dpkg-deb -x $src $out";
installPhase = ''
dir=$out/${reldir}
subdir=$dir/lpd
basedir=$out/${reldir}
${fixupPerlScripts}
fixupPerlScripts \
${lib.makeBinPath runtimeDeps} \
$basedir \
${modelDir} \
$subdir/*lpdfilter*
chmod -R +x $subdir
mv $subdir/${platformDir}/* $subdir
rm -rf $subdir/{${builtins.concatStringsSep "," (builtins.attrValues platformDirMap)}}
'';
meta = with lib; {
description = "Brother ${modelUpper} driver";
longDescription = ''
This driver works with the socket protocol,
for example socket://192.168.0.150,
but not with the IPP protocol.
'';
homepage = "http://www.brother.com/";
sourceProvenance = with sourceTypes; [ binaryNativeCode ];
license = licenses.unfree;
platforms = builtins.attrNames platformDirMap;
maintainers = with maintainers; [ milahu ];
};
};
installPhase = ''
dir=$out/${reldir}
subdir=$dir/${suffix}
basedir=${driver}/${reldir}
# this file is expected by the PPD file
# *cupsFilter: "application/vnd.cups-pdf 0 brother_lpdwrapper_HLL6400DW"
mv $subdir/*lpdwrapper* $subdir/brother_lpdwrapper_${modelUpper}
chmod +x $subdir/*lpdwrapper*
chmod +x $subdir/*paperconfig* || true
${fixupPerlScripts}
fixupPerlScripts \
${lib.makeBinPath runtimeDeps} \
$basedir \
${modelDir} \
$subdir/*lpdwrapper*
echo patching the PPD file: $subdir/*.ppd
# make the name consistent with other brother drivers
# example:
# - Brother HLL6400DW
# + Brother HL-L6400DW
sed -i -E 's/(Brother ${
builtins.substring 0 2 (modelUpper)
})(${
builtins.substring 2 999 (modelUpper)
})/\1-\2/g' $subdir/*.ppd
mkdir -p $out/lib/cups/filter
ln -s -v $subdir/*lpdwrapper* $out/lib/cups/filter
mkdir -p $out/share/cups/model
ln -s -v $subdir/*.ppd $out/share/cups/model
'';
meta = with lib; {
description = "Brother ${modelUpper} CUPS wrapper driver";
homepage = "http://www.brother.com/";
license = licenses.gpl2;
platforms = platforms.all;
maintainers = with maintainers; [ milahu ];
};
}