1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7 pkg = if config.hardware.sane.snapshot
8 then pkgs.sane-backends-git
9 else pkgs.sane-backends;
10 backends = [ pkg ] ++ config.hardware.sane.extraBackends;
11 saneConfig = pkgs.mkSaneConfig { paths = backends; };
12
13in
14
15{
16
17 ###### interface
18
19 options = {
20
21 hardware.sane.enable = mkOption {
22 type = types.bool;
23 default = false;
24 description = ''
25 Enable support for SANE scanners.
26
27 <note><para>
28 Users in the "scanner" group will gain access to the scanner.
29 </para></note>
30 '';
31 };
32
33 hardware.sane.snapshot = mkOption {
34 type = types.bool;
35 default = false;
36 description = "Use a development snapshot of SANE scanner drivers.";
37 };
38
39 hardware.sane.extraBackends = mkOption {
40 type = types.listOf types.path;
41 default = [];
42 description = ''
43 Packages providing extra SANE backends to enable.
44
45 <note><para>
46 The example contains the package for HP scanners.
47 </para></note>
48 '';
49 example = literalExample "[ pkgs.hplipWithPlugin ]";
50 };
51
52 hardware.sane.configDir = mkOption {
53 type = types.string;
54 description = "The value of SANE_CONFIG_DIR.";
55 };
56
57 };
58
59
60 ###### implementation
61
62 config = mkIf config.hardware.sane.enable {
63
64 hardware.sane.configDir = mkDefault "${saneConfig}/etc/sane.d";
65
66 environment.systemPackages = backends;
67 environment.sessionVariables = {
68 SANE_CONFIG_DIR = config.hardware.sane.configDir;
69 LD_LIBRARY_PATH = [ "${saneConfig}/lib/sane" ];
70 };
71 services.udev.packages = backends;
72
73 users.extraGroups."scanner".gid = config.ids.gids.scanner;
74
75 };
76
77}