1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2018 Arun Isaac <arunisaac@systemreboot.net>
3 ;;; Copyright © 2020 Tobias Geerinckx-Rice <me@tobias.gr>
4 ;;; Copyright © 2021 Brice Waegeneire <brice@waegenei.re>
6 ;;; This file is part of GNU Guix.
8 ;;; GNU Guix is free software; you can redistribute it and/or modify it
9 ;;; under the terms of the GNU General Public License as published by
10 ;;; the Free Software Foundation; either version 3 of the License, or (at
11 ;;; your option) any later version.
13 ;;; GNU Guix is distributed in the hope that it will be useful, but
14 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;;; GNU General Public License for more details.
18 ;;; You should have received a copy of the GNU General Public License
19 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
21 (define-module (gnu services security-token)
22 #:use-module (gnu services)
23 #:use-module (gnu services shepherd)
24 #:use-module (gnu packages admin)
25 #:use-module (gnu packages base)
26 #:use-module (gnu packages security-token)
27 #:use-module (gnu system shadow)
28 #:use-module (guix gexp)
29 #:use-module (guix modules)
30 #:use-module (guix records)
31 #:use-module (ice-9 match)
32 #:use-module (srfi srfi-26)
33 #:export (pcscd-configuration
35 pcscd-configuration-pcsc-lite
36 pcscd-configuration-usb-drivers
40 ;;; PC/SC Smart Card Daemon
43 (define-record-type* <pcscd-configuration>
44 pcscd-configuration make-pcscd-configuration pcscd-configuration?
45 (pcsc-lite pcscd-configuration-pcsc-lite
47 (usb-drivers pcscd-configuration-usb-drivers
48 (default (list ccid))))
50 (define pcscd-shepherd-service
52 (($ <pcscd-configuration> pcsc-lite)
53 (with-imported-modules (source-module-closure
54 '((gnu build shepherd)))
56 (documentation "PC/SC Smart Card Daemon")
58 (requirement '(syslogd))
59 (modules '((gnu build shepherd)))
61 (let ((socket "/run/pcscd/pcscd.comm"))
62 (when (file-exists? socket)
63 (delete-file socket)))
64 (invoke #$(file-append pcsc-lite "/sbin/pcscd"))
65 (call-with-input-file "/run/pcscd/pcscd.pid" read)))
66 (stop #~(make-kill-destructor)))))))
68 (define pcscd-activation
70 (($ <pcscd-configuration> pcsc-lite usb-drivers)
71 (with-imported-modules (source-module-closure
72 '((guix build utils)))
74 (use-modules (guix build utils))
75 ;; XXX: We can't use (guix utils) because it requires a
76 ;; dynamically-linked Guile, hence the duplicate switch-symlinks.
77 (define (switch-symlinks link target)
78 (let ((pivot (string-append link ".new")))
79 (symlink target pivot)
80 (rename-file pivot link)))
82 (switch-symlinks "/var/lib/pcsc"
85 (map (cut file-append <> "/pcsc")
88 (define pcscd-service-type
92 "Run @command{pcscd}, the PC/SC smart card daemon.")
94 (list (service-extension shepherd-root-service-type
95 (compose list pcscd-shepherd-service))
96 (service-extension activation-service-type
98 (default-value (pcscd-configuration))))