Scanners

From NixOS Wiki
Revision as of 19:37, 15 October 2020 by imported>Tobias.bora (minor typo)

Installing scanner support

Scanner support is provided by the SANE library. To enable scanner support, amend /etc/nixos/configuration.nix:

{
  ...
  hardware.sane.enable = true;
  ...
}

It is also very likely that users will required to be in the following groups scanner and lp, so you can for example configure it as follow on NixOs (don't forget to login/logout after rebuilding NixOs):

{
  ...
    users.users.YOURUSERNAME.extraGroups = [ "scanner" "lp" ];
  ...
}

Testing scanner support

To determine if your scanner is supported by SANE:

$ scanimage -L

If you can only see scanners when running as root, try adding the user to the scanner or lp either using the configuration given above, or using the following code (beware, don't forget to logout/login after running this command):

$ sudo usermod -a -G scanner,lp username

Supported backends

See the Supported Devices page to see if your scanner is supported. Some backends are proprietary and are not installed by default; see below. You may also be interested by "driverless" scanning (see below) if your scanner support the Apple AirScan and/or the Microsoft WSD, Apple maintains a list of compatible devices here.

Driverless Apple AirScan and Microsoft WSD

A large number of printers now support "driverless" scanning. As explained on the sane-airscan backend project:

Driverless scanning comes in two flavors:

  • Apple AirScan or AirPrint scanning (official protocol name is eSCL)
  • Microsoft WSD, or WS-Scan (term WSD means "Web Services for Devices)

This backend implements both protocols, choosing automatically between them. It was successfully tested with many devices from Brother, Canon, Dell, Kyocera, Lexmark, Epson, HP, Panasonic, Ricoh, Samsung and Xerox both in WSD and eSCL modes.

For eSCL devices, Apple maintains a comprehensive list of compatible devices, but please note, this list contains not only scanners and MFP, but pure printers as well.

To enable Apple AirScan/Microsoft WSD "driverless" scanning: use the sane-airscan drivers:

hardware.sane.extraBackends = [ pkgs.sane-airscan ];

HP

hardware.sane.extraBackends = [ pkgs.hplipWithPlugin ];

Epson

If your scanner is listed as supported by the epkowa backend:

hardware.sane.extraBackends = [ pkgs.epkowa ];

Some other scanners (see list) need the utsushi backend:

hardware.sane.extraBackends = [ pkgs.utsushi ];
services.udev.packages = [ pkgs.utsushi ];

SnapScan firmware

Many scanners require firmware blobs which can be downloaded from the website of the scanner or extracted from the drivers they provide. Once you have the appropriate firmware you need to tell SANE where to find it in your configuration.nix:

{
  hardware.sane.enable = true;
  nixpkgs.config.sane.snapscanFirmware = pkgs.fetchurl {
    # https://wiki.ubuntuusers.de/Scanner/Epson_Perfection/#Unterstuetzte-Geraete
    url = "https://media-cdn.ubuntu-de.org/wiki/attachments/52/46/Esfw41.bin"; #Epson Perfection 2480
    sha256 = "00cv25v4xlrgp3di9bdfd07pffh9jq2j0hncmjv3c65m8bqhjglq";
  };
}

Brother

Brother currently provides four different scanner backends for various generations of its scanners. The newest (brscan4) is supported as a loadable submodule in NixOS. It can be activated by importing the appropriate file into /etc/nixos/configuration.nix:

{
  ...
  imports = [ 
    <nixpkgs/nixos/modules/services/hardware/sane_extra_backends/brscan4.nix>
    ./hardware-configuration.nix
  ];
  ... 
}

Then just add a scanner in the sane module:

{
  ...
  hardware = {
    sane = {
      enable = true;
      brscan4 = {
        enable = true;
        netDevices = {
          home = { model = "MFC-L2700DN"; ip = "192.168.178.23"; };
        };
      };
    };
  };
  ...
}

In some cases, configuration changes may not take effect until after a reboot.

GIMP support

To enable support for scanning in GIMP:

  1. You need to install a special version of xsane, which you can enable by amending /etc/nixos/configuration.nix as follows:
    {
      ...
      nixpkgs.config.packageOverrides = pkgs: {
        xsaneGimp = pkgs.xsane.override { gimpSupport = true; }; 
      };
      ...
    }
    
  2. Rebuild:
    $ sudo nixos-rebuild switch
    
  3. Finally, you will need to manually create a symlink:
    $ ln -s /run/current-system/sw/bin/xsane ~/.gimp-2.8/plug-ins/xsane
    

Network scanning

If NixOs cannot find a scanner located on your network, you may be interested in adding in your configuration.nix:

{
  ...
  services.avahi.enable = true;
  services.avahi.nssmdns = true;
  ...
}

Currently (2017-08-16) the SANE backend does not support overriding according to  nixpkgs issue #17411. The workaround for this is to download michaelrus's sane-extra-config.nix, copy it to /etc/nixos/sane-extra-config.nix and import it in /etc/nixos/configuration.nix as follows:

{
  ...
  imports = [
    ...
    ./sane-extra-config.nix
    ...
  ];
 ...
 hardware.sane.extraConfig."magicolor" = ''
   net 10.0.0.30 0x2098
 ''; # Magicolor 1690mf
 ...
}

Network scanning

See also

Scanner firmware files