2021-05-21 12:59:30 -05:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.hardware.sane.brscan5;
|
|
|
|
|
|
|
|
netDeviceList = attrValues cfg.netDevices;
|
|
|
|
|
|
|
|
etcFiles = pkgs.callPackage ./brscan5_etc_files.nix { netDevices = netDeviceList; };
|
|
|
|
|
|
|
|
netDeviceOpts =
|
|
|
|
{ name, ... }:
|
|
|
|
{
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
name = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = ''
|
|
|
|
The friendly name you give to the network device. If undefined,
|
|
|
|
the name of attribute will be used.
|
|
|
|
'';
|
|
|
|
|
2021-10-03 18:06:03 +02:00
|
|
|
example = "office1";
|
2021-05-21 12:59:30 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
model = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = ''
|
|
|
|
The model of the network device.
|
|
|
|
'';
|
|
|
|
|
2021-10-03 18:06:03 +02:00
|
|
|
example = "ADS-1200";
|
2021-05-21 12:59:30 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
ip = mkOption {
|
|
|
|
type = with types; nullOr str;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
The ip address of the device. If undefined, you will have to
|
|
|
|
provide a nodename.
|
|
|
|
'';
|
|
|
|
|
2021-10-03 18:06:03 +02:00
|
|
|
example = "192.168.1.2";
|
2021-05-21 12:59:30 -05:00
|
|
|
};
|
|
|
|
|
2021-10-03 18:06:03 +02:00
|
|
|
nodename = mkOption {
|
|
|
|
type = with types; nullOr str;
|
2021-05-21 12:59:30 -05:00
|
|
|
default = null;
|
|
|
|
description = ''
|
2021-10-03 18:06:03 +02:00
|
|
|
The node name of the device. If undefined, you will have to
|
2021-05-21 12:59:30 -05:00
|
|
|
provide an ip.
|
|
|
|
'';
|
|
|
|
|
2021-10-03 18:06:03 +02:00
|
|
|
example = "BRW0080927AFBCE";
|
2021-05-21 12:59:30 -05:00
|
|
|
};
|
|
|
|
|
2024-12-10 20:29:24 +01:00
|
|
|
};
|
2021-05-21 12:59:30 -05:00
|
|
|
|
|
|
|
config = {
|
|
|
|
name = mkDefault name;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
|
2021-05-28 20:52:14 -05:00
|
|
|
hardware.sane.brscan5.enable = mkEnableOption "the Brother brscan5 sane backend";
|
2021-05-21 12:59:30 -05:00
|
|
|
|
|
|
|
hardware.sane.brscan5.netDevices = mkOption {
|
|
|
|
default = { };
|
|
|
|
example = {
|
|
|
|
office1 = {
|
|
|
|
model = "MFC-7860DW";
|
|
|
|
ip = "192.168.1.2";
|
|
|
|
};
|
|
|
|
office2 = {
|
|
|
|
model = "MFC-7860DW";
|
|
|
|
nodename = "BRW0080927AFBCE";
|
|
|
|
};
|
2024-12-10 20:29:24 +01:00
|
|
|
};
|
2021-05-21 12:59:30 -05:00
|
|
|
type = with types; attrsOf (submodule netDeviceOpts);
|
|
|
|
description = ''
|
|
|
|
The list of network devices that will be registered against the brscan5
|
|
|
|
sane backend.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf (config.hardware.sane.enable && cfg.enable) {
|
|
|
|
|
|
|
|
hardware.sane.extraBackends = [
|
|
|
|
pkgs.brscan5
|
|
|
|
];
|
|
|
|
|
|
|
|
environment.etc."opt/brother/scanner/brscan5" = {
|
|
|
|
source = "${etcFiles}/etc/opt/brother/scanner/brscan5";
|
|
|
|
};
|
|
|
|
environment.etc."opt/brother/scanner/models" = {
|
|
|
|
source = "${etcFiles}/etc/opt/brother/scanner/brscan5/models";
|
|
|
|
};
|
2023-05-01 11:52:21 -07:00
|
|
|
environment.etc."sane.d/dll.d/brother5.conf".source =
|
|
|
|
"${pkgs.brscan5}/etc/sane.d/dll.d/brother5.conf";
|
2021-05-21 12:59:30 -05:00
|
|
|
|
|
|
|
assertions = [
|
|
|
|
{
|
|
|
|
assertion = all (x: !(null != x.ip && null != x.nodename)) netDeviceList;
|
|
|
|
message = ''
|
|
|
|
When describing a network device as part of the attribute list
|
|
|
|
`hardware.sane.brscan5.netDevices`, only one of its `ip` or `nodename`
|
|
|
|
attribute should be specified, not both!
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|