at 21.11-pre 2.2 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 cfgFile = pkgs.writeText "reader.conf" config.services.pcscd.readerConfig; 7 8 pluginEnv = pkgs.buildEnv { 9 name = "pcscd-plugins"; 10 paths = map (p: "${p}/pcsc/drivers") config.services.pcscd.plugins; 11 }; 12 13in 14{ 15 16 ###### interface 17 18 options.services.pcscd = { 19 enable = mkEnableOption "PCSC-Lite daemon"; 20 21 plugins = mkOption { 22 type = types.listOf types.package; 23 default = [ pkgs.ccid ]; 24 defaultText = "[ pkgs.ccid ]"; 25 example = literalExample "[ pkgs.pcsc-cyberjack ]"; 26 description = "Plugin packages to be used for PCSC-Lite."; 27 }; 28 29 readerConfig = mkOption { 30 type = types.lines; 31 default = ""; 32 example = '' 33 FRIENDLYNAME "Some serial reader" 34 DEVICENAME /dev/ttyS0 35 LIBPATH /path/to/serial_reader.so 36 CHANNELID 1 37 ''; 38 description = '' 39 Configuration for devices that aren't hotpluggable. 40 41 See <citerefentry><refentrytitle>reader.conf</refentrytitle> 42 <manvolnum>5</manvolnum></citerefentry> for valid options. 43 ''; 44 }; 45 }; 46 47 ###### implementation 48 49 config = mkIf config.services.pcscd.enable { 50 51 environment.etc."reader.conf".source = cfgFile; 52 53 environment.systemPackages = [ pkgs.pcsclite ]; 54 systemd.packages = [ (getBin pkgs.pcsclite) ]; 55 56 systemd.sockets.pcscd.wantedBy = [ "sockets.target" ]; 57 58 systemd.services.pcscd = { 59 environment.PCSCLITE_HP_DROPDIR = pluginEnv; 60 restartTriggers = [ "/etc/reader.conf" ]; 61 62 # If the cfgFile is empty and not specified (in which case the default 63 # /etc/reader.conf is assumed), pcscd will happily start going through the 64 # entire confdir (/etc in our case) looking for a config file and try to 65 # parse everything it finds. Doesn't take a lot of imagination to see how 66 # well that works. It really shouldn't do that to begin with, but to work 67 # around it, we force the path to the cfgFile. 68 # 69 # https://github.com/NixOS/nixpkgs/issues/121088 70 serviceConfig.ExecStart = [ "" "${getBin pkgs.pcsclite}/bin/pcscd -f -x -c ${cfgFile}" ]; 71 }; 72 }; 73}