1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7 pkg = if config.hardware.sane.snapshot then pkgs.saneBackendsGit else pkgs.saneBackends;
8 backends = [ pkg ] ++ config.hardware.sane.extraBackends;
9 saneConfig = pkgs.mkSaneConfig { paths = backends; };
10
11in
12
13{
14
15 ###### interface
16
17 options = {
18
19 hardware.sane.enable = mkOption {
20 type = types.bool;
21 default = false;
22 description = "Enable support for SANE scanners.";
23 };
24
25 hardware.sane.snapshot = mkOption {
26 type = types.bool;
27 default = false;
28 description = "Use a development snapshot of SANE scanner drivers.";
29 };
30
31 hardware.sane.extraBackends = mkOption {
32 type = types.listOf types.path;
33 default = [];
34 description = "Packages providing extra SANE backends to enable.";
35 };
36
37 hardware.sane.configDir = mkOption {
38 type = types.string;
39 description = "The value of SANE_CONFIG_DIR.";
40 };
41
42 };
43
44
45 ###### implementation
46
47 config = mkIf config.hardware.sane.enable {
48
49 hardware.sane.configDir = mkDefault "${saneConfig}/etc/sane.d";
50
51 environment.systemPackages = backends;
52 environment.sessionVariables = {
53 SANE_CONFIG_DIR = config.hardware.sane.configDir;
54 LD_LIBRARY_PATH = [ "${saneConfig}/lib/sane" ];
55 };
56 services.udev.packages = backends;
57
58 users.extraGroups."scanner".gid = config.ids.gids.scanner;
59
60 };
61
62}