about summary refs log tree commit diff
path: root/nixpkgs/pkgs/misc/cups
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/misc/cups')
-rw-r--r--nixpkgs/pkgs/misc/cups/cups-pk-helper.nix30
-rw-r--r--nixpkgs/pkgs/misc/cups/default.nix160
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/brgenml1cupswrapper/default.nix124
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/brgenml1lpr/default.nix93
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/brlaser/default.nix63
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/brother/mfcl3770cdw/default.nix88
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/canon/default.nix225
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/canon/preload.c81
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/carps-cups/default.nix44
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/cnijfilter2/default.nix123
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/cnijfilter_2_80/default.nix109
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/cnijfilter_2_80/patches/libpng15.patch23
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/cnijfilter_2_80/patches/missing-include.patch20
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/cnijfilter_4_00/default.nix150
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/cnijfilter_4_00/patches/cnijfilter-3.80-1-cups-1.6.patch62
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/cnijfilter_4_00/patches/cnijfilter-3.80-6-cups-1.6.patch87
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/cnijfilter_4_00/patches/cnijfilter-4.00-4-ppd.patch10
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/cnijfilter_4_00/patches/cnijfilter-4.00-5-abi_x86_32.patch45
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/cnijfilter_4_00/patches/cnijfilter-4.00-6-headers.patch11
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/cups-bjnp/default.nix30
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/dymo/default.nix28
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/dymo/fix-includes.patch80
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/estudio/default.nix54
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/fxlinuxprint/default.nix51
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/googlecloudprint/default.nix64
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/hl1110/default.nix73
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/hl1210w/default.nix62
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/hl3140cw/default.nix78
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/hll2340dw/default.nix68
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/hll2390dw-cups/default.nix71
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/kyocera/default.nix50
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/kyodialog3/default.nix61
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/mfcj470dwcupswrapper/default.nix56
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/mfcj470dwlpr/default.nix45
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/mfcj6510dwcupswrapper/default.nix65
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/mfcj6510dwlpr/default.nix89
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/mfcl2700dncupswrapper/default.nix44
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/mfcl2700dnlpr/default.nix44
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/mfcl2720dwcupswrapper/default.nix47
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/mfcl2720dwlpr/default.nix45
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/mfcl2740dwcupswrapper/default.nix45
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/mfcl2740dwlpr/default.nix43
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/mfcl8690cdwcupswrapper/default.nix45
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/mfcl8690cdwlpr/default.nix45
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/samsung/1.00.36/default.nix116
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/samsung/1.00.36/module.nix44
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/samsung/1.00.37.nix98
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/samsung/4.00.39/builder.sh35
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/samsung/4.00.39/default.nix44
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/samsung/4.01.17.nix82
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/splix/default.nix55
-rw-r--r--nixpkgs/pkgs/misc/cups/drivers/zj-58/default.nix28
-rw-r--r--nixpkgs/pkgs/misc/cups/filters.nix71
53 files changed, 3504 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/misc/cups/cups-pk-helper.nix b/nixpkgs/pkgs/misc/cups/cups-pk-helper.nix
new file mode 100644
index 000000000000..f5edc7293407
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/cups-pk-helper.nix
@@ -0,0 +1,30 @@
+{ lib, stdenv, fetchurl, intltool, pkg-config, glib, polkit, cups, fetchpatch }:
+
+stdenv.mkDerivation rec {
+  version = "0.2.6";
+  pname = "cups-pk-helper";
+
+  src = fetchurl {
+    url = "https://www.freedesktop.org/software/cups-pk-helper/releases/cups-pk-helper-${version}.tar.xz";
+    sha256 = "0a52jw6rm7lr5nbyksiia0rn7sasyb5cjqcb95z1wxm2yprgi6lm";
+  };
+
+  nativeBuildInputs = [ pkg-config intltool ];
+  buildInputs = [ glib polkit cups ];
+
+  patches = [
+    # Don't use etc/dbus-1/system.d
+    (fetchpatch {
+      url = "https://gitlab.freedesktop.org/cups-pk-helper/cups-pk-helper/merge_requests/2.patch";
+      sha256 = "1kamhr5kn8c1y0q8xbip0fgr7maf3dyddlvab4n0iypk7rwwikl0";
+    })
+  ];
+
+  meta = with lib; {
+    description = "PolicyKit helper to configure cups with fine-grained privileges";
+    homepage = "http://www.freedesktop.org/wiki/Software/cups-pk-helper/";
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+    maintainers = [ maintainers.bjornfor ];
+  };
+}
diff --git a/nixpkgs/pkgs/misc/cups/default.nix b/nixpkgs/pkgs/misc/cups/default.nix
new file mode 100644
index 000000000000..0d740e071e11
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/default.nix
@@ -0,0 +1,160 @@
+{ lib, stdenv
+, fetchurl
+, pkg-config
+, removeReferencesTo
+, zlib
+, libjpeg
+, libpng
+, libtiff
+, pam
+, dbus
+, enableSystemd ? stdenv.isLinux && !stdenv.hostPlatform.isMusl
+, systemd ? null
+, acl
+, gmp
+, darwin
+, libusb1 ? null
+, gnutls ? null
+, avahi ? null
+, libpaper ? null
+, coreutils
+}:
+
+assert enableSystemd -> systemd != null;
+
+### IMPORTANT: before updating cups, make sure the nixos/tests/printing.nix test
+### works at least for your platform.
+
+with lib;
+stdenv.mkDerivation rec {
+  pname = "cups";
+
+  # After 2.2.6, CUPS requires headers only available in macOS 10.12+
+  version = if stdenv.isDarwin then "2.2.6" else "2.3.3";
+
+  passthru = { inherit version; };
+
+  src = fetchurl {
+    url = "https://github.com/apple/cups/releases/download/v${version}/cups-${version}-source.tar.gz";
+    sha256 = if version == "2.2.6"
+             then "16qn41b84xz6khrr2pa2wdwlqxr29rrrkjfi618gbgdkq9w5ff20"
+             else "1vpk0b2vq830f8fvf9z8qjsm5k141i7pi8djbinpnr78pi4dj7r6";
+  };
+
+  outputs = [ "out" "lib" "dev" "man" ];
+
+  postPatch = ''
+    substituteInPlace cups/testfile.c \
+      --replace 'cupsFileFind("cat", "/bin' 'cupsFileFind("cat", "${coreutils}/bin'
+  '';
+
+  nativeBuildInputs = [ pkg-config removeReferencesTo ];
+
+  buildInputs = [ zlib libjpeg libpng libtiff libusb1 gnutls libpaper ]
+    ++ optionals stdenv.isLinux [ avahi pam dbus ]
+    ++ optional enableSystemd systemd
+    # Separate from above only to not modify order, to avoid mass rebuilds; merge this with the above at next big change.
+    ++ optionals stdenv.isLinux [ acl ]
+    ++ optionals stdenv.isDarwin (with darwin; [
+      configd apple_sdk.frameworks.ApplicationServices
+    ]);
+
+  propagatedBuildInputs = [ gmp ];
+
+  configureFlags = [
+    "--localstatedir=/var"
+    "--sysconfdir=/etc"
+    "--enable-raw-printing"
+    "--enable-threads"
+  ] ++ optionals stdenv.isLinux [
+    "--enable-dbus"
+    "--enable-pam"
+    "--with-dbusdir=${placeholder "out"}/share/dbus-1"
+  ] ++ optional (libusb1 != null) "--enable-libusb"
+    ++ optional (gnutls != null) "--enable-ssl"
+    ++ optional (avahi != null) "--enable-avahi"
+    ++ optional (libpaper != null) "--enable-libpaper"
+    ++ optional stdenv.isDarwin "--disable-launchd";
+
+  # AR has to be an absolute path
+  preConfigure = ''
+    export AR="${getBin stdenv.cc.bintools.bintools}/bin/${stdenv.cc.targetPrefix}ar"
+    configureFlagsArray+=(
+      # Put just lib/* and locale into $lib; this didn't work directly.
+      # lib/cups is moved back to $out in postInstall.
+      # Beware: some parts of cups probably don't fully respect these.
+      "--prefix=$lib"
+      "--datadir=$out/share"
+      "--localedir=$lib/share/locale"
+
+      "--with-systemd=$out/lib/systemd/system"
+
+      ${optionalString stdenv.isDarwin ''
+        "--with-bundledir=$out"
+      ''}
+    )
+  '';
+
+  installFlags =
+    [ # Don't try to write in /var at build time.
+      "CACHEDIR=$(TMPDIR)/dummy"
+      "LOGDIR=$(TMPDIR)/dummy"
+      "REQUESTS=$(TMPDIR)/dummy"
+      "STATEDIR=$(TMPDIR)/dummy"
+      # Idem for /etc.
+      "PAMDIR=$(out)/etc/pam.d"
+      "XINETD=$(out)/etc/xinetd.d"
+      "SERVERROOT=$(out)/etc/cups"
+      # Idem for /usr.
+      "MENUDIR=$(out)/share/applications"
+      "ICONDIR=$(out)/share/icons"
+      # Work around a Makefile bug.
+      "CUPS_PRIMARY_SYSTEM_GROUP=root"
+    ];
+
+  enableParallelBuilding = true;
+
+  postInstall = ''
+      libexec=${if stdenv.isDarwin then "libexec/cups" else "lib/cups"}
+      moveToOutput $libexec "$out"
+
+      # $lib contains references to $out/share/cups.
+      # CUPS is working without them, so they are not vital.
+      find "$lib" -type f -exec grep -q "$out" {} \; \
+           -printf "removing references from %p\n" \
+           -exec remove-references-to -t "$out" {} +
+
+      # Delete obsolete stuff that conflicts with cups-filters.
+      rm -rf $out/share/cups/banners $out/share/cups/data/testprint
+
+      moveToOutput bin/cups-config "$dev"
+      sed -e "/^cups_serverbin=/s|$lib|$out|" \
+          -i "$dev/bin/cups-config"
+
+      # Rename systemd files provided by CUPS
+      for f in "$out"/lib/systemd/system/*; do
+        substituteInPlace "$f" \
+          --replace "$lib/$libexec" "$out/$libexec" \
+          --replace "org.cups.cupsd" "cups" \
+          --replace "org.cups." ""
+
+        if [[ "$f" =~ .*cupsd\..* ]]; then
+          mv "$f" "''${f/org\.cups\.cupsd/cups}"
+        else
+          mv "$f" "''${f/org\.cups\./}"
+        fi
+      done
+    '' + optionalString stdenv.isLinux ''
+      # Use xdg-open when on Linux
+      substituteInPlace "$out"/share/applications/cups.desktop \
+        --replace "Exec=htmlview" "Exec=xdg-open"
+    '';
+
+  meta = {
+    homepage = "https://cups.org/";
+    description = "A standards-based printing system for UNIX";
+    license = licenses.gpl2; # actually LGPL for the library and GPL for the rest
+    maintainers = with maintainers; [ matthewbauer ];
+    platforms = platforms.unix;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/cups/drivers/brgenml1cupswrapper/default.nix b/nixpkgs/pkgs/misc/cups/drivers/brgenml1cupswrapper/default.nix
new file mode 100644
index 000000000000..ec02e8c4f0e0
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/brgenml1cupswrapper/default.nix
@@ -0,0 +1,124 @@
+{ lib, stdenv, fetchurl, makeWrapper, cups, perl, coreutils, gnused, gnugrep
+, brgenml1lpr, debugLvl ? "0"}:
+
+/*
+    [Setup instructions](http://support.brother.com/g/s/id/linux/en/instruction_prn1a.html).
+
+    URI example
+     ~  `lpd://BRW0080927AFBCE/binary_p1`
+
+    Logging
+    -------
+
+    `/tmp/br_cupswrapper_ml1.log` when `DEBUG > 0` in `brother_lpdwrapper_BrGenML1`.
+    Note that when `DEBUG > 1` the wrapper stops performing its function. Better
+    keep `DEBUG == 1` unless this is desirable.
+
+    Now activable through this package's `debugLvl` parameter whose value is to be
+    used to establish `DEBUG`.
+
+    Issues
+    ------
+
+     1.  >  Error: /tmp/brBrGenML1rc_15642 :cannot open file !!
+
+        Fixed.
+
+     2.  >  touch: cannot touch '/tmp/BrGenML1_latest_print_info': Permission denied
+
+        Fixed.
+
+     3.  >  perl: warning: Falling back to the standard locale ("C").
+
+            are supported and installed on your system.
+            LANG = "en_US.UTF-8"
+            LC_ALL = (unset),
+            LANGUAGE = (unset),
+            perl: warning: Please check that your locale settings:
+            perl: warning: Setting locale failed.
+
+        TODO: Address.
+
+     4. Since nixos 16.03 release, in `brother_lpdwrapper_BrGenML1`:
+
+        > sh: grep: command not found
+          sh: chmod: command not found
+          sh: cp: command not found
+          Error: /tmp/brBrGenML1rc_1850 :cannot open file !!
+          sh: sed: command not found
+
+        Fixed by use of a wrapper that brings `coreutils`, `gnused`, `gnugrep`
+        in `PATH`.
+*/
+
+stdenv.mkDerivation rec {
+
+  name = "brgenml1cupswrapper-3.1.0-1";
+  src = fetchurl {
+    url = "https://download.brother.com/welcome/dlf101125/${name}.i386.deb";
+    sha256 = "0kd2a2waqr10kfv1s8is3nd5dlphw4d1343srdsbrlbbndja3s6r";
+  };
+
+  unpackPhase = ''
+    ar x $src
+    tar xfvz data.tar.gz
+  '';
+
+  nativeBuildInputs = [ makeWrapper ];
+  buildInputs = [ cups perl coreutils gnused gnugrep brgenml1lpr ];
+
+  dontBuild = true;
+
+  patchPhase = ''
+    WRAPPER=opt/brother/Printers/BrGenML1/cupswrapper/brother_lpdwrapper_BrGenML1
+    PAPER_CFG=opt/brother/Printers/BrGenML1/cupswrapper/paperconfigml1
+
+    substituteInPlace $WRAPPER \
+      --replace "basedir =~" "basedir = \"${brgenml1lpr}/opt/brother/Printers/BrGenML1\"; #" \
+      --replace "PRINTER =~" "PRINTER = \"BrGenML1\"; #" \
+      --replace "\$DEBUG=0;" "\$DEBUG=${debugLvl};"
+
+    # Fixing issue #1 and #2.
+    substituteInPlace $WRAPPER \
+      --replace "\`cp " "\`cp -p " \
+      --replace "\$TEMPRC\`" "\$TEMPRC; chmod a+rw \$TEMPRC\`" \
+      --replace "\`mv " "\`cp -p "
+
+    # This config script make this assumption that the *.ppd are found in a global location `/etc/cups/ppd`.
+    substituteInPlace $PAPER_CFG \
+      --replace "/etc/cups/ppd" "$out/share/cups/model"
+  '';
+
+
+  installPhase = ''
+    CUPSFILTER_DIR=$out/lib/cups/filter
+    CUPSPPD_DIR=$out/share/cups/model
+    CUPSWRAPPER_DIR=opt/brother/Printers/BrGenML1/cupswrapper
+
+    mkdir -p $out/$CUPSWRAPPER_DIR
+    cp -rp $CUPSWRAPPER_DIR/* $out/$CUPSWRAPPER_DIR
+
+    mkdir -p $CUPSFILTER_DIR
+    # Fixing issue #4.
+    makeWrapper \
+      $out/$CUPSWRAPPER_DIR/brother_lpdwrapper_BrGenML1 \
+      $CUPSFILTER_DIR/brother_lpdwrapper_BrGenML1 \
+      --prefix PATH : ${coreutils}/bin \
+      --prefix PATH : ${gnused}/bin \
+      --prefix PATH : ${gnugrep}/bin
+
+    mkdir -p $CUPSPPD_DIR
+    ln -s $out/$CUPSWRAPPER_DIR/brother-BrGenML1-cups-en.ppd $CUPSPPD_DIR
+  '';
+
+  dontPatchELF = true;
+  dontStrip = true;
+
+  meta = {
+    description = "Brother BrGenML1 CUPS wrapper driver";
+    homepage = "http://www.brother.com";
+    platforms = lib.platforms.linux;
+    license = lib.licenses.gpl2Plus;
+    maintainers = with lib.maintainers; [ jraygauthier ];
+  };
+}
diff --git a/nixpkgs/pkgs/misc/cups/drivers/brgenml1lpr/default.nix b/nixpkgs/pkgs/misc/cups/drivers/brgenml1lpr/default.nix
new file mode 100644
index 000000000000..6cdff2c4124e
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/brgenml1lpr/default.nix
@@ -0,0 +1,93 @@
+{ lib, stdenv, fetchurl, cups, perl, glibc, ghostscript, which, makeWrapper}:
+
+/*
+    [Setup instructions](http://support.brother.com/g/s/id/linux/en/instruction_prn1a.html).
+
+    URI example
+     ~  `lpd://BRW0080927AFBCE/binary_p1`
+
+    Logging
+    -------
+
+    `/tmp/br_lpdfilter_ml1.log` when `$ENV{LPD_DEBUG} > 0` in `filter_BrGenML1`
+    which is activated automatically when `DEBUG > 0` in `brother_lpdwrapper_BrGenML1`
+    from the cups wrapper.
+
+    Issues
+    ------
+
+     -  filter_BrGenML1 ln 196 `my $GHOST_SCRIPT=`which gs`;`
+
+        `GHOST_SCRIPT` is empty resulting in an empty `/tmp/br_lpdfilter_ml1_gsout.dat` file.
+        See `/tmp/br_lpdfilter_ml1.log` for the executed command.
+
+    Notes
+    -----
+
+     -  The `setupPrintcap` has totally no use in our context.
+*/
+
+let
+  myPatchElf = file: with lib; ''
+    patchelf --set-interpreter \
+      ${stdenv.glibc}/lib/ld-linux${optionalString stdenv.is64bit "-x86-64"}.so.2 \
+      ${file}
+  '';
+in
+stdenv.mkDerivation rec {
+
+  name = "brgenml1lpr-3.1.0-1";
+  src = fetchurl {
+    url = "https://download.brother.com/welcome/dlf101123/${name}.i386.deb";
+    sha256 = "0zdvjnrjrz9sba0k525linxp55lr4cyivfhqbkq1c11br2nvy09f";
+  };
+
+  unpackPhase = ''
+    ar x $src
+    tar xfvz data.tar.gz
+  '';
+
+  nativeBuildInputs = [ makeWrapper ];
+  buildInputs = [ cups perl glibc ghostscript which ];
+
+  dontBuild = true;
+
+  patchPhase = ''
+    INFDIR=opt/brother/Printers/BrGenML1/inf
+    LPDDIR=opt/brother/Printers/BrGenML1/lpd
+
+    # Setup max debug log by default.
+    substituteInPlace $LPDDIR/filter_BrGenML1 \
+      --replace "BR_PRT_PATH =~" "BR_PRT_PATH = \"$out/opt/brother/Printers/BrGenML1\"; #" \
+      --replace "PRINTER =~" "PRINTER = \"BrGenML1\"; #"
+
+    ${myPatchElf "$INFDIR/braddprinter"}
+    ${myPatchElf "$LPDDIR/brprintconflsr3"}
+    ${myPatchElf "$LPDDIR/rawtobr3"}
+  '';
+
+  installPhase = ''
+    INFDIR=opt/brother/Printers/BrGenML1/inf
+    LPDDIR=opt/brother/Printers/BrGenML1/lpd
+
+    mkdir -p $out/$INFDIR
+    cp -rp $INFDIR/* $out/$INFDIR
+    mkdir -p $out/$LPDDIR
+    cp -rp $LPDDIR/* $out/$LPDDIR
+
+    wrapProgram $out/$LPDDIR/filter_BrGenML1 \
+      --prefix PATH ":" "${ghostscript}/bin" \
+      --prefix PATH ":" "${which}/bin"
+  '';
+
+  dontPatchELF = true;
+
+
+  meta = {
+    description = "Brother BrGenML1 LPR driver";
+    homepage = "http://www.brother.com";
+    platforms = lib.platforms.linux;
+    license = lib.licenses.unfreeRedistributable;
+    maintainers = with lib.maintainers; [ jraygauthier ];
+  };
+}
diff --git a/nixpkgs/pkgs/misc/cups/drivers/brlaser/default.nix b/nixpkgs/pkgs/misc/cups/drivers/brlaser/default.nix
new file mode 100644
index 000000000000..b0dfd8d8170a
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/brlaser/default.nix
@@ -0,0 +1,63 @@
+{ lib, stdenv, fetchFromGitHub, cmake, zlib, cups }:
+
+stdenv.mkDerivation rec {
+  pname = "brlaser";
+  version = "6";
+
+  src = fetchFromGitHub {
+    owner = "pdewacht";
+    repo = "brlaser";
+    rev = "v${version}";
+    sha256 = "1995s69ksq1fz0vb34v0ndiqncrinbrlpmp70rkl6az7kag99s80";
+  };
+
+  nativeBuildInputs = [ cmake ];
+  buildInputs = [ zlib cups ];
+
+  cmakeFlags = [ "-DCUPS_SERVER_BIN=lib/cups" "-DCUPS_DATA_DIR=share/cups" ];
+
+  meta = with lib; {
+    description = "A CUPS driver for Brother laser printers";
+    longDescription =
+      ''
+       Although most Brother printers support a standard printer language such as PCL or PostScript, not all do. If you have a monochrome Brother laser printer (or multi-function device) and the other open source drivers don't work, this one might help.
+
+       This driver is known to work with these printers:
+
+           Brother DCP-1510
+           Brother DCP-1602
+           Brother DCP-7030
+           Brother DCP-7040
+           Brother DCP-7055
+           Brother DCP-7055W
+           Brother DCP-7060D
+           Brother DCP-7065DN
+           Brother DCP-7080
+           Brother DCP-L2500D
+           Brother DCP-L2520D
+           Brother DCP-L2540DW
+           Brother HL-1110
+           Brother HL-1200
+           Brother HL-2030
+           Brother HL-2140
+           Brother HL-2220
+           Brother HL-2270DW
+           Brother HL-5030
+           Brother HL-L2300D
+           Brother HL-L2320D
+           Brother HL-L2340D
+           Brother HL-L2360D
+           Brother MFC-1910W
+           Brother MFC-7240
+           Brother MFC-7360N
+           Brother MFC-7365DN
+           Brother MFC-7840W
+           Brother MFC-L2710DW
+           Lenovo M7605D
+      '';
+    homepage = "https://github.com/pdewacht/brlaser";
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ StijnDW ];
+  };
+}
diff --git a/nixpkgs/pkgs/misc/cups/drivers/brother/mfcl3770cdw/default.nix b/nixpkgs/pkgs/misc/cups/drivers/brother/mfcl3770cdw/default.nix
new file mode 100644
index 000000000000..10ed4368ce21
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/brother/mfcl3770cdw/default.nix
@@ -0,0 +1,88 @@
+{ pkgsi686Linux
+, stdenv
+, fetchurl
+, dpkg
+, makeWrapper
+, coreutils
+, ghostscript
+, gnugrep
+, gnused
+, which
+, perl
+, lib
+}:
+
+let
+  model = "mfcl3770cdw";
+  version = "1.0.2-0";
+  src = fetchurl {
+    url = "https://download.brother.com/welcome/dlf103935/${model}pdrv-${version}.i386.deb";
+    sha256 = "09fhbzhpjymhkwxqyxzv24b06ybmajr6872yp7pri39595mhrvay";
+  };
+  reldir = "opt/brother/Printers/${model}/";
+
+in rec {
+  driver = pkgsi686Linux.stdenv.mkDerivation rec {
+    inherit src version;
+    name = "${model}drv-${version}";
+
+    nativeBuildInputs = [ dpkg makeWrapper ];
+
+    unpackPhase = "dpkg-deb -x $src $out";
+
+    installPhase = ''
+      dir="$out/${reldir}"
+      substituteInPlace $dir/lpd/filter_${model} \
+        --replace /usr/bin/perl ${perl}/bin/perl \
+        --replace "BR_PRT_PATH =~" "BR_PRT_PATH = \"$dir\"; #" \
+        --replace "PRINTER =~" "PRINTER = \"${model}\"; #"
+      wrapProgram $dir/lpd/filter_${model} \
+        --prefix PATH : ${lib.makeBinPath [
+          coreutils ghostscript gnugrep gnused which
+        ]}
+    # need to use i686 glibc here, these are 32bit proprietary binaries
+    patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
+      $dir/lpd/brmfcl3770cdwfilter
+    '';
+
+    meta = {
+      description = "Brother ${lib.strings.toUpper model} driver";
+      homepage = "http://www.brother.com/";
+      license = lib.licenses.unfree;
+      platforms = [ "x86_64-linux" "i686-linux" ];
+      maintainers = [ lib.maintainers.steveej ];
+    };
+  };
+
+  cupswrapper = stdenv.mkDerivation rec {
+    inherit version src;
+    name = "${model}cupswrapper-${version}";
+
+    nativeBuildInputs = [ dpkg makeWrapper ];
+
+    unpackPhase = "dpkg-deb -x $src $out";
+
+    installPhase = ''
+      basedir=${driver}/${reldir}
+      dir=$out/${reldir}
+      substituteInPlace $dir/cupswrapper/brother_lpdwrapper_${model} \
+        --replace /usr/bin/perl ${perl}/bin/perl \
+        --replace "basedir =~" "basedir = \"$basedir\"; #" \
+        --replace "PRINTER =~" "PRINTER = \"${model}\"; #"
+      wrapProgram $dir/cupswrapper/brother_lpdwrapper_${model} \
+        --prefix PATH : ${lib.makeBinPath [ coreutils gnugrep gnused ]}
+      mkdir -p $out/lib/cups/filter
+      mkdir -p $out/share/cups/model
+      ln $dir/cupswrapper/brother_lpdwrapper_${model} $out/lib/cups/filter
+      ln $dir/cupswrapper/brother_${model}_printer_en.ppd $out/share/cups/model
+    '';
+
+    meta = {
+      description = "Brother ${lib.strings.toUpper model} CUPS wrapper driver";
+      homepage = "http://www.brother.com/";
+      license = lib.licenses.gpl2;
+      platforms = [ "x86_64-linux" "i686-linux" ];
+      maintainers = [ lib.maintainers.steveej ];
+    };
+  };
+}
diff --git a/nixpkgs/pkgs/misc/cups/drivers/canon/default.nix b/nixpkgs/pkgs/misc/cups/drivers/canon/default.nix
new file mode 100644
index 000000000000..754c0f4d1d0e
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/canon/default.nix
@@ -0,0 +1,225 @@
+{lib, stdenv, fetchurl, unzip, autoreconfHook, libtool, makeWrapper, cups, ghostscript, pkgsi686Linux, zlib }:
+
+let
+
+  i686_NIX_GCC = pkgsi686Linux.callPackage ({gcc}: gcc) {};
+  i686_libxml2 = pkgsi686Linux.callPackage ({libxml2}: libxml2) {};
+
+  commonVer = "4.10";
+  version = "3.70";
+  dl = "8/0100007658/08";
+
+  versionNoDots = builtins.replaceStrings ["."] [""] version;
+  src_canon = fetchurl {
+    url = "http://gdlp01.c-wss.com/gds/${dl}/linux-UFRII-drv-v${versionNoDots}-uken-05.tar.gz";
+    sha256 = "0424lvyrsvsb94qga4p4ldis7f714c5yw5ydv3f84mdl2a7papg0";
+  };
+
+in
+
+
+stdenv.mkDerivation {
+  pname = "canon-cups-ufr2";
+  version = version;
+  src = src_canon;
+
+  phases = [ "unpackPhase" "installPhase" ];
+
+  postUnpack = ''
+    (cd $sourceRoot; tar -xzf Sources/cndrvcups-common-${commonVer}-1.tar.gz)
+    (cd $sourceRoot; tar -xzf Sources/cndrvcups-lb-${version}-1.tar.gz)
+  '';
+
+  nativeBuildInputs = [ makeWrapper unzip autoreconfHook libtool ];
+
+  buildInputs = [ cups zlib ];
+
+  installPhase = ''
+    ##
+    ## cndrvcups-common buildPhase
+    ##
+    ( cd cndrvcups-common-${commonVer}/buftool
+      autoreconf -fi
+      ./autogen.sh --prefix=$out --enable-progpath=$out/bin --libdir=$out/lib --disable-shared --enable-static
+      make
+    )
+
+    ( cd cndrvcups-common-${commonVer}/backend
+      ./autogen.sh --prefix=$out --libdir=$out/lib
+      make
+    )
+
+    ( cd cndrvcups-common-${commonVer}/c3plmod_ipc
+      make
+    )
+
+    ##
+    ## cndrvcups-common installPhase
+    ##
+
+    ( cd cndrvcups-common-${commonVer}/buftool
+      make install
+    )
+
+    ( cd cndrvcups-common-${commonVer}/backend
+      make install
+    )
+
+    ( cd cndrvcups-common-${commonVer}/c3plmod_ipc
+      make install DESTDIR=$out/lib
+    )
+
+    ( cd cndrvcups-common-${commonVer}/libs
+      chmod 755 *
+      mkdir -p $out/lib32
+      mkdir -p $out/bin
+      cp libcaiowrap.so.1.0.0 $out/lib32
+      cp libcaiousb.so.1.0.0 $out/lib32
+      cp libc3pl.so.0.0.1 $out/lib32
+      cp libcaepcm.so.1.0 $out/lib32
+      cp libColorGear.so.0.0.0 $out/lib32
+      cp libColorGearC.so.1.0.0 $out/lib32
+      cp libcanon_slim.so.1.0.0 $out/lib32
+      cp c3pldrv $out/bin
+    )
+
+    (cd cndrvcups-common-${commonVer}/Rule
+      mkdir -p $out/share/usb
+      chmod 644 *.usb-quirks $out/share/usb
+    )
+
+    (cd cndrvcups-common-${commonVer}/data
+      chmod 644 *.ICC
+      mkdir -p $out/share/caepcm
+      cp *.ICC $out/share/caepcm
+      cp *.icc $out/share/caepcm
+      cp *.PRF $out/share/caepcm
+    )
+
+    (cd $out/lib32
+      ln -sf libc3pl.so.0.0.1 libc3pl.so.0
+      ln -sf libc3pl.so.0.0.1 libc3pl.so
+      ln -sf libcaepcm.so.1.0 libcaepcm.so.1
+      ln -sf libcaepcm.so.1.0 libcaepcm.so
+      ln -sf libcaiowrap.so.1.0.0 libcaiowrap.so.1
+      ln -sf libcaiowrap.so.1.0.0 libcaiowrap.so
+      ln -sf libcaiousb.so.1.0.0 libcaiousb.so.1
+      ln -sf libcaiousb.so.1.0.0 libcaiousb.so
+      ln -sf libcanon_slim.so.1.0.0 libcanon_slim.so.1
+      ln -sf libcanon_slim.so.1.0.0 libcanon_slim.so
+      ln -sf libColorGear.so.0.0.0 libColorGear.so.0
+      ln -sf libColorGear.so.0.0.0 libColorGear.so
+      ln -sf libColorGearC.so.1.0.0 libColorGearC.so.1
+      ln -sf libColorGearC.so.1.0.0 libColorGearC.so
+    )
+
+    (cd $out/lib
+      ln -sf libcanonc3pl.so.1.0.0 libcanonc3pl.so
+      ln -sf libcanonc3pl.so.1.0.0 libcanonc3pl.so.1
+    )
+
+    patchelf --set-rpath "$(cat ${i686_NIX_GCC}/nix-support/orig-cc)/lib" $out/lib32/libColorGear.so.0.0.0
+    patchelf --set-rpath "$(cat ${i686_NIX_GCC}/nix-support/orig-cc)/lib" $out/lib32/libColorGearC.so.1.0.0
+
+    patchelf --interpreter "$(cat ${i686_NIX_GCC}/nix-support/dynamic-linker)" --set-rpath "$out/lib32" $out/bin/c3pldrv
+
+    # c3pldrv is programmed with fixed paths that point to "/usr/{bin,lib.share}/..."
+    # preload32 wrappes all necessary function calls to redirect the fixed paths
+    # into $out.
+    mkdir -p $out/libexec
+    preload32=$out/libexec/libpreload32.so
+    ${i686_NIX_GCC}/bin/gcc -shared ${./preload.c} -o $preload32 -ldl -DOUT=\"$out\" -fPIC
+    wrapProgram "$out/bin/c3pldrv" \
+      --set PRELOAD_DEBUG 1 \
+      --set LD_PRELOAD $preload32 \
+      --prefix LD_LIBRARY_PATH : "$out/lib32"
+
+
+
+    ##
+    ## cndrvcups-lb buildPhase
+    ##
+
+    ( cd cndrvcups-lb-${version}/buftool
+      ./autogen.sh --prefix=$out --libdir=$out/lib --enable-progpath=$out/bin --enable-static
+      make
+    )
+
+    ( cd cndrvcups-lb-${version}/pstoufr2cpca
+      ./autogen.sh --prefix=$out --libdir=$out/lib
+      make
+    )
+
+    ##
+    ## cndrvcups-lb installPhase
+    ##
+
+    ( cd cndrvcups-lb-${version}/pstoufr2cpca
+      make install
+    )
+
+    ( cd cndrvcups-lb-${version}/libs
+      chmod 755 *
+      mkdir -p $out/lib32
+      mkdir -p $out/bin
+      cp libcanonufr2.la $out/lib32
+      cp libcanonufr2.so.1.0.0 $out/lib32
+      cp libufr2filter.so.1.0.0 $out/lib32
+      cp libEnoJBIG.so.1.0.0 $out/lib32
+      cp libEnoJPEG.so.1.0.0 $out/lib32
+      cp libcaiocnpkbidi.so.1.0.0 $out/lib32
+      cp libcnlbcm.so.1.0 $out/lib32
+
+      cp cnpkmoduleufr2 $out/bin #maybe needs setuid 4755
+      cp cnpkbidi $out/bin
+    )
+
+    ( cd $out/lib32
+      ln -sf libcanonufr2.so.1.0.0 libcanonufr2.so
+      ln -sf libcanonufr2.so.1.0.0 libcanonufr2.so.1
+      ln -sf libufr2filter.so.1.0.0 libufr2filter.so
+      ln -sf libufr2filter.so.1.0.0 libufr2filter.so.1
+      ln -sf libEnoJBIG.so.1.0.0 libEnoJBIG.so
+      ln -sf libEnoJBIG.so.1.0.0 libEnoJBIG.so.1
+      ln -sf libEnoJPEG.so.1.0.0 libEnoJPEG.so
+      ln -sf libEnoJPEG.so.1.0.0 libEnoJPEG.so.1
+      ln -sf libcaiocnpkbidi.so.1.0.0 libcaiocnpkbidi.so
+      ln -sf libcaiocnpkbidi.so.1.0.0 libcaiocnpkbidi.so.1
+      ln -sf libcnlbcm.so.1.0 libcnlbcm.so.1
+      ln -sf libcnlbcm.so.1.0 libcnlbcm.so
+    )
+
+    ( cd cndrvcups-lb-${version}
+      chmod 644 data/CnLB*
+      chmod 644 libs/cnpkbidi_info*
+      chmod 644 libs/ThLB*
+      mkdir -p $out/share/caepcm
+      mkdir -p $out/share/cnpkbidi
+      mkdir -p $out/share/ufr2filter
+      cp data/CnLB* $out/share/caepcm
+      cp libs/cnpkbidi_info* $out/share/cnpkbidi
+      cp libs/ThLB* $out/share/ufr2filter
+    )
+
+    mkdir -p $out/share/cups/model
+    install -c -m 644 cndrvcups-lb-${version}/ppd/CN*.ppd $out/share/cups/model/
+
+    patchelf --set-rpath "$out/lib32:${i686_libxml2.out}/lib" $out/lib32/libcanonufr2.so.1.0.0
+
+    patchelf --interpreter "$(cat ${i686_NIX_GCC}/nix-support/dynamic-linker)" --set-rpath "$out/lib32" $out/bin/cnpkmoduleufr2
+    patchelf --interpreter "$(cat ${i686_NIX_GCC}/nix-support/dynamic-linker)" --set-rpath "$out/lib32:${i686_libxml2.out}/lib" $out/bin/cnpkbidi
+
+    makeWrapper "${ghostscript}/bin/gs" "$out/bin/gs" \
+      --prefix LD_LIBRARY_PATH ":" "$out/lib" \
+      --prefix PATH ":" "$out/bin"
+    '';
+
+  meta = with lib; {
+    description = "CUPS Linux drivers for Canon printers";
+    homepage = "http://www.canon.com/";
+    license = licenses.unfree;
+    maintainers = with maintainers; [
+      kylesferrazza
+    ];
+  };
+}
diff --git a/nixpkgs/pkgs/misc/cups/drivers/canon/preload.c b/nixpkgs/pkgs/misc/cups/drivers/canon/preload.c
new file mode 100644
index 000000000000..f3a30063a6e3
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/canon/preload.c
@@ -0,0 +1,81 @@
+/*
+ * LD_PRELOAD trick to make c3pldrv handle the absolute path to /usr/{bin,lib,share)}.
+ * As c3pldrv is a 32 bit executable, /lib will be rewritten to /lib32.
+ *
+ * Usage:
+ *   gcc -shared -fPIC -DOUT="$out" preload.c -o preload.so -ldl
+ *   LD_PRELOAD=$PWD/preload.so ./c3pldrv
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <dlfcn.h>
+#include <limits.h>
+
+#ifndef OUT
+#error Missing OUT define - path to the installation directory.
+#endif
+
+typedef void *(*dlopen_func_t)(const char *filename, int flag);
+typedef int (*open_func_t)(const char *pathname, int flags, ...);
+typedef int (*execv_func_t)(const char *path, char *const argv[]);
+
+
+void *dlopen(const char *filename, int flag)
+{
+	dlopen_func_t orig_dlopen;
+	const char *new_filename;
+	char buffer[PATH_MAX];
+
+	orig_dlopen = (dlopen_func_t)dlsym(RTLD_NEXT, "dlopen");
+
+	new_filename = filename;
+	if (strncmp("/usr/lib", filename, 8) == 0) {
+		snprintf(buffer, PATH_MAX, OUT "/lib32%s", filename+8);
+		buffer[PATH_MAX-1] = '\0';
+		new_filename = buffer;
+	}
+	
+	return orig_dlopen(new_filename, flag);
+}
+
+int open(const char *pathname, int flags, ...)
+{
+	open_func_t orig_open;
+	const char *new_pathname;
+	char buffer[PATH_MAX];
+
+	orig_open = (open_func_t)dlsym(RTLD_NEXT, "open");
+
+	new_pathname = pathname;
+	if (strncmp("/usr/share", pathname, 10) == 0) {
+		snprintf(buffer, PATH_MAX, OUT "%s", pathname+4);
+		buffer[PATH_MAX-1] = '\0';
+		new_pathname = buffer;
+	}
+	
+	return orig_open(new_pathname, flags);
+}
+
+int execv(const char *path, char *const argv[])
+{
+	execv_func_t orig_execv;
+	const char *new_path;
+	char buffer[PATH_MAX];
+
+	orig_execv = (execv_func_t)dlsym(RTLD_NEXT, "execv");
+
+	new_path = path;
+	if (strncmp("/usr/bin", path, 8) == 0) {
+		snprintf(buffer, PATH_MAX, OUT "%s", path+4);
+		buffer[PATH_MAX-1] = '\0';
+		new_path = buffer;
+	}
+	
+	return orig_execv(new_path, argv);
+}
+
diff --git a/nixpkgs/pkgs/misc/cups/drivers/carps-cups/default.nix b/nixpkgs/pkgs/misc/cups/drivers/carps-cups/default.nix
new file mode 100644
index 000000000000..32e92da16084
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/carps-cups/default.nix
@@ -0,0 +1,44 @@
+{ stdenv
+, lib
+, fetchFromGitHub
+, cups
+}:
+
+stdenv.mkDerivation {
+  pname = "carps-cups";
+  version = "unstable-2018-03-05";
+
+  src = fetchFromGitHub {
+    owner = "ondrej-zary";
+    repo = "carps-cups";
+    rev = "18d80d1d6f473dd9132e4b6d8b5c592c74982f17";
+    sha256 = "0mjj9hs5lqxi0qamgb4sxfz4fvf7ggi66bxd37bkz3fl0g9xff70";
+  };
+
+  preBuild = ''
+    export CUPS_DATADIR="${cups}/share/cups"
+  '';
+
+  installPhase = ''
+    CUPSDIR="$out/lib/cups"
+    CUPSDATADIR="$out/share/cups"
+
+    mkdir -p "$CUPSDIR/filter" "$CUPSDATADIR/drv" "$CUPSDATADIR/usb"
+
+    install -s rastertocarps $CUPSDIR/filter
+    install -m 644 carps.drv $CUPSDATADIR/drv/
+    install -m 644 carps.usb-quirks $CUPSDATADIR/usb/
+  '';
+
+  buildInputs = [ cups ];
+
+  meta = with lib; {
+    description = "CUPS Linux drivers for Canon printers";
+    homepage = "https://www.canon.com/";
+    license = licenses.gpl3Plus;
+    maintainers = with maintainers; [
+      ewok
+    ];
+  };
+}
+
diff --git a/nixpkgs/pkgs/misc/cups/drivers/cnijfilter2/default.nix b/nixpkgs/pkgs/misc/cups/drivers/cnijfilter2/default.nix
new file mode 100644
index 000000000000..ce11f4a0551b
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/cnijfilter2/default.nix
@@ -0,0 +1,123 @@
+{ stdenv, lib, fetchzip, autoconf, automake, cups, glib, libxml2, libusb1, libtool
+, withDebug ? false }:
+
+stdenv.mkDerivation {
+  pname = "cnijfilter2";
+
+  version = "5.70";
+
+  src = fetchzip {
+    url = "http://gdlp01.c-wss.com/gds/0/0100009930/01/cnijfilter2-source-5.70-1.tar.gz";
+    sha256 = "045zjsmaidn1m44ki6m1018gjzbj77gm234n5i2lshxpbzpyh0is";
+  };
+
+  buildInputs = [
+    cups automake autoconf glib libxml2 libusb1 libtool
+  ];
+
+  # lgmon3's --enable-libdir flag is used soley for specifying in which
+  # directory the cnnnet.ini cache file should reside.
+  # NixOS uses /var/cache/cups, and given the name, it seems like a reasonable
+  # place to put the cnnet.ini file, and thus we do so.
+  #
+  # Note that the drivers attempt to dlopen
+  # $out/lib/cups/filter/libcnbpcnclapicom2.so
+  buildPhase = ''
+    mkdir -p $out/lib
+    cp com/libs_bin64/* $out/lib
+    mkdir -p $out/lib/cups/filter
+    ln -s $out/lib/libcnbpcnclapicom2.so $out/lib/cups/filter
+
+    export NIX_LDFLAGS="$NIX_LDFLAGS -L$out/lib"
+  '' + lib.optionalString withDebug ''
+    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -D__DEBUG__ -DDEBUG_LOG"
+  '' + ''
+
+    (
+      cd lgmon3
+      substituteInPlace src/Makefile.am \
+        --replace /usr/include/libusb-1.0 \
+                  ${libusb1.dev}/include/libusb-1.0
+      ./autogen.sh --prefix=$out --enable-progpath=$out/bin \
+                   --datadir=$out/share \
+                   --enable-libdir=/var/cache/cups
+      make
+    )
+
+    (
+      cd cmdtocanonij2
+      ./autogen.sh --prefix=$out
+      make
+    )
+
+    (
+      cd cnijbe2
+      substituteInPlace src/Makefile.am \
+        --replace "/usr/lib/cups/backend" \
+                  "$out/lib/cups/backend"
+      ./autogen.sh --prefix=$out --enable-progpath=$out/bin
+      make
+    )
+
+    (
+      cd rastertocanonij
+      ./autogen.sh --prefix=$out --enable-progpath=$out/bin
+      make
+    )
+
+    (
+      cd tocanonij
+      ./autogen.sh --prefix=$out --enable-progpath=$out/bin
+      make
+    )
+
+    (
+      cd tocnpwg
+      ./autogen.sh --prefix=$out --enable-progpath=$out/bin
+      make
+    )
+  '';
+
+  installPhase = ''
+    (
+      cd lgmon3
+      make install
+    )
+
+    (
+      cd cmdtocanonij2
+      make install
+    )
+
+    (
+      cd cnijbe2
+      make install
+    )
+
+    (
+      cd rastertocanonij
+      make install
+    )
+
+    (
+      cd tocanonij
+      make install
+    )
+
+    (
+      cd tocnpwg
+      make install
+    )
+
+    mkdir -p $out/share/cups/model
+    cp ppd/*.ppd $out/share/cups/model
+  '';
+
+  meta = with lib; {
+    description = "Canon InkJet printer drivers for the MG7500, MG6700, MG6600, MG5600, MG2900, MB2000, MB2300, iB4000, MB5000, MB5300, iP110, E450, MX490, E480, MG7700, MG6900, MG6800, MG5700, MG3600, and G3000 series";
+    homepage = "http://support-th.canon-asia.com/contents/TH/EN/0100712901.html";
+    license = licenses.unfree;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ cstrahan ];
+  };
+}
diff --git a/nixpkgs/pkgs/misc/cups/drivers/cnijfilter_2_80/default.nix b/nixpkgs/pkgs/misc/cups/drivers/cnijfilter_2_80/default.nix
new file mode 100644
index 000000000000..2cb3fe01ddb6
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/cnijfilter_2_80/default.nix
@@ -0,0 +1,109 @@
+{ stdenv, lib, fetchzip,
+  autoconf, automake, libtool,
+  cups, popt, libtiff, libpng,
+  ghostscript }:
+
+/* this derivation is basically just a transcription of the rpm .spec
+   file included in the tarball */
+
+stdenv.mkDerivation {
+  pname = "cnijfilter";
+
+  /* important note about versions: cnijfilter packages seem to use
+     versions in a non-standard way.  the version indicates which
+     printers are supported in the package.  so this package should
+     not be "upgraded" in the usual way.
+
+     instead, if you want to include another version supporting your
+     printer, you should try to abstract out the common things (which
+     should be pretty much everything except the version and the 'pr'
+     and 'pr_id' values to loop over). */
+  version = "2.80";
+
+  src = fetchzip {
+    url = "http://gdlp01.c-wss.com/gds/1/0100000841/01/cnijfilter-common-2.80-1.tar.gz";
+    sha256 = "06s9nl155yxmx56056y22kz1p5b2sb5fhr3gf4ddlczjkd1xch53";
+  };
+
+  buildInputs = [ autoconf libtool automake
+                  cups popt libtiff libpng
+                  ghostscript ];
+
+  patches = [ ./patches/missing-include.patch
+              ./patches/libpng15.patch ];
+
+  postPatch = ''
+    sed -i "s|/usr/lib/cups/backend|$out/lib/cups/backend|" backend/src/Makefile.am;
+    sed -i "s|/usr|$out|" backend/src/cnij_backend_common.c;
+    sed -i "s|/usr/bin|${ghostscript}/bin|" pstocanonij/filter/pstocanonij.c;
+    sed -i "s|/usr/local|$out|" libs/bjexec/bjexec.c;
+  '';
+
+  configurePhase = ''
+    cd libs
+    ./autogen.sh --prefix=$out;
+
+    cd ../cngpij
+    ./autogen.sh --prefix=$out --enable-progpath=$out/bin;
+
+    cd ../pstocanonij
+    ./autogen.sh --prefix=$out --enable-progpath=$out/bin;
+
+    cd ../backend
+    ./autogen.sh --prefix=$out;
+    cd ..;
+  '';
+
+  preInstall = ''
+    mkdir -p $out/bin $out/lib/cups/filter $out/share/cups/model;
+  '';
+
+  postInstall = ''
+    for pr in mp140 mp210 ip3500 mp520 ip4500 mp610; do
+      cd ppd;
+      ./autogen.sh --prefix=$out --program-suffix=$pr
+      make clean;
+      make;
+      make install;
+
+      cd ../cnijfilter;
+      ./autogen.sh --prefix=$out --program-suffix=$pr --enable-libpath=/var/lib/cups/path/lib/bjlib --enable-binpath=$out/bin;
+      make clean;
+      make;
+      make install;
+
+      cd ..;
+    done;
+
+    mkdir -p $out/lib/bjlib;
+    for pr_id in 315 316 319 328 326 327; do
+      install -c -m 755 $pr_id/database/* $out/lib/bjlib;
+      install -c -s -m 755 $pr_id/libs_bin/*.so.* $out/lib;
+    done;
+
+    pushd $out/lib;
+    for so_file in *.so.*; do
+      ln -s $so_file ''${so_file/.so.*/}.so;
+      patchelf --set-rpath $out/lib $so_file;
+    done;
+    popd;
+  '';
+
+  /* the tarball includes some pre-built shared libraries.  we run
+     'patchelf --set-rpath' on them just a few lines above, so that
+     they can find each other.  but that's not quite enough.  some of
+     those libraries load each other in non-standard ways -- they
+     don't list each other in the DT_NEEDED section.  so, if the
+     standard 'patchelf --shrink-rpath' (from
+     pkgs/development/tools/misc/patchelf/setup-hook.sh) is run on
+     them, it undoes the --set-rpath.  this prevents that. */
+  dontPatchELF = true;
+
+  meta = with lib; {
+    description = "Canon InkJet printer drivers for the iP5400, MP520, MP210, MP140, iP3500, and MP610 series.  (MP520 drivers also work for MX700.)";
+    homepage = "http://support-asia.canon-asia.com/content/EN/0100084101.html";
+    license = licenses.unfree;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ jerith666 ];
+  };
+}
diff --git a/nixpkgs/pkgs/misc/cups/drivers/cnijfilter_2_80/patches/libpng15.patch b/nixpkgs/pkgs/misc/cups/drivers/cnijfilter_2_80/patches/libpng15.patch
new file mode 100644
index 000000000000..f5b3a1b13db5
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/cnijfilter_2_80/patches/libpng15.patch
@@ -0,0 +1,23 @@
+diff -aur cnijfilter-source-3.20-1/cnijfilter/src/bjfimage.c cnijfilter-source-3.20-1.new/cnijfilter/src/bjfimage.c
+--- cnijfilter-source-3.20-1/cnijfilter/src/bjfimage.c	2009-03-26 06:11:05.000000000 +0100
++++ cnijfilter-source-3.20-1.new/cnijfilter/src/bjfimage.c	2012-02-10 09:33:52.512334139 +0100
+@@ -1520,8 +1520,8 @@
+ 	short			tmpformat;
+ 	short			retbyte = 0;
+ 	short			bpp = 3;
+-	long			width = 0;
+-	long			length = 0;
++	png_uint_32		width = 0;
++	png_uint_32		length = 0;
+ 	long			rstep = 0;
+ 	long			RasterLength = 0;
+ 	long			i;
+@@ -1574,7 +1574,7 @@
+ 		goto onErr;
+ 	}
+ 
+-	if (setjmp (png_p->jmpbuf))
++	if (setjmp (png_jmpbuf(png_p)))
+ 	{
+ 		png_destroy_read_struct(&png_p, &info_p, (png_infopp)NULL);
+ 		goto onErr;
diff --git a/nixpkgs/pkgs/misc/cups/drivers/cnijfilter_2_80/patches/missing-include.patch b/nixpkgs/pkgs/misc/cups/drivers/cnijfilter_2_80/patches/missing-include.patch
new file mode 100644
index 000000000000..20c2d756d1eb
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/cnijfilter_2_80/patches/missing-include.patch
@@ -0,0 +1,20 @@
+--- a/backend/src/cnij_backend_common.c	2008-09-01 10:05:44.000000000 +0200
++++ b/backend/src/cnij_backend_common.c	2012-05-06 17:38:40.000000000 +0200
+@@ -39,6 +39,7 @@
+ // CUPS Header
+ #include <cups/cups.h>
+ #include <cups/ipp.h>
++#include <cups/ppd.h>
+ 
+ // Header file for CANON
+ #include "cnij_backend_common.h"
+--- a/cngpijmon/src/bjcupsmon_cups.c	2008-09-02 12:28:24.000000000 +0200
++++ b/cngpijmon/src/bjcupsmon_cups.c	2012-05-06 17:39:20.000000000 +0200
+@@ -21,6 +21,7 @@
+ /*** Includes ***/
+ #include <cups/cups.h>
+ #include <cups/language.h>
++#include <cups/ppd.h>
+ #include <sys/types.h>
+ #include <unistd.h>
+ #include <pwd.h>
diff --git a/nixpkgs/pkgs/misc/cups/drivers/cnijfilter_4_00/default.nix b/nixpkgs/pkgs/misc/cups/drivers/cnijfilter_4_00/default.nix
new file mode 100644
index 000000000000..f6504b598cb0
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/cnijfilter_4_00/default.nix
@@ -0,0 +1,150 @@
+{ stdenv, lib, fetchzip,
+  autoconf, automake, libtool,
+  cups, popt, libtiff, libpng,
+  ghostscript, glib, libusb1, libxml2 }:
+
+/* this derivation is basically just a transcription of the rpm .spec
+   file included in the tarball */
+
+let arch =
+  if stdenv.hostPlatform.system == "x86_64-linux" then "64"
+    else if stdenv.hostPlatform.system == "i686-linux" then "32"
+    else throw "Unsupported system ${stdenv.hostPlatform.system}";
+
+in stdenv.mkDerivation {
+  pname = "cnijfilter";
+
+  /* important note about versions: cnijfilter packages seem to use
+     versions in a non-standard way.  the version indicates which
+     printers are supported in the package.  so this package should
+     not be "upgraded" in the usual way.
+
+     instead, if you want to include another version supporting your
+     printer, you should try to abstract out the common things (which
+     should be pretty much everything except the version and the 'pr'
+     and 'pr_id' values to loop over). */
+  version = "4.00";
+
+  src = fetchzip {
+    url = "http://gdlp01.c-wss.com/gds/5/0100005515/01/cnijfilter-source-4.00-1.tar.gz";
+    sha256 = "1f6vpx1z3qa88590i5m0s49j9n90vpk81xmw6pvj0nfd3qbvzkya";
+  };
+
+  buildInputs = [ autoconf libtool automake
+                  cups popt libtiff libpng
+                  ghostscript glib libusb1 libxml2 ];
+
+  # patches from https://github.com/tokiclover/bar-overlay/tree/master/net-print/cnijfilter
+  patches = [
+    ./patches/cnijfilter-3.80-1-cups-1.6.patch
+    ./patches/cnijfilter-3.80-6-cups-1.6.patch
+    ./patches/cnijfilter-4.00-4-ppd.patch
+    ./patches/cnijfilter-4.00-5-abi_x86_32.patch
+    ./patches/cnijfilter-4.00-6-headers.patch
+  ];
+
+  postPatch = ''
+    sed -i "s|/usr/lib/cups/backend|$out/lib/cups/backend|" backend/src/Makefile.am;
+    sed -i "s|/usr/lib/cups/backend|$out/lib/cups/backend|" backendnet/backend/Makefile.am;
+    sed -i "s|/usr/lib/cups/backend|$out/lib/cups/backend|" cnijbe/src/Makefile.am;
+    sed -i "s|/usr|$out|" backend/src/cnij_backend_common.c;
+    sed -i "s|/usr/bin|${ghostscript}/bin|" pstocanonij/filter/pstocanonij.c;
+  '';
+
+  configurePhase = ''
+    cd libs
+    ./autogen.sh --prefix=$out
+
+    cd ../bscc2sts
+    ./autogen.sh
+
+    cd ../cnijnpr
+    ./autogen.sh --prefix=$out --enable-libpath=$out/lib/bjlib
+
+    cd ../cngpij
+    ./autogen.sh --prefix=$out --enable-progpath=$out/bin
+
+    cd ../cngpijmnt
+    ./autogen.sh --prefix=$out --enable-progpath=$out/bin
+
+    cd ../pstocanonij
+    ./autogen.sh --prefix=$out --enable-progpath=$out/bin
+
+    cd ../backend
+    ./autogen.sh --prefix=$out
+
+    cd ../backendnet
+    ./autogen.sh --prefix=$out --enable-libpath=$out/lib/bjlib --enable-progpath=$out/bin
+
+    cd ../cmdtocanonij
+    ./autogen.sh --prefix=$out --datadir=$out/share
+
+    cd ../cnijbe
+    ./autogen.sh --prefix=$out --enable-progpath=$out/bin
+
+    cd ../lgmon2
+    substituteInPlace src/Makefile.am \
+        --replace /usr/include/libusb-1.0 \
+                  ${libusb1.dev}/include/libusb-1.0
+    ./autogen.sh --prefix=$out --enable-libpath=$out/lib/bjlib --enable-progpath=$out/bin
+
+    cd ..;
+
+    sed -e "s,cnijlgmon2_LDADD =,cnijlgmon2_LDADD = -L../../com/libs_bin${arch}," \
+    -i lgmon2/src/Makefile.am || die
+  '';
+
+  preInstall = ''
+    mkdir -p $out/bin $out/lib/cups/filter $out/share/cups/model;
+  '';
+
+  postInstall = ''
+    set -o xtrace
+    for pr in mg2400 mg2500 mg3500 mg5500 mg6400 mg6500 mg7100 p200; do
+      cd ppd;
+      ./autogen.sh --prefix=$out --program-suffix=$pr
+      make clean;
+      make;
+      make install;
+
+      cd ../cnijfilter;
+      ./autogen.sh --prefix=$out --program-suffix=$pr --enable-libpath=/var/lib/cups/path/lib/bjlib --enable-binpath=$out/bin;
+      make clean;
+      make;
+      make install;
+
+      cd ..;
+    done;
+
+    mkdir -p $out/lib/bjlib;
+    for pr_id in 423 424 425 426 427 428 429 430; do
+      install -c -m 755 $pr_id/database/* $out/lib/bjlib;
+      install -c -s -m 755 $pr_id/libs_bin${arch}/*.so.* $out/lib;
+    done;
+
+    pushd $out/lib;
+    for so_file in *.so.*; do
+      ln -s $so_file ''${so_file/.so.*/}.so;
+      patchelf --set-rpath $out/lib $so_file;
+    done;
+    popd;
+  '';
+
+  /* the tarball includes some pre-built shared libraries.  we run
+     'patchelf --set-rpath' on them just a few lines above, so that
+     they can find each other.  but that's not quite enough.  some of
+     those libraries load each other in non-standard ways -- they
+     don't list each other in the DT_NEEDED section.  so, if the
+     standard 'patchelf --shrink-rpath' (from
+     pkgs/development/tools/misc/patchelf/setup-hook.sh) is run on
+     them, it undoes the --set-rpath.  this prevents that. */
+  dontPatchELF = true;
+
+  meta = with lib; {
+    description = "Canon InkJet printer drivers for the MG2400 MG2500 MG3500 MG5500 MG6400 MG6500 MG7100 and P200 series";
+    homepage = "https://www.canon-europe.com/support/consumer_products/products/fax__multifunctionals/inkjet/pixma_mg_series/pixma_mg5550.aspx?type=drivers&driverdetailid=tcm:13-1094072";
+    license = licenses.unfree;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ chpatrick ];
+  };
+}
diff --git a/nixpkgs/pkgs/misc/cups/drivers/cnijfilter_4_00/patches/cnijfilter-3.80-1-cups-1.6.patch b/nixpkgs/pkgs/misc/cups/drivers/cnijfilter_4_00/patches/cnijfilter-3.80-1-cups-1.6.patch
new file mode 100644
index 000000000000..dfc0bb2268cb
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/cnijfilter_4_00/patches/cnijfilter-3.80-1-cups-1.6.patch
@@ -0,0 +1,62 @@
+--- a/cngpij/cngpij/bjcups.c
++++ a/cngpij/cngpij/bjcups.c
+@@ -698,8 +719,8 @@
+ 	else {
+ 		pRequest = ippNew();
+ 		
+-		pRequest->request.op.operation_id = CUPS_GET_PRINTERS;
+-		pRequest->request.op.request_id   = 1;
++		ippSetOperation(pRequest, CUPS_GET_PRINTERS);
++		ippSetRequestId(pRequest, 1);
+ 		
+ 		pLanguage = bjcupsLangDefault();	// cupsLangDefault() -> bjcupsLangDefault() for cups-1.1.19
+ 		
+@@ -708,29 +729,29 @@
+ 		ippAddString(pRequest, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, NULL);
+ 		
+ 		if ((pResponse = cupsDoRequest(pHTTP, pRequest, "/")) != NULL) {
+-			if (pResponse->request.status.status_code > IPP_OK_CONFLICT) {
++			if (ippGetStatusCode(pResponse) > IPP_OK_CONFLICT) {
+ 				fputs("ERROR: IPP ERROR\n", stderr);
+ 				goto onErr;
+ 			}
+ 			else {
+-				pAttribute = pResponse->attrs;
++				pAttribute = ippFirstAttribute(pResponse);
+ 
+ 				while (pAttribute != NULL) {
+-					while (pAttribute != NULL && pAttribute->group_tag != IPP_TAG_PRINTER) {
+-						pAttribute = pAttribute->next;
++					while (pAttribute != NULL && ippGetGroupTag(pAttribute) != IPP_TAG_PRINTER) {
++						pAttribute = ippNextAttribute(pResponse);
+ 					}
+ 					if (pAttribute == NULL) {
+ 						break;
+ 					}
+ 					
+-					while (pAttribute != NULL && pAttribute->group_tag == IPP_TAG_PRINTER) {
+-						if (strcmp(pAttribute->name, "printer-name") == 0 && pAttribute->value_tag == IPP_TAG_NAME) {
+-							pPrinter = pAttribute->values[0].string.text;
++					while (pAttribute != NULL && ippGetGroupTag(pAttribute) == IPP_TAG_PRINTER) {
++						if (strcmp(ippGetName(pAttribute), "printer-name") == 0 && ippGetValueTag(pAttribute) == IPP_TAG_NAME) {
++							pPrinter = ippGetString(pAttribute, 0, NULL);
+ 						}
+-						if (strcmp(pAttribute->name, "device-uri") == 0 && pAttribute->value_tag == IPP_TAG_URI) {
+-							pDUri = pAttribute->values[0].string.text;
++						if (strcmp(ippGetName(pAttribute), "device-uri") == 0 && ippGetValueTag(pAttribute) == IPP_TAG_URI) {
++							pDUri = ippGetString(pAttribute, 0, NULL);
+ 						}
+-						pAttribute = pAttribute->next;
++						pAttribute = ippNextAttribute(pResponse);
+ 					}
+ 
+ 					if (strcasecmp(pDestName, pPrinter) == 0) {
+@@ -739,7 +760,7 @@
+ 					}
+ 					
+ 					if (pAttribute != NULL)
+-						 pAttribute = pAttribute->next;
++						pAttribute = ippNextAttribute(pResponse);
+ 				}
+ 			}
+
diff --git a/nixpkgs/pkgs/misc/cups/drivers/cnijfilter_4_00/patches/cnijfilter-3.80-6-cups-1.6.patch b/nixpkgs/pkgs/misc/cups/drivers/cnijfilter_4_00/patches/cnijfilter-3.80-6-cups-1.6.patch
new file mode 100644
index 000000000000..6b51d4837d45
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/cnijfilter_4_00/patches/cnijfilter-3.80-6-cups-1.6.patch
@@ -0,0 +1,87 @@
+diff --git a/cngpijmnt/src/getipc.c b/cngpijmnt/src/getipc.c
+index 8688032..54c7933 100755
+--- a/cngpijmnt/src/getipc.c
++++ b/cngpijmnt/src/getipc.c
+@@ -42,7 +42,7 @@ int GetIPCData(LPIPCU pipc, char *sname)
+ 	int server_fd;
+ 	int client_fd;
+ 	char buf[128];
+-	size_t len;
++	socklen_t len;
+ 	short ret = RET_ERROR;
+ 
+ 	if( (server_fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0 )
+
+--- a/cngpijmnt/src/main.c	2016-11-12 23:39:03.534855723 +0100
++++ b/cngpijmnt/src/main.c	2016-11-12 23:47:02.521847145 +0100
+@@ -308,8 +308,8 @@
+ 					*pResponse;					// Pointer to CUPS IPP response.
+ 	ipp_attribute_t	*pAttribute;				// Pointer to CUPS attributes.
+ 	cups_lang_t		*pLanguage;					// Pointer to language.
+-	char			*pPrinter = NULL;			// Pointer to printer name.
+-	char			*pDUri = NULL;				// Pointer to Device uri.
++	const char			*pPrinter = NULL;			// Pointer to printer name.
++	const char			*pDUri = NULL;				// Pointer to Device uri.
+ 	short			retVal = -1;	// Return value.
+ /*** Parameters end ***/
+ 	
+@@ -321,8 +321,8 @@
+ 	else {
+ 		pRequest = ippNew();
+ 		
+-		pRequest->request.op.operation_id = CUPS_GET_PRINTERS;
+-		pRequest->request.op.request_id   = 1;
++		ippSetOperation(pRequest, CUPS_GET_PRINTERS);
++		ippSetRequestId(pRequest, 1);
+ 		
+ 		pLanguage = bjcupsLangDefault();	// cupsLangDefault() -> bjcupsLangDefault() for cups-1.1.19
+ 		
+@@ -331,29 +331,29 @@
+ 		ippAddString(pRequest, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, NULL);
+ 		
+ 		if ((pResponse = cupsDoRequest(pHTTP, pRequest, "/")) != NULL) {
+-			if (pResponse->request.status.status_code > IPP_OK_CONFLICT) {
++			if (ippGetStatusCode(pResponse) > IPP_OK_CONFLICT) {
+ 				fputs("ERROR: IPP ERROR\n", stderr);
+ 				goto onErr;
+ 			}
+ 			else {
+-				pAttribute = pResponse->attrs;
++				pAttribute = ippFirstAttribute(pResponse);
+ 
+ 				while (pAttribute != NULL) {
+-					while (pAttribute != NULL && pAttribute->group_tag != IPP_TAG_PRINTER) {
+-						pAttribute = pAttribute->next;
++					while (pAttribute != NULL && ippGetGroupTag(pAttribute) != IPP_TAG_PRINTER) {
++						pAttribute = ippNextAttribute(pResponse);
+ 					}
+ 					if (pAttribute == NULL) {
+ 						break;
+ 					}
+ 					
+-					while (pAttribute != NULL && pAttribute->group_tag == IPP_TAG_PRINTER) {
+-						if (strcmp(pAttribute->name, "printer-name") == 0 && pAttribute->value_tag == IPP_TAG_NAME) {
+-							pPrinter = pAttribute->values[0].string.text;
++					while (pAttribute != NULL && ippGetGroupTag(pAttribute) == IPP_TAG_PRINTER) {
++						if (strcmp(ippGetName(pAttribute), "printer-name") == 0 && ippGetValueTag(pAttribute) == IPP_TAG_NAME) {
++							pPrinter = ippGetString(pAttribute, 0, NULL);
+ 						}
+-						if (strcmp(pAttribute->name, "device-uri") == 0 && pAttribute->value_tag == IPP_TAG_URI) {
+-							pDUri = pAttribute->values[0].string.text;
++						if (strcmp(ippGetName(pAttribute), "device-uri") == 0 && ippGetValueTag(pAttribute) == IPP_TAG_URI) {
++							pDUri = ippGetString(pAttribute, 0, NULL);
+ 						}
+-						pAttribute = pAttribute->next;
++						pAttribute = ippNextAttribute(pResponse);
+ 					}
+ 
+ 					if (strcasecmp(pDestName, pPrinter) == 0) {
+@@ -362,7 +362,7 @@
+ 					}
+ 					
+ 					if (pAttribute != NULL)
+-						 pAttribute = pAttribute->next;
++						 pAttribute = ippNextAttribute(pResponse);
+ 				}
+ 			}
+ 			
diff --git a/nixpkgs/pkgs/misc/cups/drivers/cnijfilter_4_00/patches/cnijfilter-4.00-4-ppd.patch b/nixpkgs/pkgs/misc/cups/drivers/cnijfilter_4_00/patches/cnijfilter-4.00-4-ppd.patch
new file mode 100644
index 000000000000..92bef72ba056
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/cnijfilter_4_00/patches/cnijfilter-4.00-4-ppd.patch
@@ -0,0 +1,10 @@
+--- a/backend/src/cnij_backend_common.c	2016-11-13 00:08:34.600824006 +0100
++++ a/backend/src/cnij_backend_common.c	2016-11-13 00:08:52.037823694 +0100
+@@ -37,6 +37,7 @@
+ // CUPS Header
+ #include <cups/cups.h>
+ #include <cups/ipp.h>
++#include <cups/ppd.h>
+ 
+ // Header file for CANON
+ #include "cnij_backend_common.h"
diff --git a/nixpkgs/pkgs/misc/cups/drivers/cnijfilter_4_00/patches/cnijfilter-4.00-5-abi_x86_32.patch b/nixpkgs/pkgs/misc/cups/drivers/cnijfilter_4_00/patches/cnijfilter-4.00-5-abi_x86_32.patch
new file mode 100644
index 000000000000..dc85801a256b
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/cnijfilter_4_00/patches/cnijfilter-4.00-5-abi_x86_32.patch
@@ -0,0 +1,45 @@
+--- a/backendnet/configure.in	2014-08-11 08:38:46.034984462 +0200
++++ a/backendnet/configure.in	2014-08-11 08:35:42.902985813 +0200
+@@ -19,7 +19,11 @@
+ AC_DEFINE_UNQUOTED(BJLIB_PATH, "$enable_libpath")
+ AC_SUBST(BJLIB_PATH)
+ 
+-ARC=`getconf LONG_BIT`
++case "$ABI" in
++    x86) ARC=32;;
++    amd64) ARC=64;;
++    *) ARC=`getconf LONG_BIT`;;
++esac
+ AC_SUBST(ARC)
+ 
+ # Checks for programs.
+--- a/cnijfilter/configure.in	2014-08-11 08:39:44.426984031 +0200
++++ a/cnijfilter/configure.in	2014-08-11 08:35:19.788985984 +0200
+@@ -43,7 +43,11 @@
+ esac
+ AC_SUBST(CNCL_LIB_ID)
+ 
+-ARC=`getconf LONG_BIT`
++case "$ABI" in
++    x86) ARC=32;;
++    amd64) ARC=64;;
++    *) ARC=`getconf LONG_BIT`;;
++esac
+ AC_SUBST(ARC)
+ 
+ AC_PROG_CC
+--- a/cnijnpr/configure.in	2014-08-11 08:41:12.712983380 +0200
++++ a/cnijnpr/configure.in	2014-08-11 08:40:44.354983589 +0200
+@@ -37,7 +37,11 @@
+ 
+ CFLAGS="-O2"
+ 
+-ARC=`getconf LONG_BIT`
++case "$ABI" in
++    x86) ARC=32;;
++    amd64) ARC=64;;
++    *) ARC=`getconf LONG_BIT`;;
++esac
+ AC_SUBST(ARC)
+ 
+ AC_OUTPUT(Makefile
diff --git a/nixpkgs/pkgs/misc/cups/drivers/cnijfilter_4_00/patches/cnijfilter-4.00-6-headers.patch b/nixpkgs/pkgs/misc/cups/drivers/cnijfilter_4_00/patches/cnijfilter-4.00-6-headers.patch
new file mode 100644
index 000000000000..7dba79995114
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/cnijfilter_4_00/patches/cnijfilter-4.00-6-headers.patch
@@ -0,0 +1,11 @@
+--- a/cnijnpr/src/cnijnpr.c	2016-11-13 21:51:33.844977618 +0100
++++ a/cnijnpr/src/cnijnpr.c	2016-11-13 21:52:03.129977094 +0100
+@@ -34,6 +34,8 @@
+ #include <sys/ioctl.h>
+ #include <net/if.h>
+ #include <sys/sysctl.h>
++#include <sys/types.h>
++#include <unistd.h>
+ #include <config.h>
+ #include <fcntl.h>
+ 
diff --git a/nixpkgs/pkgs/misc/cups/drivers/cups-bjnp/default.nix b/nixpkgs/pkgs/misc/cups/drivers/cups-bjnp/default.nix
new file mode 100644
index 000000000000..40243bb91969
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/cups-bjnp/default.nix
@@ -0,0 +1,30 @@
+{lib, stdenv, fetchurl, cups}:
+
+stdenv.mkDerivation rec {
+  name = "cups-bjnp-1.2.2";
+
+  src = fetchurl {
+    url = "mirror://sourceforge/cups-bjnp/${name}.tar.gz";
+    sha256 = "0sb0vm1sf8ismzd9ba33qswxmsirj2z1b7lnyrc9v5ixm7q0bnrm";
+  };
+
+  preConfigure = ''configureFlags="--with-cupsbackenddir=$out/lib/cups/backend"'';
+
+  buildInputs = [cups];
+  NIX_CFLAGS_COMPILE = [
+    "-include stdio.h"
+    "-Wno-error=stringop-truncation"
+    "-Wno-error=deprecated-declarations"
+  ];
+
+  meta = {
+    description = "CUPS back-end for Canon printers";
+    longDescription = ''
+      CUPS back-end for the canon printers using the proprietary USB over IP
+      BJNP protocol. This back-end allows Cups to print over the network to a
+      Canon printer. The design is based on reverse engineering of the protocol.
+    '';
+    homepage = "http://cups-bjnp.sourceforge.net";
+    platforms = lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/cups/drivers/dymo/default.nix b/nixpkgs/pkgs/misc/cups/drivers/dymo/default.nix
new file mode 100644
index 000000000000..eccbae601043
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/dymo/default.nix
@@ -0,0 +1,28 @@
+{ stdenv, lib, fetchurl, cups, ... }:
+
+stdenv.mkDerivation rec {
+  pname = "cups-dymo";
+  version = "1.4.0.5";
+
+  # exposed version and 'real' version may differ
+  # in this case the download states '1.4.0' but the real version is '1.4.0.5'
+  # this has the potential to break future builds
+  dl-name = "dymo-cups-drivers-1.4.0";
+
+  src = fetchurl {
+    url = "http://download.dymo.com/dymo/Software/Download%20Drivers/Linux/Download/${dl-name}.tar.gz";
+    sha256 = "0wagsrz3q7yrkzb5ws0m5faq68rqnqfap9p98sgk5jl6x7krf1y6";
+  };
+
+  buildInputs = [ cups ];
+  patches = [ ./fix-includes.patch ];
+
+  makeFlags = [ "cupsfilterdir=$(out)/lib/cups/filter" "cupsmodeldir=$(out)/share/cups/model" ];
+
+  meta = {
+    description = "CUPS Linux drivers and SDK for DYMO printers";
+    homepage = "http://www.dymo.com/";
+    license = lib.licenses.gpl2;
+    maintainers = with lib.maintainers; [ makefu ];
+  };
+}
diff --git a/nixpkgs/pkgs/misc/cups/drivers/dymo/fix-includes.patch b/nixpkgs/pkgs/misc/cups/drivers/dymo/fix-includes.patch
new file mode 100644
index 000000000000..55f71369a001
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/dymo/fix-includes.patch
@@ -0,0 +1,80 @@
+diff -rp dymo-cups-drivers-1.4.0.5/src/common/CupsFilter.h dymo-cups-drivers-1.4.0.5-fix/src/common/CupsFilter.h
+*** dymo-cups-drivers-1.4.0.5/src/common/CupsFilter.h	2012-02-07 14:22:37.000000000 +0100
+--- dymo-cups-drivers-1.4.0.5-fix/src/common/CupsFilter.h	2017-03-27 23:10:17.638976126 +0200
+***************
+*** 22,29 ****
+--- 22,31 ----
+  #define hfc4bbdea_8a1b_427c_9ab5_50b84576b19e
+  
+  #include <cups/cups.h>
++ #include <cups/ppd.h>
+  #include <cups/raster.h>
+  #include <memory>
++ #include <stdio.h>
+  #include <string>
+  #include "CupsPrintEnvironment.h"
+  #include "ErrorDiffusionHalftoning.h"
+diff -rp dymo-cups-drivers-1.4.0.5/src/common/CupsPrintEnvironment.h dymo-cups-drivers-1.4.0.5-fix/src/common/CupsPrintEnvironment.h
+*** dymo-cups-drivers-1.4.0.5/src/common/CupsPrintEnvironment.h	2012-02-07 14:22:37.000000000 +0100
+--- dymo-cups-drivers-1.4.0.5-fix/src/common/CupsPrintEnvironment.h	2017-03-27 23:10:17.638976126 +0200
+***************
+*** 22,27 ****
+--- 22,28 ----
+  #define h952b1c81_8931_433a_8479_7ae6d8e85a86
+  
+  #include "PrinterDriver.h"
++ #include <stdio.h>
+  
+  namespace DymoPrinterDriver
+  {
+diff -rp dymo-cups-drivers-1.4.0.5/src/lm/CupsFilterLabelManager.h dymo-cups-drivers-1.4.0.5-fix/src/lm/CupsFilterLabelManager.h
+*** dymo-cups-drivers-1.4.0.5/src/lm/CupsFilterLabelManager.h	2012-02-07 14:22:38.000000000 +0100
+--- dymo-cups-drivers-1.4.0.5-fix/src/lm/CupsFilterLabelManager.h	2017-03-27 23:10:17.635976126 +0200
+***************
+*** 22,27 ****
+--- 22,28 ----
+  #define he780684b_6efc_428d_bfdb_c5422b1ed982
+  
+  #include <cups/cups.h>
++ #include <cups/ppd.h>
+  #include <cups/raster.h>
+  #include "LabelManagerDriver.h"
+  #include "LabelManagerLanguageMonitor.h"
+*************** public:
+*** 50,53 ****
+  
+  /*
+   * End of "$Id: CupsFilterLabelManager.h 14880 2011-03-31 16:29:05Z aleksandr $".
+!  */
+\ No newline at end of file
+--- 51,54 ----
+  
+  /*
+   * End of "$Id: CupsFilterLabelManager.h 14880 2011-03-31 16:29:05Z aleksandr $".
+!  */
+diff -rp dymo-cups-drivers-1.4.0.5/src/lw/CupsFilterLabelWriter.h dymo-cups-drivers-1.4.0.5-fix/src/lw/CupsFilterLabelWriter.h
+*** dymo-cups-drivers-1.4.0.5/src/lw/CupsFilterLabelWriter.h	2012-02-07 14:22:37.000000000 +0100
+--- dymo-cups-drivers-1.4.0.5-fix/src/lw/CupsFilterLabelWriter.h	2017-03-27 23:10:17.632976126 +0200
+***************
+*** 22,27 ****
+--- 22,28 ----
+  #define hd8574b83_b264_47b2_8d33_a46ae75691d2
+  
+  #include <cups/cups.h>
++ #include <cups/ppd.h>
+  #include <cups/raster.h>
+  #include "LabelWriterDriver.h"
+  #include "LabelWriterLanguageMonitor.h"
+diff -rp dymo-cups-drivers-1.4.0.5/src/common/CupsPrintEnvironment.cpp dymo-cups-drivers-1.4.0.5-fix/src/common/CupsPrintEnvironment.cpp
+*** dymo-cups-drivers-1.4.0.5/src/common/CupsPrintEnvironment.cpp	2019-12-16 19:37:23.429662838 +0000
+--- dymo-cups-drivers-1.4.0.5-fix/src/common/CupsPrintEnvironment.cpp	2019-12-16 19:41:48.506991614 +0000
+***************
+*** 23,28 ****
+--- 23,29 ----
+  #include "CupsPrintEnvironment.h"
+  #include <errno.h>
+  #include <cups/cups.h>
++ #include <cups/sidechannel.h>
+  #include <cassert>
+
+  namespace DymoPrinterDriver
diff --git a/nixpkgs/pkgs/misc/cups/drivers/estudio/default.nix b/nixpkgs/pkgs/misc/cups/drivers/estudio/default.nix
new file mode 100644
index 000000000000..37b39556d932
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/estudio/default.nix
@@ -0,0 +1,54 @@
+{ lib, stdenv, fetchurl, perl }:
+
+stdenv.mkDerivation {
+  pname = "cups-toshiba-estudio";
+  version = "7.89";
+
+  src = fetchurl {
+    url = "http://business.toshiba.com/downloads/KB/f1Ulds/15178/TOSHIBA_ColorMFP_CUPS.tar";
+    sha256 = "0qz4r7q55i0adf4fv3aqnfqgi2pz3jb1jixkqm9x6nk4vanyjf4r";
+  };
+
+  buildInputs = [ perl ];
+
+  phases = [ "unpackPhase"
+             "patchPhase"
+             "installPhase" ];
+
+  patchPhase = ''
+    patchShebangs lib/
+    gunzip                share/cups/model/Toshiba/TOSHIBA_ColorMFP_CUPS.gz
+    sed -i "s+/usr+$out+" share/cups/model/Toshiba/TOSHIBA_ColorMFP_CUPS
+    gzip                  share/cups/model/Toshiba/TOSHIBA_ColorMFP_CUPS
+  '';
+
+  installPhase = ''
+    mkdir -p $out/lib/cups/filter
+    mkdir -p $out/share/cups/model/Toshiba
+    cp {.,$out}/lib/cups/filter/est6550_Authentication
+    chmod 755 $out/lib/cups/filter/est6550_Authentication
+    cp {.,$out}/share/cups/model/Toshiba/TOSHIBA_ColorMFP_CUPS.gz
+    chmod 755 $out/share/cups/model/Toshiba/TOSHIBA_ColorMFP_CUPS.gz
+  '';
+
+  meta = with lib; {
+    description = "Printer only driver for the Toshiba e-STUDIO class of printers";
+    longDescription = ''
+      This driver supports the following printers: TOSHIBA e-STUDIO2000AC,
+      TOSHIBA e-STUDIO2005AC, TOSHIBA e-STUDIO2040C, TOSHIBA e-STUDIO2050C,
+      TOSHIBA e-STUDIO2055C, TOSHIBA e-STUDIO2500AC, TOSHIBA e-STUDIO2505AC,
+      TOSHIBA e-STUDIO2540C, TOSHIBA e-STUDIO2550C, TOSHIBA e-STUDIO2555C,
+      TOSHIBA e-STUDIO287CS, TOSHIBA e-STUDIO3005AC, TOSHIBA e-STUDIO3040C,
+      TOSHIBA e-STUDIO3055C, TOSHIBA e-STUDIO347CS, TOSHIBA e-STUDIO3505AC,
+      TOSHIBA e-STUDIO3540C, TOSHIBA e-STUDIO3555C, TOSHIBA e-STUDIO407CS,
+      TOSHIBA e-STUDIO4505AC, TOSHIBA e-STUDIO4540C, TOSHIBA e-STUDIO4555C,
+      TOSHIBA e-STUDIO5005AC, TOSHIBA e-STUDIO5055C, TOSHIBA e-STUDIO5506AC,
+      TOSHIBA e-STUDIO5540C, TOSHIBA e-STUDIO5560C, TOSHIBA e-STUDIO6506AC,
+      TOSHIBA e-STUDIO6540C, TOSHIBA e-STUDIO6550C, TOSHIBA e-STUDIO6560C,
+      TOSHIBA e-STUDIO6570C and TOSHIBA e-STUDIO7506AC.
+    '';
+    homepage = "http://business.toshiba.com/support/downloads/index.html";
+    license = licenses.unfree;
+    maintainers = [ maintainers.jpotier ];
+  };
+}
diff --git a/nixpkgs/pkgs/misc/cups/drivers/fxlinuxprint/default.nix b/nixpkgs/pkgs/misc/cups/drivers/fxlinuxprint/default.nix
new file mode 100644
index 000000000000..36134780e9bf
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/fxlinuxprint/default.nix
@@ -0,0 +1,51 @@
+{ stdenv, lib, fetchzip, dpkg, autoPatchelfHook, cups }:
+let
+  debPlatform =
+    if stdenv.hostPlatform.system == "x86_64-linux" then "amd64"
+    else if stdenv.hostPlatform.system == "i686-linux" then "i386"
+         else throw "Unsupported system: ${stdenv.hostPlatform.system}";
+in
+stdenv.mkDerivation rec {
+  pname = "fxlinuxprint";
+  version = "1.1.2-1";
+
+  src = fetchzip {
+    url = "https://onlinesupport.fujixerox.com/driver_downloads/fxlinuxpdf112119031.zip";
+    sha256 = "1mv07ch6ysk9bknfmjqsgxb803sj6vfin29s9knaqv17jvgyh0n3";
+    curlOpts = "--user-agent Mozilla/5.0";  # HTTP 410 otherwise
+  };
+
+  nativeBuildInputs = [ dpkg autoPatchelfHook ];
+  buildInputs = [ cups ];
+
+  sourceRoot = ".";
+  unpackCmd = "dpkg-deb -x $curSrc/fxlinuxprint_${version}_${debPlatform}.deb .";
+
+  dontConfigure = true;
+  dontBuild = true;
+
+  installPhase = ''
+    mkdir -p $out
+    mv etc $out
+    mv usr/lib $out
+
+    mkdir -p $out/share/cups/model
+    mv usr/share/ppd/FujiXerox/* $out/share/cups/model
+  '';
+
+  meta = with lib; {
+    description = "Fuji Xerox Linux Printer Driver";
+    longDescription = ''
+      DocuPrint P365/368 d
+      DocuPrint CM315/318 z
+      DocuPrint CP315/318 dw
+      ApeosPort-VI C2271/C3370/C3371/C4471/C5571/C6671/C7771
+      DocuCentre-VI C2271/C3370/C3371/C4471/C5571/C6671/C7771
+      DocuPrint 3205 d/3208 d/3505 d/3508 d/4405 d/4408 d
+    '';
+    homepage = "https://onlinesupport.fujixerox.com";
+    license = licenses.unfree;
+    maintainers = with maintainers; [ delan ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/cups/drivers/googlecloudprint/default.nix b/nixpkgs/pkgs/misc/cups/drivers/googlecloudprint/default.nix
new file mode 100644
index 000000000000..6503571eb6b6
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/googlecloudprint/default.nix
@@ -0,0 +1,64 @@
+{ stdenv, lib, fetchFromGitHub, python2, python2Packages, file, makeWrapper, cups }:
+
+# Setup instructions can be found at https://github.com/simoncadman/CUPS-Cloud-Print#configuration
+# So the nix version is something like:
+# nix run nixpkgs.cups-googlecloudprint -c sudo setupcloudprint
+# nix run nixpkgs.cups-googlecloudprint -c sudo listcloudprinters
+
+let pythonEnv = python2.buildEnv.override {
+  extraLibs = with python2Packages; [
+    six
+    httplib2
+    pycups
+  ];
+};
+
+in stdenv.mkDerivation rec {
+  pname = "cups-googlecloudprint";
+  version = "20160502";
+
+  src = fetchFromGitHub {
+    owner  = "simoncadman";
+    repo   = "CUPS-Cloud-Print";
+    rev    = version;
+    sha256 = "0760i12w7jrhq7fsgyz3yqla5cvpjb45n6m2jz96wsy3p3xf6dzz";
+  };
+
+  buildInputs = [ cups makeWrapper ];
+
+  cupsgroup = "nonexistantgroup";
+  NOPERMS = 1;
+
+  postConfigure = ''
+    substituteInPlace Makefile --replace "${cups}" "$out"
+  '';
+
+  postInstall = ''
+    pushd "$out"
+    for s in lib/cups/backend/gcp lib/cups/driver/cupscloudprint
+    do
+      echo "Wrapping $s..."
+      wrapProgram "$out/$s" --set PATH "${lib.makeBinPath [pythonEnv file]}" --prefix PYTHONPATH : "$out/share/cloudprint-cups"
+    done
+
+    mkdir bin
+
+    for s in share/cloudprint-cups/*.py
+    do
+      if [ -x "$s" ] # Only wrapping those Python scripts marked as executable
+      then
+        o="bin/$(echo $s | sed 's,share/cloudprint-cups/\(.*\).py,\1,')"
+        echo "Wrapping $o -> $s..."
+        makeWrapper "$out/$s" "$o" --set PATH "${lib.makeBinPath [pythonEnv file]}" --prefix PYTHONPATH : "$out/share/cloudprint-cups"
+      fi
+    done
+    popd
+  '';
+
+  meta = with lib; {
+    description = "Google Cloud Print driver for CUPS, allows printing to printers hosted on Google Cloud Print";
+    homepage    = "http://ccp.niftiestsoftware.com";
+    platforms   = platforms.linux;
+    license     = licenses.gpl3;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/cups/drivers/hl1110/default.nix b/nixpkgs/pkgs/misc/cups/drivers/hl1110/default.nix
new file mode 100644
index 000000000000..916ac32c2e9b
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/hl1110/default.nix
@@ -0,0 +1,73 @@
+{lib, stdenv, fetchurl, cups, dpkg, gnused, makeWrapper, ghostscript, file, a2ps, coreutils, gawk}:
+
+let
+  version = "3.0.1-1";
+cupsdeb = fetchurl {
+  url = "http://download.brother.com/welcome/dlf100421/hl1110cupswrapper-${version}.i386.deb";
+  sha256 = "a87880f4ece764a724411b5b24d15d1b912f6ffc6ecbfd9fac4cd5eda13d2eb7";
+};
+srcdir = "hl1110cupswrapper-GPL_src-${version}";
+cupssrc = fetchurl {
+  url = "http://download.brother.com/welcome/dlf100422/${srcdir}.tar.gz";
+  sha256 = "be1dce6a4608cb253b0b382db30bf5885da46b010e8eb595b15c435e2487761c";
+};
+lprdeb = fetchurl {
+  url = "http://download.brother.com/welcome/dlf100419/hl1110lpr-${version}.i386.deb";
+  sha256 = "5af241782a0d500d7f47e06ea43d61127f4019b5b1c6e68b4c1cb4521a742c22";
+};
+  in
+stdenv.mkDerivation {
+  name = "cups-brother-hl1110";
+
+  srcs = [ lprdeb cupssrc cupsdeb ];
+  nativeBuildInputs = [ makeWrapper ];
+  buildInputs = [ cups ghostscript dpkg a2ps ];
+  unpackPhase = ''
+    tar -xvf ${cupssrc}
+    '';
+  buildPhase = ''
+    gcc -Wall ${srcdir}/brcupsconfig/brcupsconfig.c -o brcupsconfig4
+    '';
+  installPhase = ''
+    # install lpr
+    dpkg-deb -x ${lprdeb} $out
+
+    substituteInPlace $out/opt/brother/Printers/HL1110/lpd/filter_HL1110 \
+    --replace /opt "$out/opt" \
+
+    sed -i '/GHOST_SCRIPT=/c\GHOST_SCRIPT=gs' $out/opt/brother/Printers/HL1110/lpd/psconvert2
+
+    patchelf --set-interpreter ${stdenv.glibc.out}/lib/ld-linux.so.2 $out/opt/brother/Printers/HL1110/lpd/brprintconflsr3
+    patchelf --set-interpreter ${stdenv.glibc.out}/lib/ld-linux.so.2 $out/opt/brother/Printers/HL1110/lpd/rawtobr3
+    patchelf --set-interpreter ${stdenv.glibc.out}/lib/ld-linux.so.2 $out/opt/brother/Printers/HL1110/inf/braddprinter
+
+    wrapProgram $out/opt/brother/Printers/HL1110/lpd/psconvert2 \
+    --prefix PATH ":" ${ lib.makeBinPath [ gnused coreutils gawk ] }
+
+    wrapProgram $out/opt/brother/Printers/HL1110/lpd/filter_HL1110 \
+    --prefix PATH ":" ${ lib.makeBinPath [ ghostscript a2ps file gnused coreutils ] }
+
+
+    dpkg-deb -x ${cupsdeb} $out
+
+    substituteInPlace $out/opt/brother/Printers/HL1110/cupswrapper/brother_lpdwrapper_HL1110 --replace /opt "$out/opt"
+
+    mkdir -p $out/lib/cups/filter
+    ln -s $out/opt/brother/Printers/HL1110/cupswrapper/brother_lpdwrapper_HL1110 $out/lib/cups/filter/brother_lpdwrapper_HL1110
+    ln -s $out/opt/brother/Printers/HL1110/cupswrapper/brother-HL1110-cups-en.ppd $out/lib/cups/filter/brother-HL1110-cups-en.ppd
+    cp brcupsconfig4 $out/opt/brother/Printers/HL1110/cupswrapper/
+    ln -s $out/opt/brother/Printers/HL1110/cupswrapper/brcupsconfig4 $out/lib/cups/filter/brcupsconfig4
+
+    wrapProgram $out/opt/brother/Printers/HL1110/cupswrapper/brother_lpdwrapper_HL1110 \
+    --prefix PATH ":" ${ lib.makeBinPath [ gnused coreutils gawk ] }
+
+    '';
+
+  meta = {
+    homepage = "http://www.brother.com/";
+    description = "Brother HL1110 printer driver";
+    license = lib.licenses.unfree;
+    platforms = lib.platforms.linux;
+    downloadPage = "http://support.brother.com/g/b/downloadlist.aspx?c=eu_ot&lang=en&prod=hl1110_us_eu_as&os=128#SelectLanguageType-561_0_1";
+  };
+}
diff --git a/nixpkgs/pkgs/misc/cups/drivers/hl1210w/default.nix b/nixpkgs/pkgs/misc/cups/drivers/hl1210w/default.nix
new file mode 100644
index 000000000000..975e07aa6c3f
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/hl1210w/default.nix
@@ -0,0 +1,62 @@
+{lib, stdenv, pkgsi686Linux, fetchurl, cups, dpkg, gnused, makeWrapper, ghostscript, file, a2ps, coreutils, gawk}:
+
+let
+  version = "3.0.1-1";
+  cupsdeb = fetchurl {
+    url = "https://download.brother.com/welcome/dlf101546/hl1210wcupswrapper-${version}.i386.deb";
+    sha256 = "0395mnw6c7qpjgjch9in5q9p2fjdqvz9bwfwp6q1hzhs08ryk7w0";
+  };
+  lprdeb = fetchurl {
+    url = "https://download.brother.com/welcome/dlf101547/hl1210wlpr-${version}.i386.deb";
+    sha256 = "1sl3g2cd4a2gygryrr27ax3qaa65cbirz3kzskd8afkwqpmjyv7j";
+  };
+in
+stdenv.mkDerivation {
+  name = "cups-brother-hl1210W";
+
+  srcs = [ lprdeb cupsdeb ];
+  nativeBuildInputs = [ makeWrapper ];
+  buildInputs = [ cups ghostscript dpkg a2ps ];
+  dontUnpack = true;
+
+  installPhase = ''
+    # install lpr
+    dpkg-deb -x ${lprdeb} $out
+
+    substituteInPlace $out/opt/brother/Printers/HL1210W/lpd/filter_HL1210W \
+      --replace /opt "$out/opt"
+
+    sed -i '/GHOST_SCRIPT=/c\GHOST_SCRIPT=gs' $out/opt/brother/Printers/HL1210W/lpd/psconvert2
+
+    patchelf --set-interpreter ${pkgsi686Linux.glibc.out}/lib/ld-linux.so.2 $out/opt/brother/Printers/HL1210W/lpd/brprintconflsr3
+    patchelf --set-interpreter ${pkgsi686Linux.glibc.out}/lib/ld-linux.so.2 $out/opt/brother/Printers/HL1210W/lpd/rawtobr3
+    patchelf --set-interpreter ${pkgsi686Linux.glibc.out}/lib/ld-linux.so.2 $out/opt/brother/Printers/HL1210W/inf/braddprinter
+
+    wrapProgram $out/opt/brother/Printers/HL1210W/lpd/psconvert2 \
+      --prefix PATH ":" ${ lib.makeBinPath [ gnused coreutils gawk ] }
+    wrapProgram $out/opt/brother/Printers/HL1210W/lpd/filter_HL1210W \
+      --prefix PATH ":" ${ lib.makeBinPath [ ghostscript a2ps file gnused coreutils ] }
+
+    # install cups
+    dpkg-deb -x ${cupsdeb} $out
+
+    substituteInPlace $out/opt/brother/Printers/HL1210W/cupswrapper/brother_lpdwrapper_HL1210W --replace /opt "$out/opt"
+
+    mkdir -p $out/lib/cups/filter
+    ln -s $out/opt/brother/Printers/HL1210W/cupswrapper/brother_lpdwrapper_HL1210W $out/lib/cups/filter/brother_lpdwrapper_HL1210W
+    ln -s $out/opt/brother/Printers/HL1210W/cupswrapper/brother-HL1210W-cups-en.ppd $out/lib/cups/filter/brother-HL1210W-cups-en.ppd
+    # cp brcupsconfig4 $out/opt/brother/Printers/HL1110/cupswrapper/
+    ln -s $out/opt/brother/Printers/HL1210W/cupswrapper/brcupsconfig4 $out/lib/cups/filter/brcupsconfig4
+
+    wrapProgram $out/opt/brother/Printers/HL1210W/cupswrapper/brother_lpdwrapper_HL1210W \
+      --prefix PATH ":" ${ lib.makeBinPath [ gnused coreutils gawk ] }
+    '';
+
+  meta = {
+    homepage = "http://www.brother.com/";
+    description = "Brother HL1210W printer driver";
+    license = lib.licenses.unfree;
+    platforms = lib.platforms.linux;
+    downloadPage = "https://support.brother.com/g/b/downloadlist.aspx?c=nz&lang=en&prod=hl1210w_eu_as&os=128";
+  };
+}
diff --git a/nixpkgs/pkgs/misc/cups/drivers/hl3140cw/default.nix b/nixpkgs/pkgs/misc/cups/drivers/hl3140cw/default.nix
new file mode 100644
index 000000000000..255fae09c7a7
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/hl3140cw/default.nix
@@ -0,0 +1,78 @@
+{lib, stdenv, fetchurl, cups, dpkg, gnused, makeWrapper, ghostscript, file, a2ps, coreutils, gawk}:
+
+let
+  version = "1.1.4-0";
+  cupsdeb = fetchurl {
+    url = "https://download.brother.com/welcome/dlf007070/hl3140cwcupswrapper-${version}.i386.deb";
+    sha256 = "a76281828ca6ee86c63034673577fadcf5f24e8ed003213bdbb6bf47a7aced6f";
+  };
+  srcdir = "hl3140cw_cupswrapper_GPL_source_${version}";
+  cupssrc = fetchurl {
+    url = "https://download.brother.com/welcome/dlf006740/${srcdir}.tar.gz";
+    sha256 = "1wp85rbvbar6rqqkaffymxjpls6jx9m9230dlrpqwy5akiaxf0rl";
+  };
+  lprdeb = fetchurl {
+    url = "https://support.brother.com/g/b/files/dlf/dlf007068/hl3140cwlpr-1.1.2-1.i386.deb";
+    sha256 = "601f392b52ed7080f71b780181823bb8f6abfd0591146b452ba1f23e21f9f865";
+  };
+in
+stdenv.mkDerivation {
+  name = "cups-brother-hl3140cw";
+  nativeBuildInputs = [ makeWrapper dpkg ];
+  buildInputs = [ cups ghostscript a2ps ];
+
+  unpackPhase = ''
+    tar -xvf ${cupssrc}
+  '';
+
+  buildPhase = ''
+    gcc -Wall ${srcdir}/brcupsconfig/brcupsconfig.c -o brcupsconfpt1
+  '';
+
+  installPhase = ''
+    # install lpr
+    dpkg-deb -x ${lprdeb} $out
+
+    substituteInPlace $out/opt/brother/Printers/hl3140cw/lpd/filterhl3140cw \
+      --replace /opt "$out/opt"
+    substituteInPlace $out/opt/brother/Printers/hl3140cw/inf/setupPrintcapij \
+      --replace /opt "$out/opt"
+
+    sed -i '/GHOST_SCRIPT=/c\GHOST_SCRIPT=gs' $out/opt/brother/Printers/hl3140cw/lpd/psconvertij2
+
+    patchelf --set-interpreter ${stdenv.glibc.out}/lib/ld-linux.so.2 $out/opt/brother/Printers/hl3140cw/lpd/brhl3140cwfilter
+    patchelf --set-interpreter ${stdenv.glibc.out}/lib/ld-linux.so.2 $out/usr/bin/brprintconf_hl3140cw
+
+    wrapProgram $out/opt/brother/Printers/hl3140cw/lpd/psconvertij2 \
+      --prefix PATH ":" ${ lib.makeBinPath [ gnused coreutils gawk ] }
+
+    wrapProgram $out/opt/brother/Printers/hl3140cw/lpd/filterhl3140cw \
+      --prefix PATH ":" ${ lib.makeBinPath [ ghostscript a2ps file gnused coreutils ] }
+
+
+    dpkg-deb -x ${cupsdeb} $out
+
+    substituteInPlace $out/opt/brother/Printers/hl3140cw/cupswrapper/cupswrapperhl3140cw \
+      --replace /opt "$out/opt"
+
+    mkdir -p $out/lib/cups/filter
+    ln -s $out/opt/brother/Printers/hl3140cw/cupswrapper/cupswrapperhl3140cw $out/lib/cups/filter/cupswrapperhl3140cw
+
+    ln -s $out/opt/brother/Printers/hl3140cw/cupswrapper/brother_hl3140cw_printer_en.ppd $out/lib/cups/filter/brother_hl3140cw_printer_en.ppd
+
+    cp brcupsconfpt1 $out/opt/brother/Printers/hl3140cw/cupswrapper/
+    ln -s $out/opt/brother/Printers/hl3140cw/cupswrapper/brcupsconfpt1 $out/lib/cups/filter/brcupsconfpt1
+    ln -s $out/opt/brother/Printers/hl3140cw/lpd/filterhl3140cw $out/lib/cups/filter/brother_lpdwrapper_hl3140cw
+
+    wrapProgram $out/opt/brother/Printers/hl3140cw/cupswrapper/cupswrapperhl3140cw \
+      --prefix PATH ":" ${ lib.makeBinPath [ gnused coreutils gawk ] }
+  '';
+
+  meta = {
+    homepage = "http://www.brother.com/";
+    description = "Brother hl3140cw printer driver";
+    license = lib.licenses.unfree;
+    platforms = lib.platforms.linux;
+    downloadPage = "https://support.brother.com/g/b/downloadlist.aspx?c=eu_ot&lang=en&prod=hl3140cw_us_eu&os=128";
+  };
+}
diff --git a/nixpkgs/pkgs/misc/cups/drivers/hll2340dw/default.nix b/nixpkgs/pkgs/misc/cups/drivers/hll2340dw/default.nix
new file mode 100644
index 000000000000..35d81b3da006
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/hll2340dw/default.nix
@@ -0,0 +1,68 @@
+{lib, stdenv, fetchurl, cups, dpkg, gnused, makeWrapper, ghostscript, file, a2ps, coreutils, gawk, perl, gnugrep, which}:
+
+let
+  version = "3.2.0-1";
+  lprdeb = fetchurl {
+    url = "https://download.brother.com/welcome/dlf101912/hll2340dlpr-${version}.i386.deb";
+    sha256 = "c0ae98b49b462cd8fbef445550f2177ce9d8bf627c904e182daa8cbaf8781e50";
+  };
+
+  cupsdeb = fetchurl {
+    url = "https://download.brother.com/welcome/dlf101913/hll2340dcupswrapper-${version}.i386.deb";
+    sha256 = "8aa24a6a825e3a4d5b51778cb46fe63032ec5a731ace22f9ef2b0ffcc2033cc9";
+  };
+
+in
+stdenv.mkDerivation {
+  name = "cups-brother-hll2340dw";
+
+  nativeBuildInputs = [ makeWrapper ];
+  buildInputs = [ cups ghostscript dpkg a2ps ];
+
+  dontUnpack = true;
+
+  installPhase = ''
+    mkdir -p $out
+    dpkg-deb -x ${cupsdeb} $out
+    dpkg-deb -x ${lprdeb} $out
+
+    substituteInPlace $out/opt/brother/Printers/HLL2340D/lpd/filter_HLL2340D \
+      --replace /opt "$out/opt" \
+      --replace /usr/bin/perl ${perl}/bin/perl \
+      --replace "BR_PRT_PATH =~" "BR_PRT_PATH = \"$out/opt/brother/Printers/HLL2340D/\"; #" \
+      --replace "PRINTER =~" "PRINTER = \"HLL2340D\"; #"
+
+    patchelf --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
+      $out/opt/brother/Printers/HLL2340D/lpd/brprintconflsr3
+    patchelf --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
+      $out/opt/brother/Printers/HLL2340D/lpd/rawtobr3
+
+    for f in \
+      $out/opt/brother/Printers/HLL2340D/cupswrapper/brother_lpdwrapper_HLL2340D \
+      $out/opt/brother/Printers/HLL2340D/cupswrapper/paperconfigml1 \
+    ; do
+      wrapProgram $f \
+        --prefix PATH : ${lib.makeBinPath [
+          coreutils ghostscript gnugrep gnused
+        ]}
+    done
+
+    mkdir -p $out/lib/cups/filter/
+    ln -s $out/opt/brother/Printers/HLL2340D/lpd/filter_HLL2340D $out/lib/cups/filter/brother_lpdwrapper_HLL2340D
+
+    mkdir -p $out/share/cups/model
+    ln -s $out/opt/brother/Printers/HLL2340D/cupswrapper/brother-HLL2340D-cups-en.ppd $out/share/cups/model/
+
+    wrapProgram $out/opt/brother/Printers/HLL2340D/lpd/filter_HLL2340D \
+      --prefix PATH ":" ${ lib.makeBinPath [ ghostscript a2ps file gnused gnugrep coreutils which ] }
+    '';
+
+  meta = with lib; {
+    homepage = "http://www.brother.com/";
+    description = "Brother hl-l2340dw printer driver";
+    license = licenses.unfree;
+    platforms = platforms.linux;
+    downloadPage = "https://support.brother.com/g/b/downloadlist.aspx?c=us&lang=es&prod=hll2340dw_us_eu_as&os=128&flang=English";
+    maintainers = [ maintainers.qknight ];
+  };
+}
diff --git a/nixpkgs/pkgs/misc/cups/drivers/hll2390dw-cups/default.nix b/nixpkgs/pkgs/misc/cups/drivers/hll2390dw-cups/default.nix
new file mode 100644
index 000000000000..04087c765e68
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/hll2390dw-cups/default.nix
@@ -0,0 +1,71 @@
+{ lib, stdenv, fetchurl, makeWrapper
+, cups
+, dpkg
+, a2ps, ghostscript, gnugrep, gnused, coreutils, file, perl, which
+}:
+
+stdenv.mkDerivation rec {
+  pname = "hll2390dw-cups";
+  version = "4.0.0-1";
+
+  src = fetchurl {
+    # The i386 part is a lie. There are x86, x86_64 and armv7l drivers.
+    # Though this builds only supports x86_64 for now.
+    url = "https://download.brother.com/welcome/dlf103579/hll2390dwpdrv-${version}.i386.deb";
+    sha256 = "0w8rxh1sa5amxr87qmzs4m2p06b1b36wn2q127mg427sbkh1rwni";
+  };
+
+  nativeBuildInputs = [ makeWrapper ];
+  buildInputs = [ cups ghostscript dpkg a2ps ];
+
+  dontUnpack = true;
+
+  installPhase = ''
+    dpkg-deb -x $src $out
+
+    substituteInPlace $out/opt/brother/Printers/HLL2390DW/lpd/lpdfilter \
+      --replace /opt "$out/opt" \
+      --replace /usr/bin/perl ${perl}/bin/perl \
+      --replace "BR_PRT_PATH =~" "BR_PRT_PATH = \"$out\"; #" \
+      --replace "PRINTER =~" "PRINTER = \"HLL2390DW\"; #"
+
+    # FIXME : Allow i686 and armv7l variations to be setup instead.
+    _PLAT=x86_64
+    patchelf --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
+      $out/opt/brother/Printers/HLL2390DW/lpd/$_PLAT/brprintconflsr3
+    patchelf --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
+      $out/opt/brother/Printers/HLL2390DW/lpd/$_PLAT/rawtobr3
+    ln -s $out/opt/brother/Printers/HLL2390DW/lpd/$_PLAT/brprintconflsr3 $out/opt/brother/Printers/HLL2390DW/lpd/brprintconflsr3
+    ln -s $out/opt/brother/Printers/HLL2390DW/lpd/$_PLAT/rawtobr3 $out/opt/brother/Printers/HLL2390DW/lpd/rawtobr3
+
+    for f in \
+      $out/opt/brother/Printers/HLL2390DW/cupswrapper/lpdwrapper \
+      $out/opt/brother/Printers/HLL2390DW/cupswrapper/paperconfigml2 \
+    ; do
+      #substituteInPlace $f \
+      wrapProgram $f \
+        --prefix PATH : ${lib.makeBinPath [
+          coreutils ghostscript gnugrep gnused
+        ]}
+    done
+
+    mkdir -p $out/lib/cups/filter/
+    ln -s $out/opt/brother/Printers/HLL2390DW/lpd/lpdfilter $out/lib/cups/filter/brother_lpdwrapper_HLL2390DW
+
+    mkdir -p $out/share/cups/model
+    ln -s $out/opt/brother/Printers/HLL2390DW/cupswrapper/brother-HLL2390DW-cups-en.ppd $out/share/cups/model/
+
+    wrapProgram $out/opt/brother/Printers/HLL2390DW/lpd/lpdfilter \
+      --prefix PATH ":" ${ lib.makeBinPath [ ghostscript a2ps file gnused gnugrep coreutils which ] }
+    '';
+
+  meta = with lib; {
+    homepage = "http://www.brother.com/";
+    description = "Brother HL-L2390DW combined print driver";
+    license = licenses.unfree;
+    platforms = [ "x86_64-linux" ];
+    downloadPage = "http://support.brother.com/g/b/downloadlist.aspx?c=us_ot&lang=en&prod=hll2390dw_us&os=128";
+    maintainers = [ maintainers.samueldr ];
+  };
+}
+
diff --git a/nixpkgs/pkgs/misc/cups/drivers/kyocera/default.nix b/nixpkgs/pkgs/misc/cups/drivers/kyocera/default.nix
new file mode 100644
index 000000000000..cd4c049e67f7
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/kyocera/default.nix
@@ -0,0 +1,50 @@
+{ stdenv, lib, fetchzip, cups }:
+
+let
+  platform =
+    if stdenv.hostPlatform.system == "x86_64-linux" then "64bit"
+    else if stdenv.hostPlatform.system == "i686-linux" then "32bit"
+         else throw "Unsupported system: ${stdenv.hostPlatform.system}";
+
+  libPath = lib.makeLibraryPath [ cups ];
+in
+
+stdenv.mkDerivation {
+  pname = "cups-kyocera";
+  version = "1.1203";
+
+  dontPatchELF = true;
+  dontStrip = true;
+
+  src = fetchzip {
+    # this site does not like curl -> override useragent
+    curlOpts = "-A ''";
+    url = "https://cdn.kyostatics.net/dlc/ru/driver/all/linuxdrv_1_1203_fs-1x2xmfp.-downloadcenteritem-Single-File.downloadcenteritem.tmp/LinuxDrv_1.1203_FS-1x2xMFP.zip";
+    sha256 = "0z1pbgidkibv4j21z0ys8cq1lafc6687syqa07qij2qd8zp15wiz";
+  };
+
+  installPhase = ''
+    tar -xvf ${platform}/Global/English.tar.gz
+    install -Dm755 English/rastertokpsl $out/lib/cups/filter/rastertokpsl
+    patchelf \
+      --set-rpath ${libPath} \
+      --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
+      $out/lib/cups/filter/rastertokpsl
+
+    mkdir -p $out/share/cups/model/Kyocera
+    cd English
+    for i in *.ppd; do
+      sed -i $i -e \
+        "s,/usr/lib/cups/filter/rastertokpsl,$out/lib/cups/filter/rastertokpsl,g"
+      cp $i $out/share/cups/model/Kyocera
+    done;
+  '';
+
+  meta = with lib; {
+    description = "CUPS drivers for several Kyocera FS-{1020,1025,1040,1060,1120,1125} printers";
+    homepage = "https://www.kyoceradocumentsolutions.ru/index/service_support/download_center.false.driver.FS1040._.EN.html#";
+    license = licenses.unfree;
+    maintainers = [ maintainers.vanzef ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/cups/drivers/kyodialog3/default.nix b/nixpkgs/pkgs/misc/cups/drivers/kyodialog3/default.nix
new file mode 100644
index 000000000000..7e0a0dea67d1
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/kyodialog3/default.nix
@@ -0,0 +1,61 @@
+{ stdenv, lib, fetchzip, cups, autoPatchelfHook
+
+  # Can either be "EU" or "Global"; it's unclear what the difference is
+  , region ? "Global", qt4
+}:
+
+let
+  platform =
+    if stdenv.hostPlatform.system == "x86_64-linux" then "64bit"
+    else if stdenv.hostPlatform.system == "i686-linux" then "32bit"
+         else throw "Unsupported system: ${stdenv.hostPlatform.system}";
+  debPlatform =
+    if platform == "64bit" then "amd64"
+    else "i386";
+  debRegion = if region == "EU" then "EU." else "";
+in
+stdenv.mkDerivation rec {
+  pname = "cups-kyodialog3";
+  version = "8.1601";
+
+  dontStrip = true;
+
+  src = fetchzip {
+    url = "https://la.kyoceradocumentsolutions.com/content/dam/kdc/kdag/downloads/technical/executables/drivers/kyoceradocumentsolutions/lad/en/Kyocera_Linux_PPD_Ver_${version}.tar.gz";
+    sha256 = "11znnlkfssakml7w80gxlz1k59f3nvhph91fkzzadnm9i7a8yjal";
+  };
+
+  nativeBuildInputs = [ autoPatchelfHook ];
+
+  buildInputs = [ cups qt4 ];
+
+  installPhase = ''
+    mkdir -p $out
+    cd $out
+
+    # unpack the debian archive
+    ar p ${src}/KyoceraLinuxPackages/${region}/${platform}/kyodialog3.en${debRegion}_0.5-0_${debPlatform}.deb data.tar.gz | tar -xz
+    rm -Rf KyoceraLinuxPackages
+
+    # strip $out/usr
+    mv usr/* .
+    rmdir usr
+
+    # allow cups to find the ppd files
+    mkdir -p share/cups/model
+    mv share/ppd/kyocera share/cups/model/Kyocera
+    rmdir share/ppd
+
+    # prepend $out to all references in ppd and desktop files
+    find -name "*.ppd" -exec sed -E -i "s:/usr/lib:$out/lib:g" {} \;
+    find -name "*.desktop" -exec sed -E -i "s:/usr/lib:$out/lib:g" {} \;
+  '';
+
+  meta = with lib; {
+    description = "CUPS drivers for several Kyocera printers";
+    homepage = "https://www.kyoceradocumentsolutions.com";
+    license = licenses.unfree;
+    maintainers = [ maintainers.steveej ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/cups/drivers/mfcj470dwcupswrapper/default.nix b/nixpkgs/pkgs/misc/cups/drivers/mfcj470dwcupswrapper/default.nix
new file mode 100644
index 000000000000..2ff073591d05
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/mfcj470dwcupswrapper/default.nix
@@ -0,0 +1,56 @@
+{ lib, stdenv, fetchurl, mfcj470dwlpr, makeWrapper}:
+
+stdenv.mkDerivation rec {
+  pname = "mfcj470dw-cupswrapper";
+  version = "3.0.0-1";
+
+  src = fetchurl {
+    url = "https://download.brother.com/welcome/dlf006866/mfcj470dw_cupswrapper_GPL_source_${version}.tar.gz";
+    sha256 = "b88f9b592723a00c024129560367f40a560ca3cba06fd99512ab368dd6855853";
+  };
+
+  nativeBuildInputs = [ makeWrapper ];
+  buildInputs = [ mfcj470dwlpr ];
+
+  patchPhase = ''
+    WRAPPER=cupswrapper/cupswrappermfcj470dw
+
+    substituteInPlace $WRAPPER \
+    --replace /opt "${mfcj470dwlpr}/opt" \
+    --replace /usr "${mfcj470dwlpr}/usr" \
+    --replace /etc "$out/etc"
+
+    substituteInPlace $WRAPPER \
+    --replace "\`cp " "\`cp -p " \
+    --replace "\`mv " "\`cp -p "
+    '';
+
+  buildPhase = ''
+    cd brcupsconfpt1
+    make all
+    cd ..
+    '';
+
+  installPhase = ''
+    TARGETFOLDER=$out/opt/brother/Printers/mfcj470dw/cupswrapper/
+    mkdir -p $out/opt/brother/Printers/mfcj470dw/cupswrapper/
+
+    cp brcupsconfpt1/brcupsconfpt1 $TARGETFOLDER
+    cp cupswrapper/cupswrappermfcj470dw $TARGETFOLDER/
+    cp PPD/brother_mfcj470dw_printer_en.ppd $TARGETFOLDER/
+    '';
+
+  cleanPhase = ''
+    cd brcupsconfpt1
+    make clean
+    '';
+
+  meta = {
+    homepage = "http://www.brother.com/";
+    description = "Brother MFC-J470DW CUPS wrapper driver";
+    license = lib.licenses.gpl2;
+    platforms = lib.platforms.linux;
+    downloadPage = "http://support.brother.com/g/b/downloadlist.aspx?c=us&lang=en&prod=mfcj470dw_us_eu_as&os=128";
+    maintainers = [ lib.maintainers.yochai ];
+  };
+}
diff --git a/nixpkgs/pkgs/misc/cups/drivers/mfcj470dwlpr/default.nix b/nixpkgs/pkgs/misc/cups/drivers/mfcj470dwlpr/default.nix
new file mode 100644
index 000000000000..b2dbd0ca77ab
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/mfcj470dwlpr/default.nix
@@ -0,0 +1,45 @@
+{ lib, stdenv, fetchurl, cups, dpkg, ghostscript, a2ps, coreutils, gnused, gawk, file, makeWrapper }:
+
+stdenv.mkDerivation rec {
+  pname = "mfcj470dw-cupswrapper";
+  version = "3.0.0-1";
+
+  src = fetchurl {
+    url = "https://download.brother.com/welcome/dlf006843/mfcj470dwlpr-${version}.i386.deb";
+    sha256 = "7202dd895d38d50bb767080f2995ed350eed99bc2b7871452c3c915c8eefc30a";
+  };
+
+  nativeBuildInputs = [ makeWrapper ];
+  buildInputs = [ cups ghostscript dpkg a2ps ];
+
+  dontUnpack = true;
+
+  installPhase = ''
+    dpkg-deb -x $src $out
+
+    substituteInPlace $out/opt/brother/Printers/mfcj470dw/lpd/filtermfcj470dw \
+    --replace /opt "$out/opt" \
+
+    sed -i '/GHOST_SCRIPT=/c\GHOST_SCRIPT=gs' $out/opt/brother/Printers/mfcj470dw/lpd/psconvertij2
+
+    patchelf --set-interpreter ${stdenv.glibc.out}/lib/ld-linux.so.2 $out/opt/brother/Printers/mfcj470dw/lpd/brmfcj470dwfilter
+
+    mkdir -p $out/lib/cups/filter/
+    ln -s $out/opt/brother/Printers/mfcj470dw/lpd/filtermfcj470dw $out/lib/cups/filter/brother_lpdwrapper_mfcj470dw
+
+    wrapProgram $out/opt/brother/Printers/mfcj470dw/lpd/psconvertij2 \
+    --prefix PATH ":" ${ lib.makeBinPath [ gnused coreutils gawk ] }
+
+    wrapProgram $out/opt/brother/Printers/mfcj470dw/lpd/filtermfcj470dw \
+    --prefix PATH ":" ${ lib.makeBinPath [ ghostscript a2ps file gnused coreutils ] }
+    '';
+
+  meta = {
+    homepage = "http://www.brother.com/";
+    description = "Brother MFC-J470DW LPR driver";
+    license = lib.licenses.unfree;
+    platforms = lib.platforms.linux;
+    downloadPage = "http://support.brother.com/g/b/downloadlist.aspx?c=us&lang=en&prod=mfcj470dw_us_eu_as&os=128";
+    maintainers = [ lib.maintainers.yochai ];
+  };
+}
diff --git a/nixpkgs/pkgs/misc/cups/drivers/mfcj6510dwcupswrapper/default.nix b/nixpkgs/pkgs/misc/cups/drivers/mfcj6510dwcupswrapper/default.nix
new file mode 100644
index 000000000000..1653ced85c5a
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/mfcj6510dwcupswrapper/default.nix
@@ -0,0 +1,65 @@
+{ lib, stdenv, fetchurl, mfcj6510dwlpr, makeWrapper}:
+
+stdenv.mkDerivation rec {
+  pname = "mfcj6510dw-cupswrapper";
+  version = "3.0.0-1";
+
+  src = fetchurl {
+    url = "https://download.brother.com/welcome/dlf006814/mfcj6510dw_cupswrapper_GPL_source_${version}.tar.gz";
+    sha256 = "0y5iffybxjin8injrdmc9n9hl4s6b8n6ck76m1z78bzi88vwmhai";
+  };
+
+  nativeBuildInputs = [ makeWrapper ];
+  buildInputs = [ mfcj6510dwlpr ];
+
+  buildPhase = ''
+    cd brcupsconfig
+    make all
+    cd ..
+    '';
+
+  installPhase = ''
+    TARGETFOLDER=$out/opt/brother/Printers/mfcj6510dw/cupswrapper
+    mkdir -p $TARGETFOLDER
+    cp PPD/brother_mfcj6510dw_printer_en.ppd $TARGETFOLDER
+    cp brcupsconfig/brcupsconfpt1 $TARGETFOLDER
+    cp scripts/cupswrappermfcj6510dw $TARGETFOLDER
+    sed -i -e '26,304d' $TARGETFOLDER/cupswrappermfcj6510dw
+    substituteInPlace $TARGETFOLDER/cupswrappermfcj6510dw \
+      --replace "\$ppd_file_name" "$TARGETFOLDER/brother_mfcj6510dw_printer_en.ppd"
+
+    CPUSFILTERFOLDER=$out/lib/cups/filter
+    mkdir -p $TARGETFOLDER $CPUSFILTERFOLDER
+    ln -s ${mfcj6510dwlpr}/lib/cups/filter/brother_lpdwrapper_mfcj6510dw $out/lib/cups/filter/brother_lpdwrapper_mfcj6510dw
+    ##TODO: Use the cups filter instead of the LPR one.
+    #cp scripts/cupswrappermfcj6510dw $CPUSFILTERFOLDER/brother_lpdwrapper_mfcj6510dw
+    #sed -i -e '110,258!d' $CPUSFILTERFOLDER/brother_lpdwrapper_mfcj6510dw
+    #sed -i -e '33,40d' $CPUSFILTERFOLDER/brother_lpdwrapper_mfcj6510dw
+    #sed -i -e '34,35d' $CPUSFILTERFOLDER/brother_lpdwrapper_mfcj6510dw
+    #substituteInPlace $CPUSFILTERFOLDER/brother_lpdwrapper_mfcj6510dw \
+    #  --replace "/opt/brother/$``{device_model``}/$``{printer_model``}/lpd/filter$``{printer_model``}" \
+    #    "${mfcj6510dwlpr}/opt/brother/Printers/mfcj6510dw/lpd/filtermfcj6510dw" \
+    #  --replace "/opt/brother/Printers/$``{printer_model``}/inf/br$``{printer_model``}rc" \
+    #    "${mfcj6510dwlpr}/opt/brother/Printers/mfcj6510dw/inf/brmfcj6510dwrc" \
+    #  --replace "/opt/brother/$``{device_model``}/$``{printer_model``}/cupswrapper/brcupsconfpt1" \
+    #    "$out/opt/brother/Printers/mfcj6510dw/cupswrapper/brcupsconfpt1" \
+    #  --replace "/usr/share/cups/model/Brother/brother_" "$out/opt/brother/Printers/mfcj6510dw/cupswrapper/brother_"
+    #substituteInPlace $CPUSFILTERFOLDER/brother_lpdwrapper_mfcj6510dw \
+    #  --replace "$``{printer_model``}" "mfcj6510dw" \
+    #  --replace "$``{printer_name``}" "MFCJ6510DW"
+    '';
+
+  cleanPhase = ''
+    cd brcupsconfpt1
+    make clean
+    '';
+
+  meta = with lib; {
+    homepage = "http://www.brother.com/";
+    description = "Brother MFC-J6510DW CUPS wrapper driver";
+    license = with licenses; gpl2;
+    platforms = with platforms; linux;
+    downloadPage = "http://support.brother.com/g/b/downloadlist.aspx?c=us&lang=en&prod=mfcj6510dw_all&os=128";
+    maintainers = with maintainers; [ ramkromberg ];
+  };
+}
diff --git a/nixpkgs/pkgs/misc/cups/drivers/mfcj6510dwlpr/default.nix b/nixpkgs/pkgs/misc/cups/drivers/mfcj6510dwlpr/default.nix
new file mode 100644
index 000000000000..741abc74f26a
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/mfcj6510dwlpr/default.nix
@@ -0,0 +1,89 @@
+{ lib, stdenv, fetchurl, pkgsi686Linux, dpkg, makeWrapper, coreutils, gnused, gawk, file, cups, util-linux, xxd, runtimeShell
+, ghostscript, a2ps }:
+
+# Why:
+# The executable "brprintconf_mfcj6510dw" binary is looking for "/opt/brother/Printers/%s/inf/br%sfunc" and "/opt/brother/Printers/%s/inf/br%src".
+# Whereby, %s is printf(3) string substitution for stdin's arg0 (the command's own filename) from the 10th char forwards, as a runtime dependency.
+# e.g. Say the filename is "0123456789ABCDE", the runtime will be looking for /opt/brother/Printers/ABCDE/inf/brABCDEfunc.
+# Presumably, the binary was designed to be deployed under the filename "printconf_mfcj6510dw", whereby it will search for "/opt/brother/Printers/mfcj6510dw/inf/brmfcj6510dwfunc".
+# For NixOS, we want to change the string to the store path of brmfcj6510dwfunc and brmfcj6510dwrc but we're faced with two complications:
+# 1. Too little room to specify the nix store path. We can't even take advantage of %s by renaming the file to the store path hash since the variable is too short and can't contain the whole hash.
+# 2. The binary needs the directory it's running from to be r/w.
+# What:
+# As such, we strip the path and substitution altogether, leaving only "brmfcj6510dwfunc" and "brmfcj6510dwrc", while filling the leftovers with nulls.
+# Fully null terminating the cstrings is necessary to keep the array the same size and preventing overflows.
+# We then use a shell script to link and execute the binary, func and rc files in a temporary directory.
+# How:
+# In the package, we dump the raw binary as a string of search-able hex values using hexdump. We execute the substitution with sed. We then convert the hex values back to binary form using xxd.
+# We also write a shell script that invoked "mktemp -d" to produce a r/w temporary directory and link what we need in the temporary directory.
+# Result:
+# The user can run brprintconf_mfcj6510dw in the shell.
+
+stdenv.mkDerivation rec {
+  pname = "mfcj6510dwlpr";
+  version = "3.0.0-1";
+
+  src = fetchurl {
+    url = "https://download.brother.com/welcome/dlf006614/mfcj6510dwlpr-${version}.i386.deb";
+    sha256 = "1ccvx393pqavsgzd8igrzlin5jrsf01d3acyvwqd1d0yz5jgqy6d";
+  };
+
+  nativeBuildInputs = [ makeWrapper ];
+  buildInputs = [ cups ghostscript dpkg a2ps ];
+
+  dontUnpack = true;
+
+  brprintconf_mfcj6510dw_script = ''
+    #!${runtimeShell}
+    cd $(mktemp -d)
+    ln -s @out@/usr/bin/brprintconf_mfcj6510dw_patched brprintconf_mfcj6510dw_patched
+    ln -s @out@/opt/brother/Printers/mfcj6510dw/inf/brmfcj6510dwfunc brmfcj6510dwfunc
+    ln -s @out@/opt/brother/Printers/mfcj6510dw/inf/brmfcj6510dwrc brmfcj6510dwrc
+    ./brprintconf_mfcj6510dw_patched "$@"
+  '';
+
+  installPhase = ''
+    dpkg-deb -x $src $out
+    substituteInPlace $out/opt/brother/Printers/mfcj6510dw/lpd/filtermfcj6510dw \
+      --replace /opt "$out/opt"
+    substituteInPlace $out/opt/brother/Printers/mfcj6510dw/lpd/psconvertij2 \
+      --replace "GHOST_SCRIPT=`which gs`" "GHOST_SCRIPT=${ghostscript}/bin/gs"
+    substituteInPlace $out/opt/brother/Printers/mfcj6510dw/inf/setupPrintcapij \
+      --replace "/opt/brother/Printers" "$out/opt/brother/Printers" \
+      --replace "printcap.local" "printcap"
+
+    patchelf --set-interpreter ${pkgsi686Linux.stdenv.cc.libc.out}/lib/ld-linux.so.2 \
+      --set-rpath $out/opt/brother/Printers/mfcj6510dw/inf:$out/opt/brother/Printers/mfcj6510dw/lpd \
+      $out/opt/brother/Printers/mfcj6510dw/lpd/brmfcj6510dwfilter
+    patchelf --set-interpreter ${pkgsi686Linux.stdenv.cc.libc.out}/lib/ld-linux.so.2 $out/usr/bin/brprintconf_mfcj6510dw
+
+    #stripping the hardcoded path.
+    ${util-linux}/bin/hexdump -ve '1/1 "%.2X"' $out/usr/bin/brprintconf_mfcj6510dw | \
+    sed 's.2F6F70742F62726F746865722F5072696E746572732F25732F696E662F6272257366756E63.62726d66636a36353130647766756e63000000000000000000000000000000000000000000.' | \
+    sed 's.2F6F70742F62726F746865722F5072696E746572732F25732F696E662F627225737263.62726D66636A3635313064777263000000000000000000000000000000000000000000.' | \
+    ${xxd}/bin/xxd -r -p > $out/usr/bin/brprintconf_mfcj6510dw_patched
+    chmod +x $out/usr/bin/brprintconf_mfcj6510dw_patched
+    #executing from current dir. segfaults if it's not r\w.
+    mkdir -p $out/bin
+    echo -n "$brprintconf_mfcj6510dw_script" > $out/bin/brprintconf_mfcj6510dw
+    chmod +x $out/bin/brprintconf_mfcj6510dw
+    substituteInPlace $out/bin/brprintconf_mfcj6510dw --replace @out@ $out
+
+    mkdir -p $out/lib/cups/filter/
+    ln -s $out/opt/brother/Printers/mfcj6510dw/lpd/filtermfcj6510dw $out/lib/cups/filter/brother_lpdwrapper_mfcj6510dw
+
+    wrapProgram $out/opt/brother/Printers/mfcj6510dw/lpd/psconvertij2 \
+      --prefix PATH ":" ${ lib.makeBinPath [ coreutils gnused gawk ] }
+    wrapProgram $out/opt/brother/Printers/mfcj6510dw/lpd/filtermfcj6510dw \
+      --prefix PATH ":" ${ lib.makeBinPath [ coreutils gnused file ghostscript a2ps ] }
+    '';
+
+  meta = with lib; {
+    description  = "Brother MFC-J6510DW LPR driver";
+    downloadPage = "http://support.brother.com/g/b/downloadlist.aspx?c=us&lang=en&prod=mfcj6510dw_all&os=128";
+    homepage     = "http://www.brother.com/";
+    license      = with licenses; unfree;
+    maintainers  = with maintainers; [ ramkromberg ];
+    platforms    = with platforms; linux;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/cups/drivers/mfcl2700dncupswrapper/default.nix b/nixpkgs/pkgs/misc/cups/drivers/mfcl2700dncupswrapper/default.nix
new file mode 100644
index 000000000000..6eebfe64d5a7
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/mfcl2700dncupswrapper/default.nix
@@ -0,0 +1,44 @@
+{ coreutils, dpkg, fetchurl, gnugrep, gnused, makeWrapper, mfcl2700dnlpr, perl, lib, stdenv }:
+
+stdenv.mkDerivation rec {
+  name = "mfcl2700dncupswrapper-${meta.version}";
+
+  src = fetchurl {
+    url = "https://download.brother.com/welcome/dlf102086/${name}.i386.deb";
+    sha256 = "07w48mah0xbv4h8vsh1qd5cd4b463bx8y6gc5x9pfgsxsy6h6da1";
+  };
+
+  nativeBuildInputs = [ dpkg makeWrapper ];
+
+  phases = [ "installPhase" ];
+
+  installPhase = ''
+    dpkg-deb -x $src $out
+
+    basedir=${mfcl2700dnlpr}/opt/brother/Printers/MFCL2700DN
+    dir=$out/opt/brother/Printers/MFCL2700DN
+
+    substituteInPlace $dir/cupswrapper/brother_lpdwrapper_MFCL2700DN \
+      --replace /usr/bin/perl ${perl}/bin/perl \
+      --replace "basedir =~" "basedir = \"$basedir\"; #" \
+      --replace "PRINTER =~" "PRINTER = \"MFCL2700DN\"; #"
+
+    wrapProgram $dir/cupswrapper/brother_lpdwrapper_MFCL2700DN \
+      --prefix PATH : ${lib.makeBinPath [ coreutils gnugrep gnused ]}
+
+    mkdir -p $out/lib/cups/filter
+    mkdir -p $out/share/cups/model
+
+    ln $dir/cupswrapper/brother_lpdwrapper_MFCL2700DN $out/lib/cups/filter
+    ln $dir/cupswrapper/brother-MFCL2700DN-cups-en.ppd $out/share/cups/model
+  '';
+
+  meta = {
+    description = "Brother MFC-L2700DN CUPS wrapper driver";
+    homepage = "http://www.brother.com/";
+    license = lib.licenses.gpl2Plus;
+    maintainers = [ lib.maintainers.tv ];
+    platforms = lib.platforms.linux;
+    version = "3.2.0-1";
+  };
+}
diff --git a/nixpkgs/pkgs/misc/cups/drivers/mfcl2700dnlpr/default.nix b/nixpkgs/pkgs/misc/cups/drivers/mfcl2700dnlpr/default.nix
new file mode 100644
index 000000000000..0d11579e9541
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/mfcl2700dnlpr/default.nix
@@ -0,0 +1,44 @@
+{ lib, stdenv, coreutils, dpkg, fetchurl, ghostscript, gnugrep, gnused, makeWrapper, perl, which }:
+
+stdenv.mkDerivation rec {
+  pname = "mfcl2700dnlpr";
+  version = "3.2.0-1";
+
+  src = fetchurl {
+    url = "https://download.brother.com/welcome/dlf102085/${pname}-${version}.i386.deb";
+    sha256 = "170qdzxlqikzvv2wphvfb37m19mn13az4aj88md87ka3rl5knk4m";
+  };
+
+  nativeBuildInputs = [ dpkg makeWrapper ];
+
+  phases = [ "installPhase" ];
+
+  installPhase = ''
+    dpkg-deb -x $src $out
+
+    dir=$out/opt/brother/Printers/MFCL2700DN
+
+    substituteInPlace $dir/lpd/filter_MFCL2700DN \
+      --replace /usr/bin/perl ${perl}/bin/perl \
+      --replace "BR_PRT_PATH =~" "BR_PRT_PATH = \"$dir\"; #" \
+      --replace "PRINTER =~" "PRINTER = \"MFCL2700DN\"; #"
+
+    wrapProgram $dir/lpd/filter_MFCL2700DN \
+      --prefix PATH : ${lib.makeBinPath [
+        coreutils ghostscript gnugrep gnused which
+      ]}
+
+    interpreter=$(cat $NIX_CC/nix-support/dynamic-linker)
+    patchelf --set-interpreter "$interpreter" $dir/inf/braddprinter
+    patchelf --set-interpreter "$interpreter" $dir/lpd/brprintconflsr3
+    patchelf --set-interpreter "$interpreter" $dir/lpd/rawtobr3
+  '';
+
+  meta = {
+    description = "Brother MFC-L2700DN LPR driver";
+    homepage = "http://www.brother.com/";
+    license = lib.licenses.unfree;
+    maintainers = [ lib.maintainers.tv ];
+    platforms = [ "i686-linux" ];
+  };
+}
diff --git a/nixpkgs/pkgs/misc/cups/drivers/mfcl2720dwcupswrapper/default.nix b/nixpkgs/pkgs/misc/cups/drivers/mfcl2720dwcupswrapper/default.nix
new file mode 100644
index 000000000000..5d4980da9d17
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/mfcl2720dwcupswrapper/default.nix
@@ -0,0 +1,47 @@
+{ lib, stdenv, fetchurl, dpkg, makeWrapper, coreutils, gnugrep, gnused, perl, mfcl2720dwlpr }:
+
+stdenv.mkDerivation rec {
+  pname = "mfcl2720dwcupswrapper";
+  version = "3.2.0-1";
+
+  src = fetchurl {
+    url = "https://download.brother.com/welcome/dlf101802/${pname}-${version}.i386.deb";
+    sha256 = "6d131926ce22c51b1854d2b91e426cc7ecbf5d6dabd698ef51a417090e35c598";
+  };
+
+  nativeBuildInputs = [ dpkg makeWrapper ];
+
+  phases = [ "installPhase" ];
+
+  installPhase = ''
+    dpkg-deb -x $src $out
+
+    basedir=${mfcl2720dwlpr}/opt/brother/Printers/MFCL2720DW
+    dir=$out/opt/brother/Printers/MFCL2720DW
+
+    substituteInPlace $dir/cupswrapper/brother_lpdwrapper_MFCL2720DW \
+      --replace /usr/bin/perl ${perl}/bin/perl \
+      --replace "basedir =~" "basedir = \"$basedir\"; #" \
+      --replace "PRINTER =~" "PRINTER = \"MFCL2720DW\"; #"
+
+    substituteInPlace $dir/cupswrapper/paperconfigml1 \
+      --replace /usr/bin/perl ${perl}/bin/perl
+
+    wrapProgram $dir/cupswrapper/brother_lpdwrapper_MFCL2720DW \
+      --prefix PATH : ${lib.makeBinPath [ coreutils gnugrep gnused ]}
+
+    mkdir -p $out/lib/cups/filter
+    mkdir -p $out/share/cups/model
+
+    ln $dir/cupswrapper/brother_lpdwrapper_MFCL2720DW $out/lib/cups/filter
+    ln $dir/cupswrapper/brother-MFCL2720DW-cups-en.ppd $out/share/cups/model
+  '';
+
+  meta = {
+    description = "Brother MFC-L2720DW CUPS wrapper driver";
+    homepage = "http://www.brother.com/";
+    license = lib.licenses.gpl2;
+    platforms = [ "x86_64-linux" "i686-linux" ];
+    maintainers = [ lib.maintainers.xeji ];
+  };
+}
diff --git a/nixpkgs/pkgs/misc/cups/drivers/mfcl2720dwlpr/default.nix b/nixpkgs/pkgs/misc/cups/drivers/mfcl2720dwlpr/default.nix
new file mode 100644
index 000000000000..2b6c458e7454
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/mfcl2720dwlpr/default.nix
@@ -0,0 +1,45 @@
+{ pkgs, lib, stdenv, fetchurl, dpkg, makeWrapper, coreutils, ghostscript, gnugrep, gnused, which, perl }:
+
+stdenv.mkDerivation rec {
+  pname = "mfcl2720dwlpr";
+  version = "3.2.0-1";
+
+  src = fetchurl {
+    url = "https://download.brother.com/welcome/dlf101801/${pname}-${version}.i386.deb";
+    sha256 = "088217e9ad118ec1e7f3d3f8f60f3bd839fe2c7d7c1136b249e9ac648dc742af";
+  };
+
+  nativeBuildInputs = [ dpkg makeWrapper ];
+
+  phases = [ "installPhase" ];
+
+  installPhase = ''
+    dpkg-deb -x $src $out
+
+    dir=$out/opt/brother/Printers/MFCL2720DW
+
+    substituteInPlace $dir/lpd/filter_MFCL2720DW \
+      --replace /usr/bin/perl ${perl}/bin/perl \
+      --replace "BR_PRT_PATH =~" "BR_PRT_PATH = \"$dir\"; #" \
+      --replace "PRINTER =~" "PRINTER = \"MFCL2720DW\"; #"
+
+    wrapProgram $dir/lpd/filter_MFCL2720DW \
+      --prefix PATH : ${lib.makeBinPath [
+        coreutils ghostscript gnugrep gnused which
+      ]}
+
+    # need to use i686 glibc here, these are 32bit proprietary binaries
+    interpreter=${pkgs.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
+  '';
+
+  meta = {
+    description = "Brother MFC-L2720DW lpr driver";
+    homepage = "http://www.brother.com/";
+    license = lib.licenses.unfree;
+    platforms = [ "x86_64-linux" "i686-linux" ];
+    maintainers = [ lib.maintainers.xeji ];
+  };
+}
diff --git a/nixpkgs/pkgs/misc/cups/drivers/mfcl2740dwcupswrapper/default.nix b/nixpkgs/pkgs/misc/cups/drivers/mfcl2740dwcupswrapper/default.nix
new file mode 100644
index 000000000000..a119c31517ce
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/mfcl2740dwcupswrapper/default.nix
@@ -0,0 +1,45 @@
+{ lib, stdenv, fetchurl, dpkg, makeWrapper, coreutils, gnugrep, gnused, perl, mfcl2740dwlpr }:
+
+stdenv.mkDerivation rec {
+  pname = "mfcl2740dwcupswrapper";
+  version = "3.2.0-1";
+
+  src = fetchurl {
+    url = "https://download.brother.com/welcome/dlf101726/${pname}-${version}.i386.deb";
+    sha256 = "078453e19f20ab6c7fc4d63c3e09f162f3d1410c04c23a294b6ffbd720b35ffb";
+  };
+
+  nativeBuildInputs = [ dpkg makeWrapper ];
+
+  unpackPhase = "dpkg-deb -x $src $out";
+
+  installPhase = ''
+    basedir=${mfcl2740dwlpr}/opt/brother/Printers/MFCL2740DW
+    dir=$out/opt/brother/Printers/MFCL2740DW
+
+    substituteInPlace $dir/cupswrapper/brother_lpdwrapper_MFCL2740DW \
+      --replace /usr/bin/perl ${perl}/bin/perl \
+      --replace "basedir =~" "basedir = \"$basedir\"; #" \
+      --replace "PRINTER =~" "PRINTER = \"MFCL2740DW\"; #"
+
+    substituteInPlace $dir/cupswrapper/paperconfigml1 \
+      --replace /usr/bin/perl ${perl}/bin/perl
+
+    wrapProgram $dir/cupswrapper/brother_lpdwrapper_MFCL2740DW \
+      --prefix PATH : ${lib.makeBinPath [ coreutils gnugrep gnused ]}
+
+    mkdir -p $out/lib/cups/filter
+    mkdir -p $out/share/cups/model
+
+    ln $dir/cupswrapper/brother_lpdwrapper_MFCL2740DW $out/lib/cups/filter
+    ln $dir/cupswrapper/brother-MFCL2740DW-cups-en.ppd $out/share/cups/model
+  '';
+
+  meta = {
+    description = "Brother MFC-L2740DW CUPS wrapper driver";
+    homepage = "http://www.brother.com/";
+    license = lib.licenses.gpl2;
+    platforms = [ "x86_64-linux" "i686-linux" ];
+    maintainers = [ lib.maintainers.enzime ];
+  };
+}
diff --git a/nixpkgs/pkgs/misc/cups/drivers/mfcl2740dwlpr/default.nix b/nixpkgs/pkgs/misc/cups/drivers/mfcl2740dwlpr/default.nix
new file mode 100644
index 000000000000..38722a734a66
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/mfcl2740dwlpr/default.nix
@@ -0,0 +1,43 @@
+{ pkgsi686Linux, lib, stdenv, fetchurl, dpkg, makeWrapper, coreutils, ghostscript, gnugrep, gnused, which, perl }:
+
+stdenv.mkDerivation rec {
+  pname = "mfcl2740dwlpr";
+  version = "3.2.0-1";
+
+  src = fetchurl {
+    url = "https://download.brother.com/welcome/dlf101727/${pname}-${version}.i386.deb";
+    sha256 = "10a2bc672bd54e718b478f3afc7e47d451557f7d5513167d3ad349a3d00bffaf";
+  };
+
+  nativeBuildInputs = [ dpkg makeWrapper ];
+
+  unpackPhase = "dpkg-deb -x $src $out";
+
+  installPhase = ''
+    dir=$out/opt/brother/Printers/MFCL2740DW
+
+    substituteInPlace $dir/lpd/filter_MFCL2740DW \
+      --replace /usr/bin/perl ${perl}/bin/perl \
+      --replace "BR_PRT_PATH =~" "BR_PRT_PATH = \"$dir\"; #" \
+      --replace "PRINTER =~" "PRINTER = \"MFCL2740DW\"; #"
+
+    wrapProgram $dir/lpd/filter_MFCL2740DW \
+      --prefix PATH : ${lib.makeBinPath [
+        coreutils ghostscript gnugrep gnused which
+      ]}
+
+    # 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
+  '';
+
+  meta = {
+    description = "Brother MFC-L2740DW lpr driver";
+    homepage = "http://www.brother.com/";
+    license = lib.licenses.unfree;
+    platforms = [ "x86_64-linux" "i686-linux" ];
+    maintainers = [ lib.maintainers.enzime ];
+  };
+}
diff --git a/nixpkgs/pkgs/misc/cups/drivers/mfcl8690cdwcupswrapper/default.nix b/nixpkgs/pkgs/misc/cups/drivers/mfcl8690cdwcupswrapper/default.nix
new file mode 100644
index 000000000000..ebb2e4392989
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/mfcl8690cdwcupswrapper/default.nix
@@ -0,0 +1,45 @@
+{ coreutils, dpkg, fetchurl, gnugrep, gnused, makeWrapper,
+mfcl8690cdwlpr, perl, lib, stdenv}:
+
+stdenv.mkDerivation rec {
+  pname = "mfcl8690cdwcupswrapper";
+  version = "1.4.0-0";
+
+  src = fetchurl {
+    url = "http://download.brother.com/welcome/dlf103250/${pname}-${version}.i386.deb";
+    sha256 = "1bl9r8mmj4vnanwpfjqgq3c9lf2v46wp5k6r2n9iqprf7ldd1kb2";
+  };
+
+  nativeBuildInputs = [ dpkg makeWrapper ];
+
+  phases = [ "installPhase" ];
+
+  installPhase = ''
+    dpkg-deb -x $src $out
+
+    basedir=${mfcl8690cdwlpr}/opt/brother/Printers/mfcl8690cdw
+    dir=$out/opt/brother/Printers/mfcl8690cdw
+
+    substituteInPlace $dir/cupswrapper/brother_lpdwrapper_mfcl8690cdw \
+      --replace /usr/bin/perl ${perl}/bin/perl \
+      --replace "basedir =~" "basedir = \"$basedir/\"; #" \
+      --replace "PRINTER =~" "PRINTER = \"mfcl8690cdw\"; #"
+
+    wrapProgram $dir/cupswrapper/brother_lpdwrapper_mfcl8690cdw \
+      --prefix PATH : ${lib.makeBinPath [ coreutils gnugrep gnused ]}
+
+    mkdir -p $out/lib/cups/filter
+    mkdir -p $out/share/cups/model
+
+    ln $dir/cupswrapper/brother_lpdwrapper_mfcl8690cdw $out/lib/cups/filter
+    ln $dir/cupswrapper/brother_mfcl8690cdw_printer_en.ppd $out/share/cups/model
+    '';
+
+  meta = {
+    description = "Brother MFC-L8690CDW CUPS wrapper driver";
+    homepage = "http://www.brother.com/";
+    license = lib.licenses.unfree;
+    platforms = lib.platforms.linux;
+    maintainers = [ lib.maintainers.fuzzy-id ];
+  };
+}
diff --git a/nixpkgs/pkgs/misc/cups/drivers/mfcl8690cdwlpr/default.nix b/nixpkgs/pkgs/misc/cups/drivers/mfcl8690cdwlpr/default.nix
new file mode 100644
index 000000000000..2b5dc44cead8
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/mfcl8690cdwlpr/default.nix
@@ -0,0 +1,45 @@
+{ coreutils, dpkg, fetchurl, file, ghostscript, gnugrep, gnused,
+makeWrapper, perl, pkgs, lib, stdenv, which }:
+
+stdenv.mkDerivation rec {
+  pname = "mfcl8690cdwlpr";
+  version = "1.3.0-0";
+
+  src = fetchurl {
+    url = "http://download.brother.com/welcome/dlf103241/${pname}-${version}.i386.deb";
+    sha256 = "0x8zd4b1psmw1znp2ibncs37xm5mljcy9yza2rx8jm8lp0a3l85v";
+  };
+
+  nativeBuildInputs = [ dpkg makeWrapper ];
+
+  phases = [ "installPhase" ];
+
+  installPhase = ''
+    dpkg-deb -x $src $out
+
+    dir=$out/opt/brother/Printers/mfcl8690cdw
+    filter=$dir/lpd/filter_mfcl8690cdw
+
+    substituteInPlace $filter \
+      --replace /usr/bin/perl ${perl}/bin/perl \
+      --replace "BR_PRT_PATH =~" "BR_PRT_PATH = \"$dir/\"; #" \
+      --replace "PRINTER =~" "PRINTER = \"mfcl8690cdw\"; #"
+
+    wrapProgram $filter \
+      --prefix PATH : ${lib.makeBinPath [
+      coreutils file ghostscript gnugrep gnused which
+      ]}
+
+    # need to use i686 glibc here, these are 32bit proprietary binaries
+    interpreter=${pkgs.pkgsi686Linux.glibc}/lib/ld-linux.so.2
+    patchelf --set-interpreter "$interpreter" $dir/lpd/brmfcl8690cdwfilter
+  '';
+
+  meta = {
+    description = "Brother MFC-L8690CDW LPR printer driver";
+    homepage = "http://www.brother.com/";
+    license = lib.licenses.unfree;
+    maintainers = [ lib.maintainers.fuzzy-id ];
+    platforms = [ "i686-linux" ];
+  };
+}
diff --git a/nixpkgs/pkgs/misc/cups/drivers/samsung/1.00.36/default.nix b/nixpkgs/pkgs/misc/cups/drivers/samsung/1.00.36/default.nix
new file mode 100644
index 000000000000..2ea0e2538539
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/samsung/1.00.36/default.nix
@@ -0,0 +1,116 @@
+{ lib, stdenv, fetchurl, cups, libusb-compat-0_1, libxml2, perl }:
+
+let
+
+    arch = if stdenv.system == "x86_64-linux"
+      then "x86_64"
+      else "i386";
+
+in stdenv.mkDerivation rec {
+  pname = "samsung-unified-linux-driver";
+  version = "1.00.36";
+
+  src = fetchurl {
+    sha256 = "1a7ngd03x0bkdl7pszy5zqqic0plxvdxqm5w7klr6hbdskx1lir9";
+    url = "http://www.bchemnet.com/suldr/driver/UnifiedLinuxDriver-${version}.tar.gz";
+  };
+
+  buildInputs = [
+    cups
+    libusb-compat-0_1
+    libxml2
+    perl
+  ];
+
+  installPhase = ''
+
+    mkdir -p $out/bin
+    cp -R ${arch}/{gettext,pstosecps,rastertospl,smfpnetdiscovery,usbresetter} $out/bin
+
+    mkdir -p $out/etc/sane.d/dll.d/
+    install -m644 noarch/etc/smfp.conf $out/etc/sane.d
+    echo smfp >> $out/etc/sane.d/dll.d/smfp-scanner.conf
+
+    mkdir -p $out/etc/smfp-common/scanner/share/
+    install -m644 noarch/libsane-smfp.cfg $out/etc/smfp-common/scanner/share/
+    install -m644 noarch/pagesize.xml $out/etc/smfp-common/scanner/share/
+
+    mkdir -p $out/etc/samsung/scanner/share/
+    install -m644 noarch/oem.conf $out/etc/samsung/scanner/share/
+
+    mkdir -p $out/lib
+    install -m755 ${arch}/libscmssc.so* $out/lib
+
+    mkdir -p $out/lib/cups/backend
+    ln -s $out/bin/smfpnetdiscovery $out/lib/cups/backend
+
+    mkdir -p $out/lib/cups/filter
+    ln -s $out/bin/{pstosecps,rastertospl} $out/lib/cups/filter
+    ln -s $ghostscript/bin/gs $out/lib/cups/filter
+
+    mkdir -p $out/lib/sane
+    install -m755 ${arch}/libsane-smfp.so* $out/lib/sane
+    ln -s libsane-smfp.so.1.0.1 $out/lib/sane/libsane-smfp.so.1
+    ln -s libsane-smfp.so.1     $out/lib/sane/libsane-smfp.so
+
+    perl -pi -e \
+      's|/opt/smfp-common/scanner/.usedby/|/tmp/\0\0fp-common/scanner/.usedby/|g' \
+       $out/lib/sane/libsane-smfp.so.1.0.1
+    perl -pi -e 's|/opt|/etc|g' \
+       $out/lib/sane/libsane-smfp.so.1.0.1 \
+       $out/bin/rastertospl \
+       noarch/package_utils \
+       noarch/pre_install.sh
+
+    mkdir -p $out/lib/udev/rules.d
+    (
+      OEM_FILE=noarch/oem.conf
+      INSTALL_LOG_FILE=/dev/null
+      . noarch/scripting_utils
+      . noarch/package_utils
+      . noarch/scanner-script.pkg
+      fill_full_template noarch/etc/smfp.rules.in $out/lib/udev/rules.d/60_smfp_samsung.rules
+      chmod -x $out/lib/udev/rules.d/60_smfp_samsung.rules
+    )
+
+    mkdir -p $out/share
+    cp -R noarch/share/* $out/share
+    gzip -9 $out/share/ppd/*.ppd
+    rm -r $out/share/locale/*/*/install.mo
+
+    mkdir -p $out/share/cups
+    cd $out/share/cups
+    ln -s ../ppd .
+    ln -s ppd model
+  '';
+
+  preFixup = ''
+    for bin in "$out/bin/"*; do
+      patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" "$bin"
+      patchelf --set-rpath "$out/lib:${lib.getLib cups}/lib" "$bin"
+    done
+
+    patchelf --set-rpath "$out/lib:${lib.getLib cups}/lib" "$out/lib/libscmssc.so"
+    patchelf --set-rpath "$out/lib:${libxml2.out}/lib:${libusb-compat-0_1.out}/lib" "$out/lib/sane/libsane-smfp.so.1.0.1"
+
+    ln -s ${stdenv.cc.cc.lib}/lib/libstdc++.so.6 $out/lib/
+  '';
+
+  # all binaries are already stripped
+  dontStrip = true;
+
+  # we did this in prefixup already
+  dontPatchELF = true;
+
+  meta = with lib; {
+    description = "Unified Linux Driver for Samsung printers and scanners";
+    homepage = "http://www.bchemnet.com/suldr";
+    downloadPage = "http://www.bchemnet.com/suldr/driver/";
+    license = licenses.unfree;
+
+    # Tested on linux-x86_64. Might work on linux-i386.
+    # Probably won't work on anything else.
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ tohl ];
+  };
+}
diff --git a/nixpkgs/pkgs/misc/cups/drivers/samsung/1.00.36/module.nix b/nixpkgs/pkgs/misc/cups/drivers/samsung/1.00.36/module.nix
new file mode 100644
index 000000000000..e98da9de2b60
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/samsung/1.00.36/module.nix
@@ -0,0 +1,44 @@
+# the original samsung-unified-linux-driver_1_00_36 has some paths
+# hardcoded in binary files
+#
+# nixos samsung-unified-linux-driver_1_00_36 tries to fix those paths
+# by patching the binaries
+#
+# this module is needed to put the expected files in the new paths
+#
+# printing works without problems
+#
+# scanning works, except one detail: sometimes it is possible to scan
+# more pages in sequence.  most of the time though, scanning stops
+# working after one page.  this problem happens both with scanimage
+# and simple-scan.  errors indicate an I/O error.  scanning works
+# again after turning the device off and on.  atm i have no idea how
+# to fix this and no time to do more about it.
+{config, pkgs, lib ? pkgs.lib, ...}:
+with lib;
+let
+  cfg = config.services.samsung-unified-linux-driver_1_00_36;
+  pkg = pkgs.samsung-unified-linux-driver_1_00_36;
+in {
+  options = {
+    services.samsung-unified-linux-driver_1_00_36 = {
+      enable = mkEnableOption "enable samsung-unified-linux-driver_1_00_36";
+    };
+  };
+  config = mkIf cfg.enable {
+    services.printing.drivers = [pkg];
+    hardware.sane.extraBackends = [pkg];
+    environment.etc = {
+      "samsung/scanner/share/oem.conf".source
+        = "${pkg}/etc/samsung/scanner/share/oem.conf";
+      "smfp-common/scanner/share/libsane-smfp.cfg".source
+        = "${pkg}/etc/smfp-common/scanner/share/libsane-smfp.cfg";
+      "smfp-common/scanner/share/pagesize.xml".source
+        = "${pkg}/etc/smfp-common/scanner/share/pagesize.xml";
+      "sane.d/smfp.conf".source
+        = "${pkg}/etc/sane.d/smfp.conf";
+      "sane.d/dll.d/smfp-scanner.conf".source
+        = "${pkg}/etc/sane.d/dll.d/smfp-scanner.conf";
+    };
+  };
+}
diff --git a/nixpkgs/pkgs/misc/cups/drivers/samsung/1.00.37.nix b/nixpkgs/pkgs/misc/cups/drivers/samsung/1.00.37.nix
new file mode 100644
index 000000000000..9fb26f62d76d
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/samsung/1.00.37.nix
@@ -0,0 +1,98 @@
+{ lib, stdenv, fetchurl, cups, libusb-compat-0_1, libxml2 }:
+
+let
+
+    arch = if stdenv.hostPlatform.system == "x86_64-linux"
+      then "x86_64"
+      else "i386";
+
+in stdenv.mkDerivation rec {
+  pname = "samsung-unified-linux-driver";
+  version = "1.00.37";
+
+  src = fetchurl {
+    sha256 = "0r66l9zp0p1qgakh4j08hynwsr4lsgq5yrpxyr0x4ldvl0z2b1bb";
+    url = "http://www.bchemnet.com/suldr/driver/UnifiedLinuxDriver-${version}.tar.gz";
+  };
+
+  buildInputs = [
+    cups
+    libusb-compat-0_1
+    libxml2
+  ];
+
+  installPhase = ''
+
+    mkdir -p $out/bin
+    cp -R ${arch}/{gettext,pstosecps,rastertospl,smfpnetdiscovery,usbresetter} $out/bin
+
+    mkdir -p $out/etc/sane.d/dll.d/
+    install -m644 noarch/etc/smfp.conf $out/etc/sane.d
+    echo smfp >> $out/etc/sane.d/dll.d/smfp-scanner.conf
+
+    mkdir -p $out/lib
+    install -m755 ${arch}/libscmssc.so* $out/lib
+
+    mkdir -p $out/lib/cups/backend
+    ln -s $out/bin/smfpnetdiscovery $out/lib/cups/backend
+
+    mkdir -p $out/lib/cups/filter
+    ln -s $out/bin/{pstosecps,rastertospl} $out/lib/cups/filter
+    ln -s $ghostscript/bin/gs $out/lib/cups/filter
+
+    mkdir -p $out/lib/sane
+    install -m755 ${arch}/libsane-smfp.so* $out/lib/sane
+    ln -s libsane-smfp.so.1.0.1 $out/lib/sane/libsane-smfp.so.1
+    ln -s libsane-smfp.so.1     $out/lib/sane/libsane-smfp.so
+
+    mkdir -p $out/lib/udev/rules.d
+    (
+      OEM_FILE=noarch/oem.conf
+      INSTALL_LOG_FILE=/dev/null
+      . noarch/scripting_utils
+      . noarch/package_utils
+      . noarch/scanner-script.pkg
+      fill_full_template noarch/etc/smfp.rules.in $out/lib/udev/rules.d/60_smfp_samsung.rules
+      chmod -x $out/lib/udev/rules.d/60_smfp_samsung.rules
+    )
+
+    mkdir -p $out/share
+    cp -R noarch/share/* $out/share
+    gzip -9 $out/share/ppd/*.ppd
+    rm -r $out/share/locale/*/*/install.mo
+
+    mkdir -p $out/share/cups
+    cd $out/share/cups
+    ln -s ../ppd .
+    ln -s ppd model
+  '';
+
+  preFixup = ''
+    for bin in "$out/bin/"*; do
+      patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" "$bin"
+      patchelf --set-rpath "$out/lib:${lib.getLib cups}/lib" "$bin"
+    done
+
+    patchelf --set-rpath "$out/lib:${lib.getLib cups}/lib" "$out/lib/libscmssc.so"
+    patchelf --set-rpath "$out/lib:${libxml2.out}/lib:${libusb-compat-0_1.out}/lib" "$out/lib/sane/libsane-smfp.so.1.0.1"
+
+    ln -s ${stdenv.cc.cc.lib}/lib/libstdc++.so.6 $out/lib/
+  '';
+
+  # all binaries are already stripped
+  dontStrip = true;
+
+  # we did this in prefixup already
+  dontPatchELF = true;
+
+  meta = with lib; {
+    description = "Unified Linux Driver for Samsung printers and scanners";
+    homepage = "http://www.bchemnet.com/suldr";
+    downloadPage = "http://www.bchemnet.com/suldr/driver/";
+    license = licenses.unfree;
+
+    # Tested on linux-x86_64. Might work on linux-i386.
+    # Probably won't work on anything else.
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/cups/drivers/samsung/4.00.39/builder.sh b/nixpkgs/pkgs/misc/cups/drivers/samsung/4.00.39/builder.sh
new file mode 100644
index 000000000000..f750df6e5063
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/samsung/4.00.39/builder.sh
@@ -0,0 +1,35 @@
+source $stdenv/setup
+
+arch=$(uname -m)
+echo "$arch" | egrep -q '^i[3456]86$' && arch=i386
+echo "Installing for $arch"
+
+unpackPhase
+patchPhase
+
+set -v
+
+cd cdroot/Linux
+mkdir -p $out/opt
+cp -r $arch/at_root/* $out
+cp -r $arch/at_opt/* $out/opt
+#cp -r noarch/at_root/* $out
+cp -r noarch/at_opt/* $out/opt
+
+cd $out
+test -d usr/lib64 && ln -s usr/lib64 lib ||
+    ln -s usr/lib lib
+mkdir -p share/cups
+cd share/cups
+ln -s ../../opt/share/* .
+ln -s ppd model
+
+cd $out/lib/cups/filter
+for i in $(ls); do
+    echo "Patching $i..."
+    patchelf --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) $i ||
+      echo "Couldn't set interpreter!"
+    patchelf --set-rpath $cups/lib:$gcc/lib:$glibc/lib $i  # This might not be necessary.
+done
+
+ln -s $ghostscript/bin/gs $out/lib/cups/filter
diff --git a/nixpkgs/pkgs/misc/cups/drivers/samsung/4.00.39/default.nix b/nixpkgs/pkgs/misc/cups/drivers/samsung/4.00.39/default.nix
new file mode 100644
index 000000000000..92f5fdc409c4
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/samsung/4.00.39/default.nix
@@ -0,0 +1,44 @@
+# Tested on linux-x86_64.  Might work on linux-i386.  Probably won't work on anything else.
+
+# To use this driver in NixOS, add it to printing.drivers in configuration.nix.
+# configuration.nix might look like this when you're done:
+# { pkgs, ... }: {
+#   printing = {
+#     enable = true;
+#     drivers = [ pkgs.samsungUnifiedLinuxDriver ];
+#   };
+#   (more stuff)
+# }
+# (This advice was tested on 2010 August 2.)
+
+{ lib, stdenv, fetchurl, cups, gcc, ghostscript, glibc, patchelf }:
+
+# Do not bump lightly! Visit <http://www.bchemnet.com/suldr/supported.html>
+# to see what will break when upgrading. Consider a new versioned attribute.
+let
+  cups' = lib.getLib cups;
+in stdenv.mkDerivation rec {
+  pname = "samsung-UnifiedLinuxDriver";
+  version = "4.00.39";
+
+  src = fetchurl {
+    url = "http://www.bchemnet.com/suldr/driver/UnifiedLinuxDriver-${version}.tar.gz";
+    sha256 = "144b4xggbzjfq7ga5nza7nra2cf6qn63z5ls7ba1jybkx1vm369k";
+  };
+
+  nativeBuildInputs = [ patchelf ];
+  buildInputs = [ cups' gcc ghostscript glibc ];
+
+  inherit gcc ghostscript glibc;
+  cups = cups';
+
+  builder = ./builder.sh;
+
+  meta = with lib; {
+    description = "Samsung's Linux printing drivers; includes binaries without source code";
+    homepage = "http://www.samsung.com/";
+    license = licenses.unfree;
+    platforms = platforms.linux;
+    broken = true;   # libscmssc.so and libmfp.so can't find their library dependencies at run-time
+  };
+}
diff --git a/nixpkgs/pkgs/misc/cups/drivers/samsung/4.01.17.nix b/nixpkgs/pkgs/misc/cups/drivers/samsung/4.01.17.nix
new file mode 100644
index 000000000000..2591cf735661
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/samsung/4.01.17.nix
@@ -0,0 +1,82 @@
+# Tested on linux-x86_64.  Might work on linux-i386.  Probably won't work on anything else.
+
+# To use this driver in NixOS, add it to printing.drivers in configuration.nix.
+# configuration.nix might look like this when you're done:
+# { pkgs, ... }: {
+#   printing = {
+#     enable = true;
+#     drivers = [ pkgs.samsung-unified-linux-driver_4_01_17 ];
+#   };
+#   (more stuff)
+# }
+# (This advice was tested on the 1st November 2016.)
+
+{ lib, stdenv, fetchurl, cups, libusb-compat-0_1 }:
+
+# Do not bump lightly! Visit <http://www.bchemnet.com/suldr/supported.html>
+# to see what will break when upgrading. Consider a new versioned attribute.
+let
+  installationPath = if stdenv.hostPlatform.system == "x86_64-linux" then "x86_64" else "i386";
+  appendPath = if stdenv.hostPlatform.system == "x86_64-linux" then "64" else "";
+  libPath = lib.makeLibraryPath [ cups libusb-compat-0_1 ] + ":$out/lib:${stdenv.cc.cc.lib}/lib${appendPath}";
+in stdenv.mkDerivation rec {
+  pname = "samsung-UnifiedLinuxDriver";
+  version = "4.01.17";
+
+  src = fetchurl {
+    url = "http://www.bchemnet.com/suldr/driver/UnifiedLinuxDriver-${version}.tar.gz";
+    sha256 = "1vv3pzvqpg1dq3xjr8161x2yp3v7ca75vil56ranhw5pkjwq66x0";
+  };
+
+  dontPatchELF = true;
+  dontStrip = true;
+
+  installPhase = ''
+    cd Linux/${installationPath}
+    mkdir -p $out/lib/cups/{backend,filter}
+    install -Dm755 mfp $out/lib/cups/backend/
+    install -Dm755 pstosecps pstospl pstosplc rastertospl rastertosplc $out/lib/cups/filter/
+    install -Dm755 libscmssc.so $out/lib/
+
+    GLOBIGNORE=*.so
+    for exe in $out/lib/cups/**/*; do
+      echo "Patching $exe"
+      patchelf \
+        --set-rpath ${libPath} \
+        --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
+        $exe
+    done
+    unset GLOBIGNORE
+
+    install -v at_root/usr/lib${appendPath}/libmfp.so.1.0.1 $out/lib
+    cd $out/lib
+    ln -s -f libmfp.so.1.0.1 libmfp.so.1
+    ln -s -f libmfp.so.1 libmfp.so
+
+    for lib in $out/lib/*.so; do
+      echo "Patching $lib"
+      patchelf \
+        --set-rpath ${libPath} \
+        $lib
+    done
+
+    mkdir -p $out/share/cups/model/samsung
+    cd -
+    cd ../noarch/at_opt/share/ppd
+    for i in *.ppd; do
+      sed -i $i -e \
+        "s,pstosecps,$out/lib/cups/filter/pstosecps,g; \
+         s,pstospl,$out/lib/cups/filter/pstospl,g; \
+         s,rastertospl,$out/lib/cups/filter/rastertospl,g"
+    done;
+    cp -r ./* $out/share/cups/model/samsung
+  '';
+
+  meta = with lib; {
+    description = "Samsung's Linux printing drivers; includes binaries without source code";
+    homepage = "http://www.samsung.com/";
+    license = licenses.unfree;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ joko ];
+  };
+}
diff --git a/nixpkgs/pkgs/misc/cups/drivers/splix/default.nix b/nixpkgs/pkgs/misc/cups/drivers/splix/default.nix
new file mode 100644
index 000000000000..1125e7697112
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/splix/default.nix
@@ -0,0 +1,55 @@
+{ lib, stdenv, fetchsvn, fetchurl, cups, cups-filters, jbigkit, zlib }:
+
+let
+
+  color-profiles = stdenv.mkDerivation {
+    name = "splix-color-profiles-20070625";
+
+    src = fetchurl {
+      url = "http://splix.ap2c.org/samsung_cms.tar.bz2";
+      sha256 = "1156flics5m9m7a4hdmcc2nphbdyary6dfmbcrmsp9xb7ivsypdl";
+    };
+
+    phases = [ "unpackPhase" "installPhase" ];
+
+    installPhase = ''
+      mkdir -p $out/share/cups/profiles/samsung
+      cp * $out/share/cups/profiles/samsung/
+    '';
+  };
+
+in stdenv.mkDerivation rec {
+  name = "splix-svn-${rev}";
+  rev = "315";
+
+  src = fetchsvn {
+    # We build this from svn, because splix hasn't been in released in several years
+    # although the community has been adding some new printer models.
+    url = "svn://svn.code.sf.net/p/splix/code/splix";
+    inherit rev;
+    sha256 = "16wbm4xnz35ca3mw2iggf5f4jaxpyna718ia190ka6y4ah932jxl";
+  };
+
+  postPatch = ''
+    mv -v *.ppd ppd/
+    substituteInPlace src/pstoqpdl.cpp \
+      --replace "RASTERDIR \"/\" RASTERTOQPDL" "\"$out/lib/cups/filter/rastertoqpdl\"" \
+      --replace "RASTERDIR" "\"${cups-filters}/lib/cups/filter\"" \
+  '';
+
+  makeFlags = [
+    "CUPSFILTER=$(out)/lib/cups/filter"
+    "CUPSPPD=$(out)/share/cups/model"
+    "CUPSPROFILE=${color-profiles}/share/cups/profiles"
+  ];
+
+  buildInputs = [ cups zlib jbigkit ];
+
+  meta = with lib; {
+    description = "CUPS drivers for SPL (Samsung Printer Language) printers";
+    homepage = "http://splix.ap2c.org";
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ jfrankenau peti ];
+  };
+}
diff --git a/nixpkgs/pkgs/misc/cups/drivers/zj-58/default.nix b/nixpkgs/pkgs/misc/cups/drivers/zj-58/default.nix
new file mode 100644
index 000000000000..0e2534997e35
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/drivers/zj-58/default.nix
@@ -0,0 +1,28 @@
+{lib, stdenv, fetchFromGitHub, cups}:
+
+stdenv.mkDerivation {
+  pname = "cups-zj-58";
+  version = "2018-02-22";
+
+  src = fetchFromGitHub {
+    owner = "klirichek";
+    repo = "zj-58";
+    rev = "e4212cd";
+    sha256 = "1w2qkspm4qqg5h8n6gmakzhiww7gag64chvy9kf89xsl3wsyp6pi";
+  };
+
+  buildInputs = [ cups ];
+
+  installPhase = ''
+    install -D rastertozj $out/lib/cups/filter/rastertozj
+    install -D ZJ-58.ppd $out/share/cups/model/zjiang/ZJ-58.ppd
+  '';
+
+  meta = with lib; {
+    description = "CUPS filter for thermal printer Zjiang ZJ-58";
+    homepage = "https://github.com/klirichek/zj-58";
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ makefu ];
+    license = licenses.bsd2;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/cups/filters.nix b/nixpkgs/pkgs/misc/cups/filters.nix
new file mode 100644
index 000000000000..8b1e7fe8fc70
--- /dev/null
+++ b/nixpkgs/pkgs/misc/cups/filters.nix
@@ -0,0 +1,71 @@
+{ lib, stdenv, fetchurl, pkg-config, cups, poppler, poppler_utils, fontconfig
+, libjpeg, libpng, perl, ijs, qpdf, dbus, avahi
+, makeWrapper, coreutils, gnused, bc, gawk, gnugrep, which, ghostscript
+, mupdf
+}:
+
+let
+  binPath = lib.makeBinPath [ coreutils gnused bc gawk gnugrep which ];
+
+in stdenv.mkDerivation rec {
+  pname = "cups-filters";
+  version = "1.25.12";
+
+  src = fetchurl {
+    url = "https://openprinting.org/download/cups-filters/${pname}-${version}.tar.xz";
+    sha256 = "1kv25011iyzvd33n5zmmn1z2p6pzk26hmmw6qvjjnx8p3sp7raqn";
+  };
+
+  nativeBuildInputs = [ pkg-config makeWrapper ];
+
+  buildInputs = [
+    cups poppler poppler_utils fontconfig libjpeg libpng perl
+    ijs qpdf dbus avahi ghostscript mupdf
+  ];
+
+  configureFlags = [
+    # TODO(Profpatsch): mupdf support
+    "--with-pdftops=pdftops"
+    "--with-pdftops-path=${poppler_utils}/bin/pdftops"
+    "--with-gs-path=${ghostscript}/bin/gs"
+    "--with-pdftocairo-path=${poppler_utils}/bin/pdftocairo"
+    "--with-ippfind-path=${cups}/bin/ippfind"
+    "--enable-imagefilters"
+    "--with-rcdir=no"
+    "--with-shell=${stdenv.shell}"
+    "--with-test-font-path=/path-does-not-exist"
+  ];
+
+  makeFlags = [ "CUPS_SERVERBIN=$(out)/lib/cups" "CUPS_DATADIR=$(out)/share/cups" "CUPS_SERVERROOT=$(out)/etc/cups" ];
+
+  postConfigure =
+    ''
+      # Ensure that bannertopdf can find the PDF templates in
+      # $out. (By default, it assumes that cups and cups-filters are
+      # installed in the same prefix.)
+      substituteInPlace config.h --replace ${cups.out}/share/cups/data $out/share/cups/data
+
+      # Ensure that gstoraster can find gs in $PATH.
+      substituteInPlace filter/gstoraster.c --replace execve execvpe
+
+      # Patch shebangs of generated build scripts
+      patchShebangs filter
+    '';
+
+  postInstall =
+    ''
+      for i in $out/lib/cups/filter/*; do
+        wrapProgram "$i" --prefix PATH ':' ${binPath}
+      done
+    '';
+
+  enableParallelBuilding = true;
+  doCheck = false; # fails 4 out of 6 tests
+
+  meta = {
+    homepage = "http://www.linuxfoundation.org/collaborate/workgroups/openprinting/cups-filters";
+    description = "Backends, filters, and other software that was once part of the core CUPS distribution but is no longer maintained by Apple Inc";
+    license = lib.licenses.gpl2;
+    platforms = lib.platforms.linux;
+  };
+}