gnu: services: Fix the NFS service.
[jackhill/guix/guix.git] / gnu / services / security-token.scm
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 ;;;
5 ;;; This file is part of GNU Guix.
6 ;;;
7 ;;; GNU Guix is free software; you can redistribute it and/or modify it
8 ;;; under the terms of the GNU General Public License as published by
9 ;;; the Free Software Foundation; either version 3 of the License, or (at
10 ;;; your option) any later version.
11 ;;;
12 ;;; GNU Guix is distributed in the hope that it will be useful, but
13 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;;; GNU General Public License for more details.
16 ;;;
17 ;;; You should have received a copy of the GNU General Public License
18 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19
20 (define-module (gnu services security-token)
21 #:use-module (gnu services)
22 #:use-module (gnu services shepherd)
23 #:use-module (gnu packages admin)
24 #:use-module (gnu packages base)
25 #:use-module (gnu packages security-token)
26 #:use-module (gnu system shadow)
27 #:use-module (guix gexp)
28 #:use-module (guix modules)
29 #:use-module (guix records)
30 #:use-module (ice-9 match)
31 #:use-module (srfi srfi-26)
32 #:export (pcscd-configuration
33 pcscd-configuration?
34 pcscd-configuration-pcsc-lite
35 pcscd-configuration-usb-drivers
36 pcscd-service-type))
37
38 ;;;
39 ;;; PC/SC Smart Card Daemon
40 ;;;
41
42 (define-record-type* <pcscd-configuration>
43 pcscd-configuration make-pcscd-configuration pcscd-configuration?
44 (pcsc-lite pcscd-configuration-pcsc-lite
45 (default pcsc-lite))
46 (usb-drivers pcscd-configuration-usb-drivers
47 (default (list ccid))))
48
49 (define pcscd-shepherd-service
50 (match-lambda
51 (($ <pcscd-configuration> pcsc-lite)
52 (with-imported-modules (source-module-closure
53 '((gnu build shepherd)))
54 (shepherd-service
55 (documentation "PC/SC Smart Card Daemon")
56 (provision '(pcscd))
57 (requirement '(syslogd))
58 (modules '((gnu build shepherd)))
59 (start #~(lambda _
60 (invoke #$(file-append pcsc-lite "/sbin/pcscd"))
61 (call-with-input-file "/run/pcscd/pcscd.pid" read)))
62 (stop #~(make-kill-destructor)))))))
63
64 (define pcscd-activation
65 (match-lambda
66 (($ <pcscd-configuration> pcsc-lite usb-drivers)
67 (with-imported-modules (source-module-closure
68 '((guix build utils)))
69 #~(begin
70 (use-modules (guix build utils))
71 ;; XXX: We can't use (guix utils) because it requires a
72 ;; dynamically-linked Guile, hence the duplicate switch-symlinks.
73 (define (switch-symlinks link target)
74 (let ((pivot (string-append link ".new")))
75 (symlink target pivot)
76 (rename-file pivot link)))
77 (mkdir-p "/var/lib")
78 (switch-symlinks "/var/lib/pcsc"
79 #$(directory-union
80 "pcsc"
81 (map (cut file-append <> "/pcsc")
82 usb-drivers))))))))
83
84 (define pcscd-service-type
85 (service-type
86 (name 'pcscd)
87 (description
88 "Run @command{pcscd}, the PC/SC smart card daemon.")
89 (extensions
90 (list (service-extension shepherd-root-service-type
91 (compose list pcscd-shepherd-service))
92 (service-extension activation-service-type
93 pcscd-activation)))
94 (default-value (pcscd-configuration))))