{ 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). If scanbd is enabled, then saned must be disabled. ''; }; 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"; home = "/var/lib/scanner"; createHome = true; }; 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"; }; }; }; }