gpg-agent.scm 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2016 Mathieu Lirzin <mthl@gnu.org>
  3. ;;; Copyright © 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
  4. ;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
  5. ;;; Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
  6. ;;; Copyright © 2018, 2019 Ricardo Wurmus <rekado@elephly.net>
  7. ;;; Copyright © 2018 Clément Lassieur <clement@lassieur.org>
  8. ;;;
  9. ;;; This file is part of GNU Guix.
  10. ;;;
  11. ;;; GNU Guix is free software; you can redistribute it and/or modify
  12. ;;; it under the terms of the GNU General Public License as published by
  13. ;;; the Free Software Foundation, either version 3 of the License, or
  14. ;;; (at your option) any later version.
  15. ;;;
  16. ;;; GNU Guix is distributed in the hope that it will be useful,
  17. ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. ;;; GNU General Public License for more details.
  20. ;;;
  21. ;;; You should have received a copy of the GNU General Public License
  22. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  23. (define-module (gpg-agent)
  24. #:use-module (guix gexp)
  25. #:use-module (guix records)
  26. #:use-module (gnu packages admin)
  27. ;; #:autoload (gnu packages ci) (cuirass)
  28. ;; #:autoload (gnu packages version-control) (git)
  29. #:use-module (gnu services)
  30. #:use-module (gnu services base)
  31. #:use-module (gnu services shepherd)
  32. #:use-module (gnu services admin)
  33. #:use-module (gnu system shadow)
  34. #:export (<gpg-agent-configuration>
  35. gpg-agent-configuration
  36. gpg-agent-configuration?
  37. user
  38. group
  39. default-cache-ttl
  40. pinetry-program
  41. allow-loopback?
  42. enable-ssh-support?
  43. emacs-allow-pinetry?
  44. gpg-agent-service-type))
  45. ;;;; Commentary:
  46. ;;; This file provides a shepherd service to run the gpg agent.
  47. ;;;; Code:
  48. (define-record-type* <gpg-agent-configuration>
  49. gpg-agent-configuration make-gpg-agent-configuration
  50. gpg-agent-configuration?
  51. (gpg-agent gpg-agent-configuration-gpg-agent ;package
  52. (default gpg-agent))
  53. (user gpg-agent-configuration-user ;string
  54. (default "gpg-agent"))
  55. (group gpg-agent-configuration-group ;string
  56. (default "gpg-agent"))
  57. (default-cache-ttl gpg-agent-configuration-default-cache-ttl ;number
  58. (default 28800))
  59. (pinentry-program gpg-agent-configuration-pinentry-program ;boolean
  60. (default "pinentry-gtk-2"))
  61. (allow-loopback? gpg-agent-configuration-allow-loopback
  62. (default #t))
  63. (enable-ssh-support? gpg-agent-configuration-enable-ssh-support
  64. (default #t))
  65. (emacs-allow-pinetry? gpg-agent-configuration-emacs-allow-pinetry
  66. (default #f)))
  67. (define (gpg-agent-shepherd-service config)
  68. "Return a <shepherd-service> for the Gpg-Agent service."
  69. (let ((gpg-agent gpg-agent-configuration-gpg-agent)
  70. (user gpg-agent-configuration-user)
  71. (group gpg-agent-configuration-group)
  72. (default-cache-ttl gpg-agent-configuration-cache-ttl)
  73. (allow-loopback? gpg-agent-configuration-allow-loopback)
  74. (enable-ssh-support? gpg-agent-configuration-enable-ssh-support)
  75. (emacs-allow-pinetry? gpg-agent-configuration-emacs-allow-pinetry))
  76. (list (shepherd-service
  77. (documentation "Run Gpg-Agent.")
  78. (provision '(gpg-agent))
  79. ;;(requirement '(networking))
  80. (start #~(make-forkexec-constructor
  81. (list (string-append #$gpg-agent "/bin/gpg-agent")
  82. " "
  83. #$@(if default-cache-ttl '("--default-cache-ttl ") '())
  84. #$@(if allow-loopback? '("--allow-loopback") '())
  85. #$@(if enable-ssh-support? '("--enable-ssh-support?") '())
  86. #$@(if emacs-allow-pinetry? '("--emacs-allow-pinetry")))
  87. #:environment-variables
  88. (list "GPG_TTY=$(tty)")
  89. #:user #$user
  90. #:group #$group
  91. ))
  92. (stop #~(make-kill-destructor))))))
  93. (define gpg-agent-service-type
  94. (service-type
  95. (name 'gpg-agent)
  96. (extensions
  97. (list
  98. (service-extension shepherd-service-type ;for 'info gpg-agent'
  99. (compose list gpg-agent-configuration-gpg-agent))
  100. ))
  101. (description
  102. "Run GPG's agent.")))