1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.hardware.sane.brscan5;
7
8 netDeviceList = attrValues cfg.netDevices;
9
10 etcFiles = pkgs.callPackage ./brscan5_etc_files.nix { netDevices = netDeviceList; };
11
12 netDeviceOpts = { name, ... }: {
13
14 options = {
15
16 name = mkOption {
17 type = types.str;
18 description = lib.mdDoc ''
19 The friendly name you give to the network device. If undefined,
20 the name of attribute will be used.
21 '';
22
23 example = "office1";
24 };
25
26 model = mkOption {
27 type = types.str;
28 description = lib.mdDoc ''
29 The model of the network device.
30 '';
31
32 example = "ADS-1200";
33 };
34
35 ip = mkOption {
36 type = with types; nullOr str;
37 default = null;
38 description = lib.mdDoc ''
39 The ip address of the device. If undefined, you will have to
40 provide a nodename.
41 '';
42
43 example = "192.168.1.2";
44 };
45
46 nodename = mkOption {
47 type = with types; nullOr str;
48 default = null;
49 description = lib.mdDoc ''
50 The node name of the device. If undefined, you will have to
51 provide an ip.
52 '';
53
54 example = "BRW0080927AFBCE";
55 };
56
57 };
58
59
60 config =
61 { name = mkDefault name;
62 };
63 };
64
65in
66
67{
68 options = {
69
70 hardware.sane.brscan5.enable =
71 mkEnableOption (lib.mdDoc "the Brother brscan5 sane backend");
72
73 hardware.sane.brscan5.netDevices = mkOption {
74 default = {};
75 example =
76 { office1 = { model = "MFC-7860DW"; ip = "192.168.1.2"; };
77 office2 = { model = "MFC-7860DW"; nodename = "BRW0080927AFBCE"; };
78 };
79 type = with types; attrsOf (submodule netDeviceOpts);
80 description = lib.mdDoc ''
81 The list of network devices that will be registered against the brscan5
82 sane backend.
83 '';
84 };
85 };
86
87 config = mkIf (config.hardware.sane.enable && cfg.enable) {
88
89 hardware.sane.extraBackends = [
90 pkgs.brscan5
91 ];
92
93 environment.etc."opt/brother/scanner/brscan5" =
94 { source = "${etcFiles}/etc/opt/brother/scanner/brscan5"; };
95 environment.etc."opt/brother/scanner/models" =
96 { source = "${etcFiles}/etc/opt/brother/scanner/brscan5/models"; };
97 environment.etc."sane.d/dll.d/brother5.conf".source = "${pkgs.brscan5}/etc/sane.d/dll.d/brother.conf";
98
99 assertions = [
100 { assertion = all (x: !(null != x.ip && null != x.nodename)) netDeviceList;
101 message = ''
102 When describing a network device as part of the attribute list
103 `hardware.sane.brscan5.netDevices`, only one of its `ip` or `nodename`
104 attribute should be specified, not both!
105 '';
106 }
107 ];
108
109 };
110}