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