security-token.scm 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2018, 2022 Arun Isaac <arunisaac@systemreboot.net>
  3. ;;; Copyright © 2020 Tobias Geerinckx-Rice <me@tobias.gr>
  4. ;;; Copyright © 2021 Brice Waegeneire <brice@waegenei.re>
  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. (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. ;;; PC/SC Smart Card Daemon
  39. ;;;
  40. (define-record-type* <pcscd-configuration>
  41. pcscd-configuration make-pcscd-configuration pcscd-configuration?
  42. (pcsc-lite pcscd-configuration-pcsc-lite
  43. (default pcsc-lite))
  44. (usb-drivers pcscd-configuration-usb-drivers
  45. (default (list ccid))))
  46. (define pcscd-shepherd-service
  47. (match-lambda
  48. (($ <pcscd-configuration> pcsc-lite)
  49. (with-imported-modules (source-module-closure
  50. '((gnu build shepherd)))
  51. (shepherd-service
  52. (documentation "PC/SC Smart Card Daemon")
  53. (provision '(pcscd))
  54. (requirement '(syslogd))
  55. (modules '((gnu build shepherd)))
  56. (start #~(lambda _
  57. (let ((socket "/run/pcscd/pcscd.comm"))
  58. (when (file-exists? socket)
  59. (delete-file socket)))
  60. (fork+exec-command
  61. (list #$(file-append pcsc-lite "/sbin/pcscd")
  62. "--foreground")
  63. #:log-file "/var/log/pcscd.log")))
  64. (stop #~(make-kill-destructor)))))))
  65. (define pcscd-activation
  66. (match-lambda
  67. (($ <pcscd-configuration> pcsc-lite usb-drivers)
  68. (with-imported-modules (source-module-closure
  69. '((guix build utils)))
  70. #~(begin
  71. (use-modules (guix build utils))
  72. (mkdir-p "/var/lib")
  73. (switch-symlinks "/var/lib/pcsc"
  74. #$(directory-union
  75. "pcsc"
  76. (map (cut file-append <> "/pcsc")
  77. usb-drivers))))))))
  78. (define pcscd-service-type
  79. (service-type
  80. (name 'pcscd)
  81. (description
  82. "Run @command{pcscd}, the PC/SC smart card daemon.")
  83. (extensions
  84. (list (service-extension shepherd-root-service-type
  85. (compose list pcscd-shepherd-service))
  86. (service-extension activation-service-type
  87. pcscd-activation)))
  88. (default-value (pcscd-configuration))))