nixos/pcscd: Improve and clean up module

So far the module only allowed for the ccid driver, but there are a lot
of other PCSC driver modules out there, so let's add an option called
"plugins", which boils down to a store path that links together all the
paths specified.

We don't need to create stuff in /var/lib/pcsc anymore, because we
patched pcsclite to allow setting PCSCLITE_HP_DROPDIR.

Another new option is readerConfig, which is especially useful for
non-USB readers that aren't autodetected.

The systemd service now is no longer Type=forking, because we're now
passing the -f (foreground) option to pcscd.

Tested against a YubiKey 4, SCR335 and a REINER SCT USB reader.

Signed-off-by: aszlig <aszlig@redmoonstudios.org>
Cc: @wkennington

aszlig 9720e16a bc877d8b

+34 -19
+34 -19
nixos/modules/services/hardware/pcscd.nix
··· 1 1 { config, lib, pkgs, ... }: 2 2 3 + with lib; 4 + 3 5 let 4 - cfgFile = pkgs.writeText "reader.conf" ""; 5 - in 6 + cfgFile = pkgs.writeText "reader.conf" config.services.pcscd.readerConfig; 6 7 7 - with lib; 8 + pluginEnv = pkgs.buildEnv { 9 + name = "pcscd-plugins"; 10 + paths = map (p: "${p}/pcsc/drivers") config.services.pcscd.plugins; 11 + }; 8 12 9 - { 13 + in { 10 14 11 15 ###### interface 12 16 13 17 options = { 14 18 15 19 services.pcscd = { 20 + enable = mkEnableOption "PCSC-Lite daemon"; 16 21 17 - enable = mkOption { 18 - default = false; 19 - description = "Whether to enable the PCSC-Lite daemon."; 22 + plugins = mkOption { 23 + type = types.listOf types.package; 24 + default = [ pkgs.ccid ]; 25 + defaultText = "[ pkgs.ccid ]"; 26 + example = literalExample "[ pkgs.pcsc-cyberjack ]"; 27 + description = "Plugin packages to be used for PCSC-Lite."; 20 28 }; 21 29 30 + readerConfig = mkOption { 31 + type = types.lines; 32 + default = ""; 33 + example = '' 34 + FRIENDLYNAME "Some serial reader" 35 + DEVICENAME /dev/ttyS0 36 + LIBPATH /path/to/serial_reader.so 37 + CHANNELID 1 38 + ''; 39 + description = '' 40 + Configuration for devices that aren't hotpluggable. 41 + 42 + See <citerefentry><refentrytitle>reader.conf</refentrytitle> 43 + <manvolnum>5</manvolnum></citerefentry> for valid options. 44 + ''; 45 + }; 22 46 }; 23 - 24 47 }; 25 - 26 48 27 49 ###### implementation 28 50 ··· 37 59 38 60 systemd.services.pcscd = { 39 61 description = "PCSC-Lite daemon"; 40 - preStart = '' 41 - mkdir -p /var/lib/pcsc 42 - rm -Rf /var/lib/pcsc/drivers 43 - ln -s ${pkgs.ccid}/pcsc/drivers /var/lib/pcsc/ 44 - ''; 62 + environment.PCSCLITE_HP_DROPDIR = pluginEnv; 45 63 serviceConfig = { 46 - Type = "forking"; 47 - ExecStart = "${pkgs.pcsclite}/sbin/pcscd --auto-exit -c ${cfgFile}"; 48 - ExecReload = "${pkgs.pcsclite}/sbin/pcscd --hotplug"; 64 + ExecStart = "${pkgs.pcsclite}/sbin/pcscd -f -x -c ${cfgFile}"; 65 + ExecReload = "${pkgs.pcsclite}/sbin/pcscd -H"; 49 66 }; 50 67 }; 51 - 52 68 }; 53 - 54 69 }