pcscd: allow multiple readerConfig entries

This commit is contained in:
Christoph Honal 2024-07-09 09:43:41 +02:00
parent f6e9c84743
commit 735f85e845

View File

@ -1,11 +1,16 @@
{ config, lib, pkgs, ... }: {
config,
lib,
pkgs,
...
}:
let let
cfg = config.services.pcscd; cfg = config.services.pcscd;
cfgFile = pkgs.writeText "reader.conf" config.services.pcscd.readerConfig; cfgFile = pkgs.writeText "reader.conf" (
builtins.concatStringsSep "\n\n" config.services.pcscd.readerConfigs
);
package = if config.security.polkit.enable package = if config.security.polkit.enable then pkgs.pcscliteWithPolkit else pkgs.pcsclite;
then pkgs.pcscliteWithPolkit
else pkgs.pcsclite;
pluginEnv = pkgs.buildEnv { pluginEnv = pkgs.buildEnv {
name = "pcscd-plugins"; name = "pcscd-plugins";
@ -14,6 +19,20 @@ let
in in
{ {
imports = [
(lib.mkChangedOptionModule
[ "services" "pcscd" "readerConfig" ]
[ "services" "pcscd" "readerConfigs" ]
(
config:
let
readerConfig = lib.getAttrFromPath [ "services" "pcscd" "readerConfig" ] config;
in
[ readerConfig ]
)
)
];
options.services.pcscd = { options.services.pcscd = {
enable = lib.mkEnableOption "PCSC-Lite daemon, to access smart cards using SCard API (PC/SC)"; enable = lib.mkEnableOption "PCSC-Lite daemon, to access smart cards using SCard API (PC/SC)";
@ -24,15 +43,17 @@ in
description = "Plugin packages to be used for PCSC-Lite."; description = "Plugin packages to be used for PCSC-Lite.";
}; };
readerConfig = lib.mkOption { readerConfigs = lib.mkOption {
type = lib.types.lines; type = lib.types.listOf lib.types.lines;
default = ""; default = [ ];
example = '' example = [
''
FRIENDLYNAME "Some serial reader" FRIENDLYNAME "Some serial reader"
DEVICENAME /dev/ttyS0 DEVICENAME /dev/ttyS0
LIBPATH /path/to/serial_reader.so LIBPATH /path/to/serial_reader.so
CHANNELID 1 CHANNELID 1
''; ''
];
description = '' description = ''
Configuration for devices that aren't hotpluggable. Configuration for devices that aren't hotpluggable.
@ -68,7 +89,10 @@ in
# around it, we force the path to the cfgFile. # around it, we force the path to the cfgFile.
# #
# https://github.com/NixOS/nixpkgs/issues/121088 # https://github.com/NixOS/nixpkgs/issues/121088
serviceConfig.ExecStart = [ "" "${lib.getExe package} -f -x -c ${cfgFile} ${lib.escapeShellArgs cfg.extraArgs}" ]; serviceConfig.ExecStart = [
""
"${lib.getExe package} -f -x -c ${cfgFile} ${lib.escapeShellArgs cfg.extraArgs}"
];
}; };
}; };
} }