security-token.scm 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. (define-module (gnu services security-token)
  19. #:use-module (gnu services)
  20. #:use-module (gnu services shepherd)
  21. #:use-module (gnu packages admin)
  22. #:use-module (gnu packages base)
  23. #:use-module (gnu packages security-token)
  24. #:use-module (gnu system shadow)
  25. #:use-module (guix gexp)
  26. #:use-module (guix modules)
  27. #:use-module (guix records)
  28. #:use-module (ice-9 match)
  29. #:use-module (srfi srfi-26)
  30. #:export (pcscd-configuration
  31. pcscd-configuration?
  32. pcscd-configuration-pcsc-lite
  33. pcscd-configuration-usb-drivers
  34. pcscd-service-type))
  35. ;;;
  36. ;;; PC/SC Smart Card Daemon
  37. ;;;
  38. (define-record-type* <pcscd-configuration>
  39. pcscd-configuration make-pcscd-configuration pcscd-configuration?
  40. (pcsc-lite pcscd-configuration-pcsc-lite
  41. (default pcsc-lite))
  42. (usb-drivers pcscd-configuration-usb-drivers
  43. (default (list ccid))))
  44. (define pcscd-shepherd-service
  45. (match-lambda
  46. (($ <pcscd-configuration> pcsc-lite)
  47. (with-imported-modules (source-module-closure
  48. '((gnu build shepherd)))
  49. (shepherd-service
  50. (documentation "PC/SC Smart Card Daemon")
  51. (provision '(pcscd))
  52. (requirement '(syslogd))
  53. (modules '((gnu build shepherd)))
  54. (start #~(lambda _
  55. (invoke #$(file-append pcsc-lite "/sbin/pcscd"))
  56. (call-with-input-file "/var/run/pcscd/pcscd.pid" read)))
  57. (stop #~(make-kill-destructor)))))))
  58. (define pcscd-activation
  59. (match-lambda
  60. (($ <pcscd-configuration> pcsc-lite usb-drivers)
  61. (with-imported-modules (source-module-closure
  62. '((guix build utils)))
  63. #~(begin
  64. (use-modules (guix build utils))
  65. ;; XXX: We can't use (guix utils) because it requires a
  66. ;; dynamically-linked Guile, hence the duplicate switch-symlinks.
  67. (define (switch-symlinks link target)
  68. (let ((pivot (string-append link ".new")))
  69. (symlink target pivot)
  70. (rename-file pivot link)))
  71. (mkdir-p "/var/lib")
  72. (switch-symlinks "/var/lib/pcsc"
  73. #$(directory-union
  74. "pcsc"
  75. (map (cut file-append <> "/pcsc")
  76. usb-drivers))))))))
  77. (define pcscd-service-type
  78. (service-type
  79. (name 'pcscd)
  80. (description
  81. "Run @command{pcscd}, the PC/SC smart card daemon.")
  82. (extensions
  83. (list (service-extension shepherd-root-service-type
  84. (compose list pcscd-shepherd-service))
  85. (service-extension activation-service-type
  86. pcscd-activation)))
  87. (default-value (pcscd-configuration))))