summary refs log tree commit diff
path: root/pkgs/applications/graphics/sane/backends/dsseries/default.nix
blob: 37ac02987061e0cce04d481a16c5926ebc5f0559 (plain) (blame)
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
{ stdenv, fetchurl, rpmextract }:

stdenv.mkDerivation rec {
  pname = "libsane-dsseries";
  version = "1.0.5-1";

  src = fetchurl {
    url = "https://download.brother.com/welcome/dlf100974/${pname}-${version}.x86_64.rpm";
    sha256 = "1wfdbfbf51cc7njzikdg48kwpnpc0pg5s6p0s0y3z0q7y59x2wbq";
  };

  nativeBuildInputs = [ rpmextract ];

  unpackCmd = ''
    mkdir ${pname}-${version} && pushd ${pname}-${version}
    rpmextract $curSrc
    popd
  '';

  patchPhase = ''
    substituteInPlace etc/udev/rules.d/50-Brother_DSScanner.rules \
      --replace 'GROUP="users"' 'GROUP="scanner", ENV{libsane_matched}="yes"'

    mkdir -p etc/sane.d/dll.d
    echo "dsseries" > etc/sane.d/dll.d/dsseries.conf
  '';

  installPhase = ''
    mkdir -p $out
    cp -dr etc $out
    cp -dr usr/lib64 $out/lib
  '';

  preFixup = ''
    for f in `find $out/lib/sane/ -type f`; do
      # Make it possible to find libstdc++.so.6
      patchelf --set-rpath ${stdenv.cc.cc.lib}/lib:$out/lib/sane $f

      # Horrible kludge: The driver hardcodes /usr/lib/sane/ as a dlopen path.
      # We can directly modify the binary to force a relative lookup instead.
      # The new path is NULL-padded to the same length as the original path.
      sed -i "s|/usr/lib/sane/%s|%s\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00|g" $f
    done
  '';

  meta = {
    description = "Brother DSSeries SANE backend driver";
    homepage = "http://www.brother.com";
    platforms = stdenv.lib.platforms.linux;
    license = stdenv.lib.licenses.unfree;
    maintainers = with stdenv.lib.maintainers; [ callahad ];
  };
}