1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2016 John Darrington <jmd@gnu.org>
4 ;;; This file is part of GNU Guix.
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.
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.
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/>.
19 (define-module (gnu services nfs)
21 #:use-module (gnu services shepherd)
22 #:use-module (gnu packages onc-rpc)
23 #:use-module (gnu packages linux)
25 #:use-module (guix records)
26 #:use-module (ice-9 match)
27 #:use-module (gnu build file-systems)
28 #:export (rpcbind-service-type
30 rpcbind-configuration?
45 (define default-pipefs-directory "/var/lib/nfs/rpc_pipefs")
49 (define-record-type* <rpcbind-configuration>
50 rpcbind-configuration make-rpcbind-configuration
51 rpcbind-configuration?
52 (rpcbind rpcbind-configuration-rpcbind
54 (warm-start? rpcbind-configuration-warm-start?
57 (define rpcbind-service-type
58 (shepherd-service-type
62 (rpcbind-configuration-rpcbind config))
64 (define rpcbind-command
65 #~(list (string-append #$nfs-utils "/bin/rpcbind") "-f"
66 #$@(if (rpcbind-configuration-warm-start? config) '("-w") '())))
69 (documentation "Start the RPC bind daemon.")
70 (requirement '(networking))
71 (provision '(rpcbind-daemon))
73 (start #~(make-forkexec-constructor #$rpcbind-command))
74 (stop #~(make-kill-destructor))))))
78 (define-record-type* <pipefs-configuration>
79 pipefs-configuration make-pipefs-configuration
81 (mount-point pipefs-configuration-mount-point
82 (default default-pipefs-directory)))
84 (define pipefs-service-type
85 (shepherd-service-type
88 (define pipefs-directory (pipefs-configuration-mount-point config))
91 (documentation "Mount the pipefs pseudo file system.")
92 (provision '(rpc-pipefs))
95 (mkdir-p #$pipefs-directory)
96 (mount "rpc_pipefs" #$pipefs-directory "rpc_pipefs")
97 (member #$pipefs-directory (mount-points))))
99 (stop #~(lambda (pid . args)
100 (umount #$pipefs-directory MNT_DETACH)
101 (not (member #$pipefs-directory (mount-points)))))))))
105 (define-record-type* <gss-configuration>
106 gss-configuration make-gss-configuration
108 (pipefs-directory gss-configuration-pipefs-directory
109 (default default-pipefs-directory))
110 (nfs-utils gss-configuration-gss
111 (default nfs-utils)))
113 (define gss-service-type
114 (shepherd-service-type
118 (gss-configuration-gss config))
120 (define pipefs-directory
121 (gss-configuration-pipefs-directory config))
124 #~(list (string-append #$nfs-utils "/sbin/rpc.gssd") "-f"
125 "-p" #$pipefs-directory))
128 (documentation "Start the RPC GSS daemon.")
129 (requirement '(rpcbind-daemon rpc-pipefs))
130 (provision '(gss-daemon))
132 (start #~(make-forkexec-constructor #$gss-command))
133 (stop #~(make-kill-destructor))))))
137 (define-record-type* <idmap-configuration>
138 idmap-configuration make-idmap-configuration
140 (pipefs-directory idmap-configuration-pipefs-directory
141 (default default-pipefs-directory))
142 (domain idmap-configuration-domain
144 (nfs-utils idmap-configuration-idmap
145 (default nfs-utils)))
147 (define idmap-service-type
148 (shepherd-service-type
153 (idmap-configuration-idmap config))
155 (define pipefs-directory
156 (idmap-configuration-pipefs-directory config))
158 (define domain (idmap-configuration-domain config))
160 (define (idmap-config-file config)
161 (plain-file "idmapd.conf"
165 (format #f "Domain = ~a\n" domain))
167 "Nobody-User = nobody\n"
168 "Nobody-Group = nogroup\n")))
170 (define idmap-command
171 #~(list (string-append #$nfs-utils "/sbin/rpc.idmapd") "-f"
172 "-p" #$pipefs-directory
173 "-c" #$(idmap-config-file config)))
176 (documentation "Start the RPC IDMAP daemon.")
177 (requirement '(rpcbind-daemon rpc-pipefs))
178 (provision '(idmap-daemon))
179 (start #~(make-forkexec-constructor #$idmap-command))
180 (stop #~(make-kill-destructor))))))