security-token.scm 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. (define-module (gnu services security-token)
  20. #:use-module (gnu services)
  21. #:use-module (gnu services shepherd)
  22. #:use-module (gnu packages admin)
  23. #:use-module (gnu packages base)
  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. ;;; PC/SC Smart Card Daemon
  38. ;;;
  39. (define-record-type* <pcscd-configuration>
  40. pcscd-configuration make-pcscd-configuration pcscd-configuration?
  41. (pcsc-lite pcscd-configuration-pcsc-lite
  42. (default pcsc-lite))
  43. (usb-drivers pcscd-configuration-usb-drivers
  44. (default (list ccid))))
  45. (define pcscd-shepherd-service
  46. (match-lambda
  47. (($ <pcscd-configuration> pcsc-lite)
  48. (with-imported-modules (source-module-closure
  49. '((gnu build shepherd)))
  50. (shepherd-service
  51. (documentation "PC/SC Smart Card Daemon")
  52. (provision '(pcscd))
  53. (requirement '(syslogd))
  54. (modules '((gnu build shepherd)))
  55. (start #~(lambda _
  56. (invoke #$(file-append pcsc-lite "/sbin/pcscd"))
  57. (call-with-input-file "/run/pcscd/pcscd.pid" read)))
  58. (stop #~(make-kill-destructor)))))))
  59. (define pcscd-activation
  60. (match-lambda
  61. (($ <pcscd-configuration> pcsc-lite usb-drivers)
  62. (with-imported-modules (source-module-closure
  63. '((guix build utils)))
  64. #~(begin
  65. (use-modules (guix build utils))
  66. ;; XXX: We can't use (guix utils) because it requires a
  67. ;; dynamically-linked Guile, hence the duplicate switch-symlinks.
  68. (define (switch-symlinks link target)
  69. (let ((pivot (string-append link ".new")))
  70. (symlink target pivot)
  71. (rename-file pivot link)))
  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))))