2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
2024-02-29 20:09:43 +00:00
|
|
|
cfg = config.services.pcscd;
|
2020-04-24 23:36:52 +00:00
|
|
|
cfgFile = pkgs.writeText "reader.conf" config.services.pcscd.readerConfig;
|
|
|
|
|
2022-11-02 22:02:43 +00:00
|
|
|
package = if config.security.polkit.enable
|
|
|
|
then pkgs.pcscliteWithPolkit
|
|
|
|
else pkgs.pcsclite;
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
pluginEnv = pkgs.buildEnv {
|
|
|
|
name = "pcscd-plugins";
|
|
|
|
paths = map (p: "${p}/pcsc/drivers") config.services.pcscd.plugins;
|
|
|
|
};
|
|
|
|
|
2021-04-26 19:14:03 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options.services.pcscd = {
|
2022-09-09 14:08:57 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "PCSC-Lite daemon");
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-04-26 19:14:03 +00:00
|
|
|
plugins = mkOption {
|
|
|
|
type = types.listOf types.package;
|
2021-10-06 13:57:05 +00:00
|
|
|
defaultText = literalExpression "[ pkgs.ccid ]";
|
|
|
|
example = literalExpression "[ pkgs.pcsc-cyberjack ]";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Plugin packages to be used for PCSC-Lite.";
|
2021-04-26 19:14:03 +00:00
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-04-26 19:14:03 +00:00
|
|
|
readerConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
example = ''
|
|
|
|
FRIENDLYNAME "Some serial reader"
|
|
|
|
DEVICENAME /dev/ttyS0
|
|
|
|
LIBPATH /path/to/serial_reader.so
|
|
|
|
CHANNELID 1
|
|
|
|
'';
|
2022-08-21 13:32:41 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-04-26 19:14:03 +00:00
|
|
|
Configuration for devices that aren't hotpluggable.
|
|
|
|
|
2022-08-21 13:32:41 +00:00
|
|
|
See {manpage}`reader.conf(5)` for valid options.
|
2021-04-26 19:14:03 +00:00
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2024-02-29 20:09:43 +00:00
|
|
|
|
|
|
|
extraArgs = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ ];
|
|
|
|
description = lib.mdDoc "Extra command line arguments to be passed to the PCSC daemon.";
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf config.services.pcscd.enable {
|
2021-04-26 19:14:03 +00:00
|
|
|
environment.etc."reader.conf".source = cfgFile;
|
|
|
|
|
2024-02-29 20:09:43 +00:00
|
|
|
environment.systemPackages = [ package ];
|
|
|
|
systemd.packages = [ package ];
|
2021-04-26 19:14:03 +00:00
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
services.pcscd.plugins = [ pkgs.ccid ];
|
|
|
|
|
2021-04-26 19:14:03 +00:00
|
|
|
systemd.sockets.pcscd.wantedBy = [ "sockets.target" ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
systemd.services.pcscd = {
|
|
|
|
environment.PCSCLITE_HP_DROPDIR = pluginEnv;
|
2021-05-03 20:48:10 +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
|
2024-02-29 20:09:43 +00:00
|
|
|
serviceConfig.ExecStart = [ "" "${lib.getExe package} -f -x -c ${cfgFile} ${lib.escapeShellArgs cfg.extraArgs}" ];
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|