2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
2024-01-02 11:29:13 +00:00
|
|
|
pkg = config.hardware.sane.backends-package.override {
|
2021-08-05 21:33:18 +00:00
|
|
|
scanSnapDriversUnfree = config.hardware.sane.drivers.scanSnap.enable;
|
|
|
|
scanSnapDriversPackage = config.hardware.sane.drivers.scanSnap.package;
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
sanedConf = pkgs.writeTextFile {
|
|
|
|
name = "saned.conf";
|
|
|
|
destination = "/etc/sane.d/saned.conf";
|
|
|
|
text = ''
|
|
|
|
localhost
|
|
|
|
${config.services.saned.extraConfig}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
netConf = pkgs.writeTextFile {
|
|
|
|
name = "net.conf";
|
|
|
|
destination = "/etc/sane.d/net.conf";
|
|
|
|
text = ''
|
|
|
|
${lib.optionalString config.services.saned.enable "localhost"}
|
|
|
|
${config.hardware.sane.netConf}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
env = {
|
2022-12-28 21:21:41 +00:00
|
|
|
SANE_CONFIG_DIR = "/etc/sane-config";
|
2022-11-21 17:40:18 +00:00
|
|
|
LD_LIBRARY_PATH = [ "/etc/sane-libs" ];
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
backends = [ pkg netConf ] ++ optional config.services.saned.enable sanedConf ++ config.hardware.sane.extraBackends;
|
2021-04-05 15:23:46 +00:00
|
|
|
saneConfig = pkgs.mkSaneConfig { paths = backends; inherit (config.hardware.sane) disabledDefaultBackends; };
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
enabled = config.hardware.sane.enable || config.services.saned.enable;
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
hardware.sane.enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-09-09 14:08:57 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Enable support for SANE scanners.
|
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
::: {.note}
|
|
|
|
Users in the "scanner" group will gain access to the scanner, or the "lp" group if it's also a printer.
|
|
|
|
:::
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-01-02 11:29:13 +00:00
|
|
|
hardware.sane.backends-package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.sane-backends;
|
|
|
|
defaultText = literalExpression "pkgs.sane-backends";
|
|
|
|
description = lib.mdDoc "Backends driver package to use.";
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
hardware.sane.snapshot = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Use a development snapshot of SANE scanner drivers.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
hardware.sane.extraBackends = mkOption {
|
|
|
|
type = types.listOf types.path;
|
|
|
|
default = [];
|
2022-09-09 14:08:57 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Packages providing extra SANE backends to enable.
|
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
::: {.note}
|
2022-11-04 12:27:35 +00:00
|
|
|
The example contains the package for HP scanners, and the package for
|
|
|
|
Apple AirScan and Microsoft WSD support (supports many
|
|
|
|
vendors/devices).
|
2022-09-09 14:08:57 +00:00
|
|
|
:::
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
2022-11-04 12:27:35 +00:00
|
|
|
example = literalExpression "[ pkgs.hplipWithPlugin pkgs.sane-airscan ]";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2021-04-05 15:23:46 +00:00
|
|
|
hardware.sane.disabledDefaultBackends = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
example = [ "v4l" ];
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-04-05 15:23:46 +00:00
|
|
|
Names of backends which are enabled by default but should be disabled.
|
2022-08-12 12:06:08 +00:00
|
|
|
See `$SANE_CONFIG_DIR/dll.conf` for the list of possible names.
|
2021-04-05 15:23:46 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
hardware.sane.configDir = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
internal = true;
|
2022-09-09 14:08:57 +00:00
|
|
|
description = lib.mdDoc "The value of SANE_CONFIG_DIR.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
hardware.sane.netConf = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
example = "192.168.0.16";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Network hosts that should be probed for remote scanners.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-08-05 21:33:18 +00:00
|
|
|
hardware.sane.drivers.scanSnap.enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
example = true;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-08-05 21:33:18 +00:00
|
|
|
Whether to enable drivers for the Fujitsu ScanSnap scanners.
|
|
|
|
|
|
|
|
The driver files are unfree and extracted from the Windows driver image.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-01-02 11:29:13 +00:00
|
|
|
hardware.sane.drivers.scanSnap.package = mkPackageOption pkgs [ "sane-drivers" "epjitsu" ] {
|
|
|
|
extraDescription = ''
|
|
|
|
Useful if you want to extract the driver files yourself.
|
2021-08-05 21:33:18 +00:00
|
|
|
|
2024-01-02 11:29:13 +00:00
|
|
|
The process is described in the {file}`/etc/sane.d/epjitsu.conf` file in
|
2022-08-12 12:06:08 +00:00
|
|
|
the `sane-backends` package.
|
2021-08-05 21:33:18 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-12-02 08:20:57 +00:00
|
|
|
hardware.sane.openFirewall = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
Open ports needed for discovery of scanners on the local network, e.g.
|
|
|
|
needed for Canon scanners (BJNP protocol).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
services.saned.enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Enable saned network daemon for remote connection to scanners.
|
|
|
|
|
2022-12-28 21:21:41 +00:00
|
|
|
saned would be run from `scanner` user; to allow
|
2022-08-12 12:06:08 +00:00
|
|
|
access to hardware that doesn't have `scanner` group
|
2020-04-24 23:36:52 +00:00
|
|
|
you should add needed groups to this user.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
services.saned.extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
example = "192.168.0.0/24";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Extra saned configuration lines.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkMerge [
|
|
|
|
(mkIf enabled {
|
|
|
|
hardware.sane.configDir = mkDefault "${saneConfig}/etc/sane.d";
|
|
|
|
|
|
|
|
environment.systemPackages = backends;
|
|
|
|
environment.sessionVariables = env;
|
2022-12-28 21:21:41 +00:00
|
|
|
environment.etc."sane-config".source = config.hardware.sane.configDir;
|
2022-11-21 17:40:18 +00:00
|
|
|
environment.etc."sane-libs".source = "${saneConfig}/lib/sane";
|
2020-04-24 23:36:52 +00:00
|
|
|
services.udev.packages = backends;
|
|
|
|
|
|
|
|
users.groups.scanner.gid = config.ids.gids.scanner;
|
2022-12-02 08:20:57 +00:00
|
|
|
networking.firewall.allowedUDPPorts = mkIf config.hardware.sane.openFirewall [ 8612 ];
|
2020-04-24 23:36:52 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
(mkIf config.services.saned.enable {
|
|
|
|
networking.firewall.connectionTrackingModules = [ "sane" ];
|
|
|
|
|
|
|
|
systemd.services."saned@" = {
|
|
|
|
description = "Scanner Service";
|
|
|
|
environment = mapAttrs (name: val: toString val) env;
|
|
|
|
serviceConfig = {
|
|
|
|
User = "scanner";
|
|
|
|
Group = "scanner";
|
|
|
|
ExecStart = "${pkg}/bin/saned";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.sockets.saned = {
|
|
|
|
description = "saned incoming socket";
|
|
|
|
wantedBy = [ "sockets.target" ];
|
|
|
|
listenStreams = [ "0.0.0.0:6566" "[::]:6566" ];
|
|
|
|
socketConfig = {
|
|
|
|
# saned needs to distinguish between IPv4 and IPv6 to open matching data sockets.
|
|
|
|
BindIPv6Only = "ipv6-only";
|
|
|
|
Accept = true;
|
2020-12-03 08:41:04 +00:00
|
|
|
MaxConnections = 64;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
users.users.scanner = {
|
|
|
|
uid = config.ids.uids.scanner;
|
|
|
|
group = "scanner";
|
2021-04-13 19:44:15 +00:00
|
|
|
extraGroups = [ "lp" ] ++ optionals config.services.avahi.enable [ "avahi" ];
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
|
|
|
}
|