Skip to content

Commit

Permalink
nixos/hardware.sane.brscan5: remove with lib;
Browse files Browse the repository at this point in the history
  • Loading branch information
Stunkymonkey committed Dec 8, 2024
1 parent 5cbb902 commit bbea258
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions nixos/modules/services/hardware/sane_extra_backends/brscan5.nix
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
{ config, lib, pkgs, ... }:

with lib;

let
cfg = config.hardware.sane.brscan5;

netDeviceList = attrValues cfg.netDevices;
netDeviceList = lib.attrValues cfg.netDevices;

etcFiles = pkgs.callPackage ./brscan5_etc_files.nix { netDevices = netDeviceList; };

netDeviceOpts = { name, ... }: {

options = {

name = mkOption {
type = types.str;
name = lib.mkOption {
type = lib.types.str;
description = ''
The friendly name you give to the network device. If undefined,
the name of attribute will be used.
Expand All @@ -23,17 +20,17 @@ let
example = "office1";
};

model = mkOption {
type = types.str;
model = lib.mkOption {
type = lib.types.str;
description = ''
The model of the network device.
'';

example = "ADS-1200";
};

ip = mkOption {
type = with types; nullOr str;
ip = lib.mkOption {
type = with lib.types; nullOr str;
default = null;
description = ''
The ip address of the device. If undefined, you will have to
Expand All @@ -43,8 +40,8 @@ let
example = "192.168.1.2";
};

nodename = mkOption {
type = with types; nullOr str;
nodename = lib.mkOption {
type = with lib.types; nullOr str;
default = null;
description = ''
The node name of the device. If undefined, you will have to
Expand All @@ -58,7 +55,7 @@ let


config =
{ name = mkDefault name;
{ name = lib.mkDefault name;
};
};

Expand All @@ -68,23 +65,23 @@ in
options = {

hardware.sane.brscan5.enable =
mkEnableOption "the Brother brscan5 sane backend";
lib.mkEnableOption "the Brother brscan5 sane backend";

hardware.sane.brscan5.netDevices = mkOption {
hardware.sane.brscan5.netDevices = lib.mkOption {
default = {};
example =
{ office1 = { model = "MFC-7860DW"; ip = "192.168.1.2"; };
office2 = { model = "MFC-7860DW"; nodename = "BRW0080927AFBCE"; };
};
type = with types; attrsOf (submodule netDeviceOpts);
type = with lib.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) {
config = lib.mkIf (config.hardware.sane.enable && cfg.enable) {

hardware.sane.extraBackends = [
pkgs.brscan5
Expand All @@ -97,7 +94,7 @@ in
environment.etc."sane.d/dll.d/brother5.conf".source = "${pkgs.brscan5}/etc/sane.d/dll.d/brother5.conf";

assertions = [
{ assertion = all (x: !(null != x.ip && null != x.nodename)) netDeviceList;
{ assertion = lib.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`
Expand Down

0 comments on commit bbea258

Please sign in to comment.