From c80385d93469aeb2d4134ef0056cea330c48c251 Mon Sep 17 00:00:00 2001 From: Dan Callahan Date: Fri, 8 Mar 2019 14:58:32 +0000 Subject: [PATCH] dsseries: init at 1.0.5-1 --- nixos/modules/module-list.nix | 1 + .../hardware/sane_extra_backends/dsseries.nix | 26 +++++++++ .../sane/backends/dsseries/default.nix | 53 +++++++++++++++++++ pkgs/top-level/all-packages.nix | 2 + 4 files changed, 82 insertions(+) create mode 100644 nixos/modules/services/hardware/sane_extra_backends/dsseries.nix create mode 100644 pkgs/applications/graphics/sane/backends/dsseries/default.nix diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 6bccd253500a..773389fa7189 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -311,6 +311,7 @@ ./services/hardware/ratbagd.nix ./services/hardware/sane.nix ./services/hardware/sane_extra_backends/brscan4.nix + ./services/hardware/sane_extra_backends/dsseries.nix ./services/hardware/tcsd.nix ./services/hardware/tlp.nix ./services/hardware/thinkfan.nix diff --git a/nixos/modules/services/hardware/sane_extra_backends/dsseries.nix b/nixos/modules/services/hardware/sane_extra_backends/dsseries.nix new file mode 100644 index 000000000000..d71a17f5ea6b --- /dev/null +++ b/nixos/modules/services/hardware/sane_extra_backends/dsseries.nix @@ -0,0 +1,26 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + options = { + + hardware.sane.dsseries.enable = + mkEnableOption "Brother DSSeries scan backend" // { + description = '' + When enabled, will automatically register the "dsseries" SANE backend. + + This supports the Brother DSmobile scanner series, including the + DS-620, DS-720D, DS-820W, and DS-920DW scanners. + ''; + }; + }; + + config = mkIf (config.hardware.sane.enable && config.hardware.sane.dsseries.enable) { + + hardware.sane.extraBackends = [ pkgs.dsseries ]; + services.udev.packages = [ pkgs.dsseries ]; + boot.kernelModules = [ "sg" ]; + + }; +} diff --git a/pkgs/applications/graphics/sane/backends/dsseries/default.nix b/pkgs/applications/graphics/sane/backends/dsseries/default.nix new file mode 100644 index 000000000000..01c203b407c1 --- /dev/null +++ b/pkgs/applications/graphics/sane/backends/dsseries/default.nix @@ -0,0 +1,53 @@ +{ stdenv, fetchurl, rpmextract }: + +stdenv.mkDerivation rec { + name = "libsane-dsseries-${version}"; + version = "1.0.5-1"; + + src = fetchurl { + url = "https://download.brother.com/welcome/dlf100974/${name}.x86_64.rpm"; + sha256 = "1wfdbfbf51cc7njzikdg48kwpnpc0pg5s6p0s0y3z0q7y59x2wbq"; + }; + + nativeBuildInputs = [ rpmextract ]; + + unpackCmd = '' + mkdir ${name} && pushd ${name} + 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 ]; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 6f25783a71d7..7ee4338b5f74 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -22869,6 +22869,8 @@ in brscan4 = callPackage ../applications/graphics/sane/backends/brscan4 { }; + dsseries = callPackage ../applications/graphics/sane/backends/dsseries { }; + mkSaneConfig = callPackage ../applications/graphics/sane/config.nix { }; sane-frontends = callPackage ../applications/graphics/sane/frontends.nix { };