2014-04-14 14:26:48 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2010-01-11 21:56:01 +00:00
|
|
|
|
2016-06-04 11:07:09 +00:00
|
|
|
with lib;
|
|
|
|
|
2014-03-21 22:52:24 +00:00
|
|
|
let
|
2016-06-04 11:07:09 +00:00
|
|
|
cfgFile = pkgs.writeText "reader.conf" config.services.pcscd.readerConfig;
|
2014-03-21 22:52:24 +00:00
|
|
|
|
2016-06-04 11:07:09 +00:00
|
|
|
pluginEnv = pkgs.buildEnv {
|
|
|
|
name = "pcscd-plugins";
|
|
|
|
paths = map (p: "${p}/pcsc/drivers") config.services.pcscd.plugins;
|
|
|
|
};
|
2010-01-11 21:56:01 +00:00
|
|
|
|
2020-09-08 12:32:16 +00:00
|
|
|
in
|
|
|
|
{
|
2010-01-11 21:56:01 +00:00
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
2020-09-08 12:32:16 +00:00
|
|
|
options.services.pcscd = {
|
|
|
|
enable = mkEnableOption "PCSC-Lite daemon";
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2020-09-08 12:32:16 +00:00
|
|
|
plugins = mkOption {
|
|
|
|
type = types.listOf types.package;
|
|
|
|
default = [ pkgs.ccid ];
|
|
|
|
defaultText = "[ pkgs.ccid ]";
|
|
|
|
example = literalExample "[ pkgs.pcsc-cyberjack ]";
|
|
|
|
description = "Plugin packages to be used for PCSC-Lite.";
|
|
|
|
};
|
2016-06-04 11:07:09 +00:00
|
|
|
|
2020-09-08 12:32:16 +00:00
|
|
|
readerConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
example = ''
|
|
|
|
FRIENDLYNAME "Some serial reader"
|
|
|
|
DEVICENAME /dev/ttyS0
|
|
|
|
LIBPATH /path/to/serial_reader.so
|
|
|
|
CHANNELID 1
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Configuration for devices that aren't hotpluggable.
|
|
|
|
|
|
|
|
See <citerefentry><refentrytitle>reader.conf</refentrytitle>
|
|
|
|
<manvolnum>5</manvolnum></citerefentry> for valid options.
|
|
|
|
'';
|
2010-01-11 21:56:01 +00:00
|
|
|
};
|
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2010-01-11 21:56:01 +00:00
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf config.services.pcscd.enable {
|
|
|
|
|
2020-09-08 12:32:16 +00:00
|
|
|
environment.etc."reader.conf".source = cfgFile;
|
|
|
|
|
2021-04-30 08:21:43 +00:00
|
|
|
environment.systemPackages = [ pkgs.pcsclite ];
|
2020-09-08 12:32:16 +00:00
|
|
|
systemd.packages = [ (getBin pkgs.pcsclite) ];
|
|
|
|
|
|
|
|
systemd.sockets.pcscd.wantedBy = [ "sockets.target" ];
|
2014-04-12 02:58:21 +00:00
|
|
|
|
2014-03-21 22:52:24 +00:00
|
|
|
systemd.services.pcscd = {
|
2016-06-04 11:07:09 +00:00
|
|
|
environment.PCSCLITE_HP_DROPDIR = pluginEnv;
|
2020-09-08 12:32:16 +00:00
|
|
|
restartTriggers = [ "/etc/reader.conf" ];
|
2021-04-29 01:17:33 +00:00
|
|
|
|
|
|
|
# If the cfgFile is empty and not specified (in which case the default
|
|
|
|
# /etc/reader.conf is assumed), pcscd will happily start going through the
|
|
|
|
# entire confdir (/etc in our case) looking for a config file and try to
|
|
|
|
# parse everything it finds. Doesn't take a lot of imagination to see how
|
|
|
|
# well that works. It really shouldn't do that to begin with, but to work
|
|
|
|
# around it, we force the path to the cfgFile.
|
|
|
|
#
|
|
|
|
# https://github.com/NixOS/nixpkgs/issues/121088
|
|
|
|
serviceConfig.ExecStart = [ "" "${getBin pkgs.pcsclite}/bin/pcscd -f -x -c ${cfgFile}" ];
|
2014-03-21 22:52:24 +00:00
|
|
|
};
|
2010-01-11 21:56:01 +00:00
|
|
|
};
|
|
|
|
}
|