From 46e5f2ec85df1f1ea176a492e79d754d61a20304 Mon Sep 17 00:00:00 2001 From: Benson Chu Date: Sun, 23 Jun 2024 07:53:08 -0500 Subject: [PATCH] Let's give it a try --- configuration.nix | 2 +- mfcl2690dw/default.nix | 93 ++++++++++++++++++++++++++++++------------ 2 files changed, 67 insertions(+), 28 deletions(-) diff --git a/configuration.nix b/configuration.nix index 9b68798..3723187 100644 --- a/configuration.nix +++ b/configuration.nix @@ -188,7 +188,7 @@ in urwid ])) - # (pkgs.callPackage ./mfcl2690dw/default.nix { }) + (pkgs.callPackage ./mfcl2690dw/default.nix { }) ]; networking.firewall.allowedTCPPorts = [ 22 ]; diff --git a/mfcl2690dw/default.nix b/mfcl2690dw/default.nix index 3d2e645..f089fca 100644 --- a/mfcl2690dw/default.nix +++ b/mfcl2690dw/default.nix @@ -1,44 +1,83 @@ -{ pkgsi686Linux, lib, stdenv, fetchurl, dpkg, makeWrapper, coreutils, ghostscript, gnugrep, gnused, which, perl }: +{ lib, stdenv, fetchurl, dpkg, autoPatchelfHook, makeWrapper, perl, gnused, ghostscript, file, coreutils, gnugrep, which }: + +let + arches = [ "x86_64" "i686" "armv7l" ]; + + runtimeDeps = [ + ghostscript + file + gnused + gnugrep + coreutils + which + ]; + + printerName = "mfcl2690dw"; +in stdenv.mkDerivation rec { - pname = "mfcl2690dwpdrv"; + pname = "cups-brother-${printerName}"; version = "4.0.0-1"; + nativeBuildInputs = [ dpkg makeWrapper autoPatchelfHook ]; + buildInputs = [ perl ]; + + dontUnpack = true; + src = fetchurl { - url = "https://download.brother.com/welcome/dlf101727/${pname}-${version}.i386.deb"; + url = "https://download.brother.com/welcome/dlf105065/${printerName}pdrv-${version}.i386.deb"; sha256 = "765da49f1f0d68ed36ba553e6e60aa5030e87845b74afe0d7d46ebab28ab5256"; }; - nativeBuildInputs = [ dpkg makeWrapper ]; - - unpackPhase = "dpkg-deb -x $src $out"; - installPhase = '' - dir=$out/opt/brother/Printers/MFCL2690DW + runHook preInstall - substituteInPlace $dir/lpd/lpdfilter \ - --replace /usr/bin/perl ${perl}/bin/perl \ - --replace "BR_PRT_PATH =~" "BR_PRT_PATH = \"$dir\"; #" \ - --replace "PRINTER =~" "PRINTER = \"MFCL2690DW\"; #" + mkdir -p $out + dpkg-deb -x $src $out - wrapProgram $dir/lpd/filter_MFCL2690DW \ - --prefix PATH : ${lib.makeBinPath [ - coreutils ghostscript gnugrep gnused which - ]} + # delete unnecessary files for the current architecture + '' + lib.concatMapStrings (arch: '' + echo Deleting files for ${arch} + rm -r "$out/opt/brother/Printers/MFCL2690DW/lpd/${arch}" + '') (builtins.filter (arch: arch != stdenv.hostPlatform.linuxArch) arches) + '' - # need to use i686 glibc here, these are 32bit proprietary binaries - interpreter=${pkgsi686Linux.glibc}/lib/ld-linux.so.2 - patchelf --set-interpreter "$interpreter" $dir/inf/braddprinter - patchelf --set-interpreter "$interpreter" $dir/lpd/brprintconflsr3 - patchelf --set-interpreter "$interpreter" $dir/lpd/rawtobr3 - ''; + # bundled scripts don't understand the arch subdirectories for some reason + ln -s \ + "$out/opt/brother/Printers/MFCL2690DW/lpd/${stdenv.hostPlatform.linuxArch}/"* \ + "$out/opt/brother/Printers/MFCL2690DW/lpd/" - meta = { - description = "Brother MFC-L2690DW lpr driver"; + # Fix global references and replace auto discovery mechanism with hardcoded values + substituteInPlace $out/opt/brother/Printers/MFCL2690DW/lpd/lpdfilter \ + --replace /opt "$out/opt" \ + --replace "my \$BR_PRT_PATH =" "my \$BR_PRT_PATH = \"$out/opt/brother/Printers/MFCL2690DW\"; #" \ + --replace "PRINTER =~" "PRINTER = \"MFCL2690DW\"; #" + + # Make sure all executables have the necessary runtime dependencies available + find "$out" -executable -and -type f | while read file; do + wrapProgram "$file" --prefix PATH : "${lib.makeBinPath runtimeDeps}" + done + + # Symlink filter and ppd into a location where CUPS will discover it + mkdir -p $out/lib/cups/filter + mkdir -p $out/share/cups/model + + ln -s \ + $out/opt/brother/Printers/MFCL2690DW/lpd/lpdfilter \ + $out/lib/cups/filter/brother_lpdwrapper_MFCL2690DW + + ln -s \ + $out/opt/brother/Printers/MFCL2690DW/cupswrapper/brother-MFCL2690DW-cups-en.ppd \ + $out/share/cups/model/ + + runHook postInstall + ''; + + meta = with lib; { homepage = "http://www.brother.com/"; + description = "Brother MFC-L2690DW printer driver"; sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ]; - license = lib.licenses.unfree; - platforms = [ "x86_64-linux" "i686-linux" ]; - maintainers = [ lib.maintainers.Enzime ]; + license = licenses.unfree; + platforms = builtins.map (arch: "${arch}-linux") arches; + maintainers = [ maintainers.lovesegfault ]; }; }