projects/guix·blob kernel-updates · refs

95 lines · 3.5 KiB

1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2018, 2022 Arun Isaac <[email protected]>
3;;; Copyright © 2020 Tobias Geerinckx-Rice <[email protected]>
4;;; Copyright © 2021 Brice Waegeneire <[email protected]>
5;;;
6;;; This file is part of GNU Guix.
7;;;
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.
12;;;
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.
17;;;
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/>.
20
21(define-module (gnu services security-token)
22 #:use-module (gnu services)
23 #:use-module (gnu services dbus)
24 #:use-module (gnu services shepherd)
25 #:use-module (gnu packages admin)
26 #:use-module (gnu packages base)
27 #:use-module (gnu packages security-token)
28 #:use-module (gnu system shadow)
29 #:use-module (guix gexp)
30 #:use-module (guix modules)
31 #:use-module (guix records)
32 #:use-module (ice-9 match)
33 #:use-module (srfi srfi-26)
34 #:export (pcscd-configuration
35 pcscd-configuration?
36 pcscd-configuration-pcsc-lite
37 pcscd-configuration-usb-drivers
38 pcscd-service-type))
39
40;;;
41;;; PC/SC Smart Card Daemon
42;;;
43
44(define-record-type* <pcscd-configuration>
45 pcscd-configuration make-pcscd-configuration pcscd-configuration?
46 (pcsc-lite pcscd-configuration-pcsc-lite
47 (default pcsc-lite))
48 (usb-drivers pcscd-configuration-usb-drivers
49 (default (list ccid))))
50
51(define pcscd-shepherd-service
52 (match-lambda
53 (($ <pcscd-configuration> pcsc-lite)
54 (shepherd-service
55 (documentation "PC/SC Smart Card Daemon")
56 (provision '(pcscd))
57 (requirement '(user-processes syslogd))
58 (start #~(lambda _
59 (let ((socket "/run/pcscd/pcscd.comm"))
60 (when (file-exists? socket)
61 (delete-file socket)))
62 (fork+exec-command
63 (list #$(file-append pcsc-lite "/sbin/pcscd")
64 "--foreground")
65 #:log-file "/var/log/pcscd.log")))
66 (stop #~(make-kill-destructor))))))
67
68(define pcscd-activation
69 (match-lambda
70 (($ <pcscd-configuration> pcsc-lite usb-drivers)
71 (with-imported-modules (source-module-closure
72 '((guix build utils)))
73 #~(begin
74 (use-modules (guix build utils))
75
76 (mkdir-p "/var/lib")
77 (switch-symlinks "/var/lib/pcsc"
78 #$(directory-union
79 "pcsc"
80 (map (cut file-append <> "/pcsc")
81 usb-drivers))))))))
82
83(define pcscd-service-type
84 (service-type
85 (name 'pcscd)
86 (description
87 "Run @command{pcscd}, the PC/SC smart card daemon.")
88 (extensions
89 (list (service-extension shepherd-root-service-type
90 (compose list pcscd-shepherd-service))
91 (service-extension activation-service-type
92 pcscd-activation)
93 (service-extension polkit-service-type
94 (compose list pcscd-configuration-pcsc-lite))))
95 (default-value (pcscd-configuration))))