Can't get Brother MFC-J5340DWE to work properly

Hi all

I love NixOS and I want to switch to it full time but have recently had to go back to OpenSUSE Tumbleweed to get some photos to print properly. Don’t get me wrong, I love Tumbleweed and it’s my ‘go-to’ when something isn’t working and I need to get something done but I prefer the way NixOS works.
I have a Brother MFC-J5340DWE printer and although I can get the scanner to work just fine and I can print most things, there are options missing which I need, one of the main ones being the option to change paper type to Photo paper/Glossy which I discovered yesterday when printing some photos which came out with the colour being wrong (a person with a very red face instead of the normal human colour).
I have attached my printer.nix file which I import into my configuration.nix as I’m not sure if I’m missing something or I’ve added the wrong option in or something. I tried reading through how to build a printer package from the .deb or .rpm files on the brother website but couldn’t figure out how to get it to work.

Can someone please help?

{ config, lib, pkgs, modulesPath, ... }:

{
  imports =
    [ (modulesPath + "/installer/scan/not-detected.nix")
<nixpkgs/nixos/modules/services/hardware/sane_extra_backends/brscan5.nix>
    ];


# Enable Printer
hardware.printers = {
  ensureDefaultPrinter = "Brother";
  ensurePrinters = [{
    name = "Brother";
    location = "home";
    model = "MFC-J5340DW";
ppdOptions = {
      pageSize = "A4";
    };
    description = "Brother MFC-J5340DW";
    deviceUri = "ipp://<IP>/ipp";
  }];
};

# Enable Scanner
hardware = {
sane = {
enable = true;
brscan5 = {
enable = true;
netDevices = {
home = { model = "MFC-J5340DW"; ip = "<IP>"; };
};
};
};
};

}

MFC-J3930DW here so not sure how applicable it is, but I had to write my own derivations for the driver — partly based on some other attempt I’ve found in some random repo, but it required quite a bit of additional debugging to figure out why options like paper size don’t get propagated to the printer properly. The biggest issue were the perl scripts not resolving files where those options were defined properly and the simplest solution was just wrapping it into FHS (but some choice patching was also required). It doesn’t work 100% perfectly in that some options need changing in CUPS default to work reliably, but I change them rarely enough I didn’t end up tracking it down yet.

Not sure how helpful that will be for your problem, but figured I might as well share:

I’m using a similar Brother printer. I don’t put anything in configuration.nix and GNOME detects it. I can set paper type and all sort of options. The only problem is that, after a system reconfiguration, the printer configuration becomes stale, and I have to delete the printer from GNOME’s settings. It will reappear after a few seconds and work again.

That’s interesting, Plasma should detect it too - do you have any other printer-related settings in any of your config or just the line that is present in configuration.nix by default?

I’ve made some changes (the path, model number and sha256) but don’t really know what to do with the files now.

Well, they are just two packages, each wrapping the respective part of the driver the cupswrapper one is the one you will want to add to your services.printing.drivers and the lpr one is just a dependency of it. You could include them for example in your nixpkgs overlay, roughly like so:

let
  brotherOvelay = final: prev: {
    mfcj3930dw-cupswrapper = prev.callPackage ./brother/mfcj3930dw-cupswrapper.nix { };
    mfcj3930dw-lpr = prev.pkgsi686Linux.callPackage ./brother/mfcj3930dw-lpr.nix { };
  }
in
  # ...

That said, I’m not sure if you can expect for it to work out-of-the-box for you — the patches I’ve produced were created by modifying the extracted driver until it works and creating a diff of changes. I full expect the Perl code in your driver (or even other parts of it) to be different enough that the patches won’t apply cleanly.

I’ve linked this mostly as an example of what you should try looking at, if you were willing to write a derivation for your driver — most importantly fixing the paths in the Perl code and wrapping the provided binaries in an FHS env. I’m not sure if there is an easier answer than that, at least I couldn’t find one.

No, I don’t have any printer related configuration in configure.nix nor in any other place.