Commit | Line | Data |
---|---|---|
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) | |
25c8c8cd | 27 | #:use-module (srfi srfi-1) |
eb419bc9 JD |
28 | #:use-module (ice-9 match) |
29 | #:use-module (gnu build file-systems) | |
d6a07ee6 JD |
30 | #:export (rpcbind-service-type |
31 | rpcbind-configuration | |
eb419bc9 JD |
32 | rpcbind-configuration? |
33 | ||
34 | pipefs-service-type | |
35 | pipefs-configuration | |
36 | pipefs-configuration? | |
37 | ||
38 | idmap-service-type | |
39 | idmap-configuration | |
40 | idmap-configuration? | |
41 | ||
42 | gss-service-type | |
43 | gss-configuration | |
44 | gss-configuration?)) | |
45 | ||
46 | ||
47 | (define default-pipefs-directory "/var/lib/nfs/rpc_pipefs") | |
48 | ||
49 | \f | |
d6a07ee6 JD |
50 | |
51 | (define-record-type* <rpcbind-configuration> | |
52 | rpcbind-configuration make-rpcbind-configuration | |
53 | rpcbind-configuration? | |
54 | (rpcbind rpcbind-configuration-rpcbind | |
55 | (default rpcbind)) | |
56 | (warm-start? rpcbind-configuration-warm-start? | |
57 | (default #t))) | |
58 | ||
59 | (define rpcbind-service-type | |
ba1808d5 RW |
60 | (let ((proc |
61 | (lambda (config) | |
62 | (define rpcbind | |
63 | (rpcbind-configuration-rpcbind config)) | |
d6a07ee6 | 64 | |
ba1808d5 RW |
65 | (define rpcbind-command |
66 | #~(list (string-append #$rpcbind "/bin/rpcbind") "-f" | |
67 | #$@(if (rpcbind-configuration-warm-start? config) '("-w") '()))) | |
d6a07ee6 | 68 | |
ba1808d5 RW |
69 | (shepherd-service |
70 | (documentation "Start the RPC bind daemon.") | |
71 | (requirement '(networking)) | |
72 | (provision '(rpcbind-daemon)) | |
d6a07ee6 | 73 | |
ba1808d5 RW |
74 | (start #~(make-forkexec-constructor #$rpcbind-command)) |
75 | (stop #~(make-kill-destructor)))))) | |
76 | (service-type | |
77 | (name 'rpcbind) | |
78 | (extensions | |
79 | (list (service-extension shepherd-root-service-type | |
80 | (compose list proc)))) | |
81 | ;; We use the extensions feature to allow other services to automatically | |
82 | ;; configure and start this service. Only one value can be provided. We | |
83 | ;; override it with the value returned by the extending service. | |
84 | (compose identity) | |
85 | (extend (lambda (config values) | |
86 | (match values | |
87 | ((first . rest) first) | |
88 | (_ config)))) | |
89 | (default-value (rpcbind-configuration))))) | |
eb419bc9 JD |
90 | |
91 | \f | |
92 | ||
93 | (define-record-type* <pipefs-configuration> | |
94 | pipefs-configuration make-pipefs-configuration | |
95 | pipefs-configuration? | |
96 | (mount-point pipefs-configuration-mount-point | |
97 | (default default-pipefs-directory))) | |
98 | ||
99 | (define pipefs-service-type | |
25c8c8cd RW |
100 | (let ((proc |
101 | (lambda (config) | |
102 | (define pipefs-directory (pipefs-configuration-mount-point config)) | |
eb419bc9 | 103 | |
25c8c8cd RW |
104 | (shepherd-service |
105 | (documentation "Mount the pipefs pseudo file system.") | |
106 | (provision '(rpc-pipefs)) | |
eb419bc9 | 107 | |
25c8c8cd RW |
108 | (start #~(lambda () |
109 | (mkdir-p #$pipefs-directory) | |
110 | (mount "rpc_pipefs" #$pipefs-directory "rpc_pipefs") | |
111 | (member #$pipefs-directory (mount-points)))) | |
eb419bc9 | 112 | |
25c8c8cd RW |
113 | (stop #~(lambda (pid . args) |
114 | (umount #$pipefs-directory MNT_DETACH) | |
115 | (not (member #$pipefs-directory (mount-points))))))))) | |
116 | (service-type | |
117 | (name 'pipefs) | |
118 | (extensions | |
119 | (list (service-extension shepherd-root-service-type | |
120 | (compose list proc)))) | |
121 | ;; We use the extensions feature to allow other services to automatically | |
122 | ;; configure and start this service. Only one value can be provided. We | |
123 | ;; override it with the value returned by the extending service. | |
124 | (compose identity) | |
125 | (extend (lambda (config values) (first values))) | |
126 | (default-value (pipefs-configuration))))) | |
eb419bc9 JD |
127 | |
128 | \f | |
129 | ||
130 | (define-record-type* <gss-configuration> | |
131 | gss-configuration make-gss-configuration | |
132 | gss-configuration? | |
5d4ba498 | 133 | (pipefs-directory gss-configuration-pipefs-directory |
eb419bc9 JD |
134 | (default default-pipefs-directory)) |
135 | (nfs-utils gss-configuration-gss | |
136 | (default nfs-utils))) | |
137 | ||
138 | (define gss-service-type | |
139 | (shepherd-service-type | |
140 | 'gss | |
141 | (lambda (config) | |
142 | (define nfs-utils | |
143 | (gss-configuration-gss config)) | |
144 | ||
145 | (define pipefs-directory | |
146 | (gss-configuration-pipefs-directory config)) | |
147 | ||
148 | (define gss-command | |
149 | #~(list (string-append #$nfs-utils "/sbin/rpc.gssd") "-f" | |
150 | "-p" #$pipefs-directory)) | |
151 | ||
152 | (shepherd-service | |
153 | (documentation "Start the RPC GSS daemon.") | |
154 | (requirement '(rpcbind-daemon rpc-pipefs)) | |
155 | (provision '(gss-daemon)) | |
156 | ||
157 | (start #~(make-forkexec-constructor #$gss-command)) | |
158 | (stop #~(make-kill-destructor)))))) | |
159 | ||
160 | \f | |
161 | ||
162 | (define-record-type* <idmap-configuration> | |
163 | idmap-configuration make-idmap-configuration | |
164 | idmap-configuration? | |
5d4ba498 | 165 | (pipefs-directory idmap-configuration-pipefs-directory |
eb419bc9 JD |
166 | (default default-pipefs-directory)) |
167 | (domain idmap-configuration-domain | |
5d4ba498 RW |
168 | (default #f)) |
169 | (nfs-utils idmap-configuration-nfs-utils | |
eb419bc9 JD |
170 | (default nfs-utils))) |
171 | ||
172 | (define idmap-service-type | |
173 | (shepherd-service-type | |
174 | 'idmap | |
175 | (lambda (config) | |
176 | ||
177 | (define nfs-utils | |
5d4ba498 | 178 | (idmap-configuration-nfs-utils config)) |
eb419bc9 JD |
179 | |
180 | (define pipefs-directory | |
181 | (idmap-configuration-pipefs-directory config)) | |
182 | ||
183 | (define domain (idmap-configuration-domain config)) | |
184 | ||
185 | (define (idmap-config-file config) | |
186 | (plain-file "idmapd.conf" | |
187 | (string-append | |
188 | "\n[General]\n" | |
189 | (if domain | |
190 | (format #f "Domain = ~a\n" domain)) | |
191 | "\n[Mapping]\n" | |
192 | "Nobody-User = nobody\n" | |
193 | "Nobody-Group = nogroup\n"))) | |
194 | ||
195 | (define idmap-command | |
196 | #~(list (string-append #$nfs-utils "/sbin/rpc.idmapd") "-f" | |
197 | "-p" #$pipefs-directory | |
198 | "-c" #$(idmap-config-file config))) | |
199 | ||
200 | (shepherd-service | |
201 | (documentation "Start the RPC IDMAP daemon.") | |
202 | (requirement '(rpcbind-daemon rpc-pipefs)) | |
203 | (provision '(idmap-daemon)) | |
204 | (start #~(make-forkexec-constructor #$idmap-command)) | |
205 | (stop #~(make-kill-destructor)))))) | |
206 |