services: nfs: Fix name of package variable.
[jackhill/guix/guix.git] / gnu / services / nfs.scm
CommitLineData
d6a07ee6
JD
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2016 John Darrington <jmd@gnu.org>
981ce389 3;;; Copyright © 2018, 2019, 2020 Ricardo Wurmus <rekado@elephly.net>
d6a07ee6
JD
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
20(define-module (gnu services nfs)
21 #:use-module (gnu)
22 #:use-module (gnu services shepherd)
23 #:use-module (gnu packages onc-rpc)
eb419bc9 24 #:use-module (gnu packages linux)
d6a07ee6
JD
25 #:use-module (guix)
26 #:use-module (guix records)
eb419bc9
JD
27 #:use-module (ice-9 match)
28 #:use-module (gnu build file-systems)
d6a07ee6
JD
29 #:export (rpcbind-service-type
30 rpcbind-configuration
eb419bc9
JD
31 rpcbind-configuration?
32
33 pipefs-service-type
34 pipefs-configuration
35 pipefs-configuration?
36
37 idmap-service-type
38 idmap-configuration
39 idmap-configuration?
40
41 gss-service-type
42 gss-configuration
43 gss-configuration?))
44
45
46(define default-pipefs-directory "/var/lib/nfs/rpc_pipefs")
47
48\f
d6a07ee6
JD
49
50(define-record-type* <rpcbind-configuration>
51 rpcbind-configuration make-rpcbind-configuration
52 rpcbind-configuration?
53 (rpcbind rpcbind-configuration-rpcbind
54 (default rpcbind))
55 (warm-start? rpcbind-configuration-warm-start?
56 (default #t)))
57
58(define rpcbind-service-type
59 (shepherd-service-type
60 'rpcbind
61 (lambda (config)
981ce389 62 (define rpcbind
d6a07ee6
JD
63 (rpcbind-configuration-rpcbind config))
64
65 (define rpcbind-command
981ce389 66 #~(list (string-append #$rpcbind "/bin/rpcbind") "-f"
d6a07ee6
JD
67 #$@(if (rpcbind-configuration-warm-start? config) '("-w") '())))
68
69 (shepherd-service
70 (documentation "Start the RPC bind daemon.")
71 (requirement '(networking))
72 (provision '(rpcbind-daemon))
73
74 (start #~(make-forkexec-constructor #$rpcbind-command))
75 (stop #~(make-kill-destructor))))))
eb419bc9
JD
76
77\f
78
79(define-record-type* <pipefs-configuration>
80 pipefs-configuration make-pipefs-configuration
81 pipefs-configuration?
82 (mount-point pipefs-configuration-mount-point
83 (default default-pipefs-directory)))
84
85(define pipefs-service-type
86 (shepherd-service-type
87 'pipefs
88 (lambda (config)
89 (define pipefs-directory (pipefs-configuration-mount-point config))
90
91 (shepherd-service
162a1374 92 (documentation "Mount the pipefs pseudo file system.")
eb419bc9
JD
93 (provision '(rpc-pipefs))
94
95 (start #~(lambda ()
96 (mkdir-p #$pipefs-directory)
97 (mount "rpc_pipefs" #$pipefs-directory "rpc_pipefs")
98 (member #$pipefs-directory (mount-points))))
99
100 (stop #~(lambda (pid . args)
101 (umount #$pipefs-directory MNT_DETACH)
102 (not (member #$pipefs-directory (mount-points)))))))))
103
104\f
105
106(define-record-type* <gss-configuration>
107 gss-configuration make-gss-configuration
108 gss-configuration?
109 (pipefs-directory gss-configuration-pipefs-directory
110 (default default-pipefs-directory))
111 (nfs-utils gss-configuration-gss
112 (default nfs-utils)))
113
114(define gss-service-type
115 (shepherd-service-type
116 'gss
117 (lambda (config)
118 (define nfs-utils
119 (gss-configuration-gss config))
120
121 (define pipefs-directory
122 (gss-configuration-pipefs-directory config))
123
124 (define gss-command
125 #~(list (string-append #$nfs-utils "/sbin/rpc.gssd") "-f"
126 "-p" #$pipefs-directory))
127
128 (shepherd-service
129 (documentation "Start the RPC GSS daemon.")
130 (requirement '(rpcbind-daemon rpc-pipefs))
131 (provision '(gss-daemon))
132
133 (start #~(make-forkexec-constructor #$gss-command))
134 (stop #~(make-kill-destructor))))))
135
136\f
137
138(define-record-type* <idmap-configuration>
139 idmap-configuration make-idmap-configuration
140 idmap-configuration?
141 (pipefs-directory idmap-configuration-pipefs-directory
142 (default default-pipefs-directory))
143 (domain idmap-configuration-domain
144 (default #f))
145 (nfs-utils idmap-configuration-idmap
146 (default nfs-utils)))
147
148(define idmap-service-type
149 (shepherd-service-type
150 'idmap
151 (lambda (config)
152
153 (define nfs-utils
154 (idmap-configuration-idmap config))
155
156 (define pipefs-directory
157 (idmap-configuration-pipefs-directory config))
158
159 (define domain (idmap-configuration-domain config))
160
161 (define (idmap-config-file config)
162 (plain-file "idmapd.conf"
163 (string-append
164 "\n[General]\n"
165 (if domain
166 (format #f "Domain = ~a\n" domain))
167 "\n[Mapping]\n"
168 "Nobody-User = nobody\n"
169 "Nobody-Group = nogroup\n")))
170
171 (define idmap-command
172 #~(list (string-append #$nfs-utils "/sbin/rpc.idmapd") "-f"
173 "-p" #$pipefs-directory
174 "-c" #$(idmap-config-file config)))
175
176 (shepherd-service
177 (documentation "Start the RPC IDMAP daemon.")
178 (requirement '(rpcbind-daemon rpc-pipefs))
179 (provision '(idmap-daemon))
180 (start #~(make-forkexec-constructor #$idmap-command))
181 (stop #~(make-kill-destructor))))))
182