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 default = [ pkgs.ccid ];
28 defaultText = literalExpression "[ pkgs.ccid ]";
29 example = literalExpression "[ pkgs.pcsc-cyberjack ]";
30 description = lib.mdDoc "Plugin packages to be used for PCSC-Lite.";
33 readerConfig = mkOption {
37 FRIENDLYNAME "Some serial reader"
39 LIBPATH /path/to/serial_reader.so
42 description = lib.mdDoc ''
43 Configuration for devices that aren't hotpluggable.
45 See {manpage}`reader.conf(5)` for valid options.
52 config = mkIf config.services.pcscd.enable {
54 environment.etc."reader.conf".source = cfgFile;
56 environment.systemPackages = [ package ];
57 systemd.packages = [ (getBin package) ];
59 systemd.sockets.pcscd.wantedBy = [ "sockets.target" ];
61 systemd.services.pcscd = {
62 environment.PCSCLITE_HP_DROPDIR = pluginEnv;
63 restartTriggers = [ "/etc/reader.conf" ];
65 # If the cfgFile is empty and not specified (in which case the default
66 # /etc/reader.conf is assumed), pcscd will happily start going through the
67 # entire confdir (/etc in our case) looking for a config file and try to
68 # parse everything it finds. Doesn't take a lot of imagination to see how
69 # well that works. It really shouldn't do that to begin with, but to work
70 # around it, we force the path to the cfgFile.
72 # https://github.com/NixOS/nixpkgs/issues/121088
73 serviceConfig.ExecStart = [ "" "${getBin package}/bin/pcscd -f -x -c ${cfgFile}" ];