2016-04-30 02:45:21 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.hardware.sane.brscan4;
|
|
|
|
|
|
|
|
netDeviceList = attrValues cfg.netDevices;
|
|
|
|
|
|
|
|
etcFiles = pkgs.callPackage ./brscan4_etc_files.nix { netDevices = netDeviceList; };
|
|
|
|
|
2018-07-20 21:56:59 +01:00
|
|
|
netDeviceOpts = { name, ... }: {
|
2016-04-30 02:45:21 +01:00
|
|
|
|
|
|
|
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 17:06:03 +01:00
|
|
|
example = "office1";
|
2016-04-30 02:45:21 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
model = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = ''
|
|
|
|
The model of the network device.
|
|
|
|
'';
|
|
|
|
|
2021-10-03 17:06:03 +01:00
|
|
|
example = "MFC-7860DW";
|
2016-04-30 02:45:21 +01: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 17:06:03 +01:00
|
|
|
example = "192.168.1.2";
|
2016-04-30 02:45:21 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
nodename = mkOption {
|
|
|
|
type = with types; nullOr str;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
The node name of the device. If undefined, you will have to
|
|
|
|
provide an ip.
|
|
|
|
'';
|
|
|
|
|
2021-10-03 17:06:03 +01:00
|
|
|
example = "BRW0080927AFBCE";
|
2016-04-30 02:45:21 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
config =
|
|
|
|
{ name = mkDefault name;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
|
2019-09-14 18:51:29 +01:00
|
|
|
hardware.sane.brscan4.enable =
|
2016-04-30 02:45:21 +01:00
|
|
|
mkEnableOption "Brother's brscan4 scan backend" // {
|
|
|
|
description = ''
|
|
|
|
When enabled, will automatically register the "brscan4" sane
|
2019-09-14 18:51:29 +01:00
|
|
|
backend and bring configuration files to their expected location.
|
2016-04-30 02:45:21 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
hardware.sane.brscan4.netDevices = mkOption {
|
|
|
|
default = {};
|
|
|
|
example =
|
|
|
|
{ office1 = { model = "MFC-7860DW"; ip = "192.168.1.2"; };
|
|
|
|
office2 = { model = "MFC-7860DW"; nodename = "BRW0080927AFBCE"; };
|
|
|
|
};
|
2020-08-23 00:28:45 +01:00
|
|
|
type = with types; attrsOf (submodule netDeviceOpts);
|
2016-04-30 02:45:21 +01:00
|
|
|
description = ''
|
|
|
|
The list of network devices that will be registered against the brscan4
|
|
|
|
sane backend.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf (config.hardware.sane.enable && cfg.enable) {
|
|
|
|
|
|
|
|
hardware.sane.extraBackends = [
|
|
|
|
pkgs.brscan4
|
|
|
|
];
|
|
|
|
|
2019-09-14 18:51:29 +01:00
|
|
|
environment.etc."opt/brother/scanner/brscan4" =
|
|
|
|
{ source = "${etcFiles}/etc/opt/brother/scanner/brscan4"; };
|
2016-04-30 02:45:21 +01: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.brscan4.netDevices`, only one of its `ip` or `nodename`
|
|
|
|
attribute should be specified, not both!
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
};
|
2016-09-11 08:44:22 +01:00
|
|
|
}
|