Added module for scanbd

This commit is contained in:
fleaz 2024-03-24 17:55:38 +01:00
parent 668d7e83b0
commit 8394729396
No known key found for this signature in database
GPG key ID: AED15F8FDD04D083
2 changed files with 135 additions and 0 deletions

View file

@ -3,5 +3,6 @@
#./gotosocial.nix #./gotosocial.nix
./matrix-alertmanager-receiver.nix ./matrix-alertmanager-receiver.nix
#./mealie.nix #./mealie.nix
./scanbd.nix
]; ];
} }

134
modules/scanbd.nix Normal file
View file

@ -0,0 +1,134 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.scanbd;
configDir = "/etc/scanbd";
scanbdConf = pkgs.writeText "scanbd.conf"
''
global {
debug = true
debug-level = ${toString cfg.debugLevel}
user = ${cfg.user}
group = ${cfg.group}
scriptdir = ${configDir}/scripts
pidfile = ${cfg.pidFile}
timeout = ${toString cfg.timeOut}
environment {
device = "SCANBD_DEVICE"
action = "SCANBD_ACTION"
}
multiple_actions = true
${cfg.extraConfig}
}
'';
in
{
options = {
services.scanbd.enable = mkOption {
type = types.bool;
default = false;
description = ''
Enable support for scanbd (scanner button daemon).
<note><para>
If scanbd is enabled, then saned must be disabled.
</para></note>
'';
};
services.scanbd.user = mkOption {
type = types.str;
default = "scanner";
example = "";
description = ''
scanbd daemon user name.
'';
};
services.scanbd.group = mkOption {
type = types.str;
default = "scanner";
example = "";
description = ''
scanbd daemon group name.
'';
};
services.scanbd.extraConfig = mkOption {
type = types.lines;
default = "";
example = ''
device canon {
filter = "^genesys.*"
desc = "Canon LIDE"
action file {
filter = "^file.*"
desc = "File"
script = "copy.script"
}
}
'';
description = ''
Extra configuration lines included verbatim in scanbd.conf.
Use e.g. in lieu of including device-specific config templates
under scanner.d/
'';
};
services.scanbd.pidFile = mkOption {
type = types.str;
default = "/var/run/scanbd.pid";
example = "";
description = ''
PID file path.
'';
};
services.scanbd.timeOut = mkOption {
type = types.int;
default = 500;
example = "";
description = ''
Device polling timeout (in ms).
'';
};
services.scanbd.debugLevel = mkOption {
type = types.int;
default = 3;
example = "";
description = ''
Debug logging (1=error, 2=warn, 3=info, 4-7=debug)
'';
};
};
###### implementation
config = mkIf config.services.scanbd.enable {
users.groups.scanner.gid = config.ids.gids.scanner;
users.users.scanner = {
uid = config.ids.uids.scanner;
group = "scanner";
};
environment.etc."scanbd/scanbd.conf".source = scanbdConf;
environment.etc."scanbd/scripts/test.script".source = "${pkgs.scanbd}/etc/scanbd/test.script";
systemd.services.scanbd = {
description = "Scanner button polling service";
wantedBy = [ "multi-user.target" ];
aliases=["dbus-de.kmux.scanbd.server.service"];
serviceConfig = {
ExecStart = "${pkgs.scanbd}/bin/scanbd -f -c ${configDir}/scanbd.conf";
};
};
};
}