1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2018 Arun Isaac <arunisaac@systemreboot.net>
4 ;;; This file is part of GNU Guix.
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19 (define-module (gnu services security-token)
20 #:use-module (gnu services)
21 #:use-module (gnu services shepherd)
22 #:use-module (gnu packages admin)
23 #:use-module (gnu packages base)
24 #:use-module (gnu packages security-token)
25 #:use-module (gnu system shadow)
26 #:use-module (guix gexp)
27 #:use-module (guix modules)
28 #:use-module (guix records)
29 #:use-module (ice-9 match)
30 #:use-module (srfi srfi-26)
31 #:export (pcscd-configuration
33 pcscd-configuration-pcsc-lite
34 pcscd-configuration-usb-drivers
38 ;;; PC/SC Smart Card Daemon
41 (define-record-type* <pcscd-configuration>
42 pcscd-configuration make-pcscd-configuration pcscd-configuration?
43 (pcsc-lite pcscd-configuration-pcsc-lite
45 (usb-drivers pcscd-configuration-usb-drivers
46 (default (list ccid))))
48 (define pcscd-shepherd-service
50 (($ <pcscd-configuration> pcsc-lite)
51 (with-imported-modules (source-module-closure
52 '((gnu build shepherd)))
54 (documentation "PC/SC Smart Card Daemon")
56 (requirement '(syslogd))
57 (modules '((gnu build shepherd)))
59 (invoke #$(file-append pcsc-lite "/sbin/pcscd"))
60 (call-with-input-file "/var/run/pcscd/pcscd.pid" read)))
61 (stop #~(make-kill-destructor)))))))
63 (define pcscd-activation
65 (($ <pcscd-configuration> pcsc-lite usb-drivers)
66 (with-imported-modules (source-module-closure
67 '((guix build utils)))
69 (use-modules (guix build utils))
70 ;; XXX: We can't use (guix utils) because it requires a
71 ;; dynamically-linked Guile, hence the duplicate switch-symlinks.
72 (define (switch-symlinks link target)
73 (let ((pivot (string-append link ".new")))
74 (symlink target pivot)
75 (rename-file pivot link)))
77 (switch-symlinks "/var/lib/pcsc"
80 (map (cut file-append <> "/pcsc")
83 (define pcscd-service-type
87 "Run @command{pcscd}, the PC/SC smart card daemon.")
89 (list (service-extension shepherd-root-service-type
90 (compose list pcscd-shepherd-service))
91 (service-extension activation-service-type
93 (default-value (pcscd-configuration))))