From 83947293966a99621d28fdfe05dd92ca33528574 Mon Sep 17 00:00:00 2001 From: fleaz Date: Sun, 24 Mar 2024 17:55:38 +0100 Subject: [PATCH] Added module for scanbd --- modules/default.nix | 1 + modules/scanbd.nix | 134 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 135 insertions(+) create mode 100644 modules/scanbd.nix diff --git a/modules/default.nix b/modules/default.nix index c3a784d..295601a 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -3,5 +3,6 @@ #./gotosocial.nix ./matrix-alertmanager-receiver.nix #./mealie.nix + ./scanbd.nix ]; } diff --git a/modules/scanbd.nix b/modules/scanbd.nix new file mode 100644 index 0000000..e57bdb4 --- /dev/null +++ b/modules/scanbd.nix @@ -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). + + + 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"; + }; + + 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"; + }; + }; + }; +}