nfs.scm 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2016 John Darrington <jmd@gnu.org>
  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 nfs)
  19. #:use-module (gnu)
  20. #:use-module (gnu services shepherd)
  21. #:use-module (gnu packages onc-rpc)
  22. #:use-module (gnu packages linux)
  23. #:use-module (guix)
  24. #:use-module (guix records)
  25. #:use-module (ice-9 match)
  26. #:use-module (gnu build file-systems)
  27. #:export (rpcbind-service-type
  28. rpcbind-configuration
  29. rpcbind-configuration?
  30. pipefs-service-type
  31. pipefs-configuration
  32. pipefs-configuration?
  33. idmap-service-type
  34. idmap-configuration
  35. idmap-configuration?
  36. gss-service-type
  37. gss-configuration
  38. gss-configuration?))
  39. (define default-pipefs-directory "/var/lib/nfs/rpc_pipefs")
  40. (define-record-type* <rpcbind-configuration>
  41. rpcbind-configuration make-rpcbind-configuration
  42. rpcbind-configuration?
  43. (rpcbind rpcbind-configuration-rpcbind
  44. (default rpcbind))
  45. (warm-start? rpcbind-configuration-warm-start?
  46. (default #t)))
  47. (define rpcbind-service-type
  48. (shepherd-service-type
  49. 'rpcbind
  50. (lambda (config)
  51. (define nfs-utils
  52. (rpcbind-configuration-rpcbind config))
  53. (define rpcbind-command
  54. #~(list (string-append #$nfs-utils "/bin/rpcbind") "-f"
  55. #$@(if (rpcbind-configuration-warm-start? config) '("-w") '())))
  56. (shepherd-service
  57. (documentation "Start the RPC bind daemon.")
  58. (requirement '(networking))
  59. (provision '(rpcbind-daemon))
  60. (start #~(make-forkexec-constructor #$rpcbind-command))
  61. (stop #~(make-kill-destructor))))))
  62. (define-record-type* <pipefs-configuration>
  63. pipefs-configuration make-pipefs-configuration
  64. pipefs-configuration?
  65. (mount-point pipefs-configuration-mount-point
  66. (default default-pipefs-directory)))
  67. (define pipefs-service-type
  68. (shepherd-service-type
  69. 'pipefs
  70. (lambda (config)
  71. (define pipefs-directory (pipefs-configuration-mount-point config))
  72. (shepherd-service
  73. (documentation "Mount the pipefs pseudo filesystem.")
  74. (provision '(rpc-pipefs))
  75. (start #~(lambda ()
  76. (mkdir-p #$pipefs-directory)
  77. (mount "rpc_pipefs" #$pipefs-directory "rpc_pipefs")
  78. (member #$pipefs-directory (mount-points))))
  79. (stop #~(lambda (pid . args)
  80. (umount #$pipefs-directory MNT_DETACH)
  81. (not (member #$pipefs-directory (mount-points)))))))))
  82. (define-record-type* <gss-configuration>
  83. gss-configuration make-gss-configuration
  84. gss-configuration?
  85. (pipefs-directory gss-configuration-pipefs-directory
  86. (default default-pipefs-directory))
  87. (nfs-utils gss-configuration-gss
  88. (default nfs-utils)))
  89. (define gss-service-type
  90. (shepherd-service-type
  91. 'gss
  92. (lambda (config)
  93. (define nfs-utils
  94. (gss-configuration-gss config))
  95. (define pipefs-directory
  96. (gss-configuration-pipefs-directory config))
  97. (define gss-command
  98. #~(list (string-append #$nfs-utils "/sbin/rpc.gssd") "-f"
  99. "-p" #$pipefs-directory))
  100. (shepherd-service
  101. (documentation "Start the RPC GSS daemon.")
  102. (requirement '(rpcbind-daemon rpc-pipefs))
  103. (provision '(gss-daemon))
  104. (start #~(make-forkexec-constructor #$gss-command))
  105. (stop #~(make-kill-destructor))))))
  106. (define-record-type* <idmap-configuration>
  107. idmap-configuration make-idmap-configuration
  108. idmap-configuration?
  109. (pipefs-directory idmap-configuration-pipefs-directory
  110. (default default-pipefs-directory))
  111. (domain idmap-configuration-domain
  112. (default #f))
  113. (nfs-utils idmap-configuration-idmap
  114. (default nfs-utils)))
  115. (define idmap-service-type
  116. (shepherd-service-type
  117. 'idmap
  118. (lambda (config)
  119. (define nfs-utils
  120. (idmap-configuration-idmap config))
  121. (define pipefs-directory
  122. (idmap-configuration-pipefs-directory config))
  123. (define domain (idmap-configuration-domain config))
  124. (define (idmap-config-file config)
  125. (plain-file "idmapd.conf"
  126. (string-append
  127. "\n[General]\n"
  128. (if domain
  129. (format #f "Domain = ~a\n" domain))
  130. "\n[Mapping]\n"
  131. "Nobody-User = nobody\n"
  132. "Nobody-Group = nogroup\n")))
  133. (define idmap-command
  134. #~(list (string-append #$nfs-utils "/sbin/rpc.idmapd") "-f"
  135. "-p" #$pipefs-directory
  136. "-c" #$(idmap-config-file config)))
  137. (shepherd-service
  138. (documentation "Start the RPC IDMAP daemon.")
  139. (requirement '(rpcbind-daemon rpc-pipefs))
  140. (provision '(idmap-daemon))
  141. (start #~(make-forkexec-constructor #$idmap-command))
  142. (stop #~(make-kill-destructor))))))