1 { config, lib, pkgs, ... }:
6 cfgFile = pkgs.writeText "reader.conf" config.services.pcscd.readerConfig;
8 package = if config.security.polkit.enable
9 then pkgs.pcscliteWithPolkit
12 pluginEnv = pkgs.buildEnv {
13 name = "pcscd-plugins";
14 paths = map (p: "${p}/pcsc/drivers") config.services.pcscd.plugins;
22 options.services.pcscd = {
23 enable = mkEnableOption (lib.mdDoc "PCSC-Lite daemon");
26 type = types.listOf types.package;
27 defaultText = literalExpression "[ pkgs.ccid ]";
28 example = literalExpression "[ pkgs.pcsc-cyberjack ]";
29 description = lib.mdDoc "Plugin packages to be used for PCSC-Lite.";
32 readerConfig = mkOption {
36 FRIENDLYNAME "Some serial reader"
38 LIBPATH /path/to/serial_reader.so
41 description = lib.mdDoc ''
42 Configuration for devices that aren't hotpluggable.
44 See {manpage}`reader.conf(5)` for valid options.
51 config = mkIf config.services.pcscd.enable {
53 environment.etc."reader.conf".source = cfgFile;
55 environment.systemPackages = [ package ];
56 systemd.packages = [ (getBin package) ];
58 services.pcscd.plugins = [ pkgs.ccid ];
60 systemd.sockets.pcscd.wantedBy = [ "sockets.target" ];
62 systemd.services.pcscd = {
63 environment.PCSCLITE_HP_DROPDIR = pluginEnv;
64 restartTriggers = [ "/etc/reader.conf" ];
66 # If the cfgFile is empty and not specified (in which case the default
67 # /etc/reader.conf is assumed), pcscd will happily start going through the
68 # entire confdir (/etc in our case) looking for a config file and try to
69 # parse everything it finds. Doesn't take a lot of imagination to see how
70 # well that works. It really shouldn't do that to begin with, but to work
71 # around it, we force the path to the cfgFile.
73 # https://github.com/NixOS/nixpkgs/issues/121088
74 serviceConfig.ExecStart = [ "" "${getBin package}/bin/pcscd -f -x -c ${cfgFile}" ];