2014-04-14 18:26:48 +04:00
|
|
|
{ config, lib, pkgs, ... }:
|
2011-12-05 21:32:45 +04:00
|
|
|
|
2014-04-14 18:26:48 +04:00
|
|
|
with lib;
|
2011-12-05 21:32:45 +04:00
|
|
|
|
2013-10-30 20:37:45 +04:00
|
|
|
let
|
|
|
|
|
2021-02-19 20:04:09 +03:00
|
|
|
pkg = pkgs.sane-backends;
|
2016-11-11 03:49:02 +03:00
|
|
|
|
|
|
|
sanedConf = pkgs.writeTextFile {
|
|
|
|
name = "saned.conf";
|
|
|
|
destination = "/etc/sane.d/saned.conf";
|
|
|
|
text = ''
|
|
|
|
localhost
|
|
|
|
${config.services.saned.extraConfig}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2016-11-11 04:12:04 +03:00
|
|
|
netConf = pkgs.writeTextFile {
|
|
|
|
name = "net.conf";
|
|
|
|
destination = "/etc/sane.d/net.conf";
|
|
|
|
text = ''
|
|
|
|
${lib.optionalString config.services.saned.enable "localhost"}
|
|
|
|
${config.hardware.sane.netConf}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2016-11-11 03:49:02 +03:00
|
|
|
env = {
|
|
|
|
SANE_CONFIG_DIR = config.hardware.sane.configDir;
|
|
|
|
LD_LIBRARY_PATH = [ "${saneConfig}/lib/sane" ];
|
|
|
|
};
|
|
|
|
|
2016-11-11 04:12:04 +03:00
|
|
|
backends = [ pkg netConf ] ++ optional config.services.saned.enable sanedConf ++ config.hardware.sane.extraBackends;
|
2021-02-19 18:49:49 +03:00
|
|
|
saneConfig = pkgs.mkSaneConfig { paths = backends; inherit (config.hardware.sane) disabledDefaultBackends; };
|
2013-10-30 20:37:45 +04:00
|
|
|
|
2016-11-11 03:49:02 +03:00
|
|
|
enabled = config.hardware.sane.enable || config.services.saned.enable;
|
|
|
|
|
2013-10-30 20:37:45 +04:00
|
|
|
in
|
|
|
|
|
2011-12-05 21:32:45 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
hardware.sane.enable = mkOption {
|
2013-10-30 20:37:45 +04:00
|
|
|
type = types.bool;
|
2011-12-05 21:32:45 +04:00
|
|
|
default = false;
|
2016-02-21 22:55:39 +03:00
|
|
|
description = ''
|
|
|
|
Enable support for SANE scanners.
|
|
|
|
|
|
|
|
<note><para>
|
2017-02-03 20:29:20 +03:00
|
|
|
Users in the "scanner" group will gain access to the scanner, or the "lp" group if it's also a printer.
|
2016-02-21 22:55:39 +03:00
|
|
|
</para></note>
|
|
|
|
'';
|
2011-12-05 21:32:45 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
hardware.sane.snapshot = mkOption {
|
2013-10-30 20:37:45 +04:00
|
|
|
type = types.bool;
|
2011-12-05 21:32:45 +04:00
|
|
|
default = false;
|
|
|
|
description = "Use a development snapshot of SANE scanner drivers.";
|
|
|
|
};
|
|
|
|
|
2014-05-11 22:31:21 +04:00
|
|
|
hardware.sane.extraBackends = mkOption {
|
|
|
|
type = types.listOf types.path;
|
|
|
|
default = [];
|
2016-02-21 22:55:39 +03:00
|
|
|
description = ''
|
|
|
|
Packages providing extra SANE backends to enable.
|
|
|
|
|
|
|
|
<note><para>
|
|
|
|
The example contains the package for HP scanners.
|
|
|
|
</para></note>
|
|
|
|
'';
|
|
|
|
example = literalExample "[ pkgs.hplipWithPlugin ]";
|
2014-05-11 22:31:21 +04:00
|
|
|
};
|
|
|
|
|
2021-02-19 18:49:49 +03:00
|
|
|
hardware.sane.disabledDefaultBackends = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
example = [ "v4l" ];
|
|
|
|
description = ''
|
|
|
|
Names of backends which are enabled by default but should be disabled.
|
|
|
|
See <literal>$SANE_CONFIG_DIR/dll.conf</literal> for the list of possible names.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-06-24 12:52:12 +04:00
|
|
|
hardware.sane.configDir = mkOption {
|
2019-08-08 23:48:27 +03:00
|
|
|
type = types.str;
|
2016-11-11 03:49:02 +03:00
|
|
|
internal = true;
|
2014-06-24 12:52:12 +04:00
|
|
|
description = "The value of SANE_CONFIG_DIR.";
|
|
|
|
};
|
|
|
|
|
2016-11-11 04:12:04 +03:00
|
|
|
hardware.sane.netConf = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
example = "192.168.0.16";
|
|
|
|
description = ''
|
|
|
|
Network hosts that should be probed for remote scanners.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2016-11-11 03:49:02 +03:00
|
|
|
services.saned.enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Enable saned network daemon for remote connection to scanners.
|
2011-12-05 21:32:45 +04:00
|
|
|
|
2016-11-11 03:49:02 +03:00
|
|
|
saned would be runned from <literal>scanner</literal> user; to allow
|
|
|
|
access to hardware that doesn't have <literal>scanner</literal> group
|
|
|
|
you should add needed groups to this user.
|
|
|
|
'';
|
|
|
|
};
|
2011-12-05 21:32:45 +04:00
|
|
|
|
2016-11-11 03:49:02 +03:00
|
|
|
services.saned.extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
example = "192.168.0.0/24";
|
|
|
|
description = ''
|
|
|
|
Extra saned configuration lines.
|
|
|
|
'';
|
|
|
|
};
|
2013-10-30 20:37:45 +04:00
|
|
|
|
2016-11-11 03:49:02 +03:00
|
|
|
};
|
2015-09-24 12:42:32 +03:00
|
|
|
|
2013-10-30 20:37:45 +04:00
|
|
|
|
2016-11-11 03:49:02 +03:00
|
|
|
###### implementation
|
2013-10-30 20:37:45 +04:00
|
|
|
|
2016-11-11 03:49:02 +03:00
|
|
|
config = mkMerge [
|
|
|
|
(mkIf enabled {
|
|
|
|
hardware.sane.configDir = mkDefault "${saneConfig}/etc/sane.d";
|
|
|
|
|
|
|
|
environment.systemPackages = backends;
|
|
|
|
environment.sessionVariables = env;
|
|
|
|
services.udev.packages = backends;
|
|
|
|
|
2019-08-14 00:52:01 +03:00
|
|
|
users.groups.scanner.gid = config.ids.gids.scanner;
|
2016-11-11 03:49:02 +03: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-11-18 22:18:27 +03:00
|
|
|
MaxConnections = 64;
|
2016-11-11 03:49:02 +03:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-08-14 00:52:01 +03:00
|
|
|
users.users.scanner = {
|
2016-11-11 03:49:02 +03:00
|
|
|
uid = config.ids.uids.scanner;
|
|
|
|
group = "scanner";
|
2021-04-12 22:29:49 +03:00
|
|
|
extraGroups = [ "lp" ] ++ optionals config.services.avahi.enable [ "avahi" ];
|
2016-11-11 03:49:02 +03:00
|
|
|
};
|
|
|
|
})
|
|
|
|
];
|
2011-12-05 21:32:45 +04:00
|
|
|
|
|
|
|
}
|