Commit | Line | Data |
---|---|---|
de30205b AI |
1 | ;;; GNU Guix --- Functional package management for GNU |
2 | ;;; Copyright © 2018 Arun Isaac <arunisaac@systemreboot.net> | |
3 | ;;; | |
4 | ;;; This file is part of GNU Guix. | |
5 | ;;; | |
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. | |
10 | ;;; | |
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. | |
15 | ;;; | |
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/>. | |
18 | ||
19 | (define-module (gnu services security-token) | |
20 | #:use-module (gnu services) | |
21 | #:use-module (gnu services shepherd) | |
22 | #:use-module (gnu packages admin) | |
6fb6ac68 | 23 | #:use-module (gnu packages base) |
de30205b AI |
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 | |
32 | pcscd-configuration? | |
33 | pcscd-configuration-pcsc-lite | |
34 | pcscd-configuration-usb-drivers | |
35 | pcscd-service-type)) | |
36 | ||
37 | ;;; | |
38 | ;;; PC/SC Smart Card Daemon | |
39 | ;;; | |
40 | ||
41 | (define-record-type* <pcscd-configuration> | |
42 | pcscd-configuration make-pcscd-configuration pcscd-configuration? | |
43 | (pcsc-lite pcscd-configuration-pcsc-lite | |
44 | (default pcsc-lite)) | |
45 | (usb-drivers pcscd-configuration-usb-drivers | |
46 | (default (list ccid)))) | |
47 | ||
48 | (define pcscd-shepherd-service | |
49 | (match-lambda | |
50 | (($ <pcscd-configuration> pcsc-lite) | |
51 | (with-imported-modules (source-module-closure | |
52 | '((gnu build shepherd))) | |
53 | (shepherd-service | |
54 | (documentation "PC/SC Smart Card Daemon") | |
55 | (provision '(pcscd)) | |
56 | (requirement '(syslogd)) | |
57 | (modules '((gnu build shepherd))) | |
58 | (start #~(lambda _ | |
59 | (invoke #$(file-append pcsc-lite "/sbin/pcscd")) | |
60 | (call-with-input-file "/var/run/pcscd/pcscd.pid" read))) | |
61 | (stop #~(make-kill-destructor))))))) | |
62 | ||
63 | (define pcscd-activation | |
64 | (match-lambda | |
65 | (($ <pcscd-configuration> pcsc-lite usb-drivers) | |
6fb6ac68 CM |
66 | (with-imported-modules (source-module-closure |
67 | '((guix build utils))) | |
68 | #~(begin | |
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))) | |
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)))))))) | |
de30205b AI |
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 | (default-value (pcscd-configuration)))) |