Commit | Line | Data |
---|---|---|
c5df1839 | 1 | ;;; GNU Guix --- Functional package management for GNU |
f8865db6 | 2 | ;;; Copyright © 2013, 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org> |
c5df1839 LC |
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 | ||
19 | (define-module (gnu system file-systems) | |
575b4b09 | 20 | #:use-module (ice-9 match) |
c5df1839 | 21 | #:use-module (guix records) |
3392ce5d | 22 | #:use-module (guix store) |
f8865db6 LC |
23 | #:use-module ((gnu build file-systems) |
24 | #:select (string->uuid uuid->string)) | |
25 | #:re-export (string->uuid | |
26 | uuid->string) | |
c5df1839 LC |
27 | #:export (<file-system> |
28 | file-system | |
29 | file-system? | |
30 | file-system-device | |
d4c87617 | 31 | file-system-title |
c5df1839 LC |
32 | file-system-mount-point |
33 | file-system-type | |
34 | file-system-needed-for-boot? | |
35 | file-system-flags | |
36 | file-system-options | |
be21979d | 37 | file-system-mount? |
4e469051 LC |
38 | file-system-check? |
39 | file-system-create-mount-point? | |
e51710d1 | 40 | file-system-dependencies |
c5df1839 | 41 | |
575b4b09 | 42 | file-system->spec |
661a1d79 | 43 | uuid |
575b4b09 | 44 | |
c5df1839 | 45 | %fuse-control-file-system |
a69576ea | 46 | %binary-format-file-system |
705f8b68 MW |
47 | %shared-memory-file-system |
48 | %pseudo-terminal-file-system | |
3392ce5d | 49 | %immutable-store |
727636aa | 50 | %control-groups |
14454f0b | 51 | %elogind-file-systems |
a69576ea | 52 | |
5dae0186 | 53 | %base-file-systems |
c829bc80 | 54 | %container-file-systems |
5dae0186 | 55 | |
9110c2e9 DT |
56 | <file-system-mapping> |
57 | file-system-mapping | |
58 | file-system-mapping? | |
59 | file-system-mapping-source | |
60 | file-system-mapping-target | |
61 | file-system-mapping-writable? | |
62 | ||
63 | %store-mapping)) | |
c5df1839 LC |
64 | |
65 | ;;; Commentary: | |
66 | ;;; | |
67 | ;;; Declaring file systems to be mounted. | |
68 | ;;; | |
69 | ;;; Code: | |
70 | ||
71 | ;; File system declaration. | |
72 | (define-record-type* <file-system> file-system | |
73 | make-file-system | |
74 | file-system? | |
75 | (device file-system-device) ; string | |
d4c87617 LC |
76 | (title file-system-title ; 'device | 'label | 'uuid |
77 | (default 'device)) | |
c5df1839 LC |
78 | (mount-point file-system-mount-point) ; string |
79 | (type file-system-type) ; string | |
80 | (flags file-system-flags ; list of symbols | |
81 | (default '())) | |
82 | (options file-system-options ; string or #f | |
83 | (default #f)) | |
be21979d LC |
84 | (mount? file-system-mount? ; Boolean |
85 | (default #t)) | |
4d6b879c | 86 | (needed-for-boot? %file-system-needed-for-boot? ; Boolean |
c5df1839 LC |
87 | (default #f)) |
88 | (check? file-system-check? ; Boolean | |
4e469051 LC |
89 | (default #t)) |
90 | (create-mount-point? file-system-create-mount-point? ; Boolean | |
e51710d1 | 91 | (default #f)) |
e502bf89 LC |
92 | (dependencies file-system-dependencies ; list of <file-system> |
93 | (default '()))) ; or <mapped-device> | |
c5df1839 | 94 | |
4d6b879c LC |
95 | (define-inlinable (file-system-needed-for-boot? fs) |
96 | "Return true if FS has the 'needed-for-boot?' flag set, or if it's the root | |
97 | file system." | |
98 | (or (%file-system-needed-for-boot? fs) | |
99 | (string=? "/" (file-system-mount-point fs)))) | |
100 | ||
575b4b09 DT |
101 | (define (file-system->spec fs) |
102 | "Return a list corresponding to file-system FS that can be passed to the | |
103 | initrd code." | |
104 | (match fs | |
be21979d | 105 | (($ <file-system> device title mount-point type flags options _ _ check?) |
575b4b09 DT |
106 | (list device title mount-point type flags options check?)))) |
107 | ||
661a1d79 LC |
108 | (define-syntax uuid |
109 | (lambda (s) | |
110 | "Return the bytevector corresponding to the given UUID representation." | |
111 | (syntax-case s () | |
112 | ((_ str) | |
113 | (string? (syntax->datum #'str)) | |
114 | ;; A literal string: do the conversion at expansion time. | |
1cab9e81 LC |
115 | (let ((bv (string->uuid (syntax->datum #'str)))) |
116 | (unless bv | |
117 | (syntax-violation 'uuid "invalid UUID" s)) | |
118 | (datum->syntax #'str bv))) | |
661a1d79 LC |
119 | ((_ str) |
120 | #'(string->uuid str))))) | |
121 | ||
122 | \f | |
123 | ;;; | |
124 | ;;; Common file systems. | |
125 | ;;; | |
126 | ||
c5df1839 LC |
127 | (define %fuse-control-file-system |
128 | ;; Control file system for Linux' file systems in user-space (FUSE). | |
129 | (file-system | |
130 | (device "fusectl") | |
131 | (mount-point "/sys/fs/fuse/connections") | |
132 | (type "fusectl") | |
133 | (check? #f))) | |
134 | ||
135 | (define %binary-format-file-system | |
136 | ;; Support for arbitrary executable binary format. | |
137 | (file-system | |
138 | (device "binfmt_misc") | |
139 | (mount-point "/proc/sys/fs/binfmt_misc") | |
140 | (type "binfmt_misc") | |
141 | (check? #f))) | |
142 | ||
7f239fd3 LC |
143 | (define %tty-gid |
144 | ;; ID of the 'tty' group. Allocate it statically to make it easy to refer | |
145 | ;; to it from here and from the 'tty' group definitions. | |
c8fa3426 | 146 | 996) |
7f239fd3 LC |
147 | |
148 | (define %pseudo-terminal-file-system | |
149 | ;; The pseudo-terminal file system. It needs to be mounted so that | |
150 | ;; statfs(2) returns DEVPTS_SUPER_MAGIC like libc's getpt(3) expects (and | |
151 | ;; thus openpty(3) and its users, such as xterm.) | |
152 | (file-system | |
153 | (device "none") | |
154 | (mount-point "/dev/pts") | |
155 | (type "devpts") | |
156 | (check? #f) | |
157 | (needed-for-boot? #f) | |
158 | (create-mount-point? #t) | |
159 | (options (string-append "gid=" (number->string %tty-gid) ",mode=620")))) | |
a69576ea | 160 | |
db17ae5c LC |
161 | (define %shared-memory-file-system |
162 | ;; Shared memory. | |
163 | (file-system | |
164 | (device "tmpfs") | |
165 | (mount-point "/dev/shm") | |
166 | (type "tmpfs") | |
167 | (check? #f) | |
168 | (flags '(no-suid no-dev)) | |
169 | (options "size=50%") ;TODO: make size configurable | |
170 | (create-mount-point? #t))) | |
171 | ||
3392ce5d LC |
172 | (define %immutable-store |
173 | ;; Read-only store to avoid users or daemons accidentally modifying it. | |
174 | ;; 'guix-daemon' has provisions to remount it read-write in its own name | |
175 | ;; space. | |
176 | (file-system | |
177 | (device (%store-prefix)) | |
178 | (mount-point (%store-prefix)) | |
179 | (type "none") | |
180 | (check? #f) | |
181 | (flags '(read-only bind-mount)))) | |
182 | ||
727636aa | 183 | (define %control-groups |
b78cad85 LC |
184 | (let ((parent (file-system |
185 | (device "cgroup") | |
186 | (mount-point "/sys/fs/cgroup") | |
187 | (type "tmpfs") | |
188 | (check? #f)))) | |
189 | (cons parent | |
190 | (map (lambda (subsystem) | |
191 | (file-system | |
192 | (device "cgroup") | |
193 | (mount-point (string-append "/sys/fs/cgroup/" subsystem)) | |
194 | (type "cgroup") | |
195 | (check? #f) | |
196 | (options subsystem) | |
197 | (create-mount-point? #t) | |
198 | ||
199 | ;; This must be mounted after, and unmounted before the | |
200 | ;; parent directory. | |
201 | (dependencies (list parent)))) | |
202 | '("cpuset" "cpu" "cpuacct" "memory" "devices" "freezer" | |
203 | "blkio" "perf_event" "hugetlb"))))) | |
727636aa | 204 | |
14454f0b MW |
205 | (define %elogind-file-systems |
206 | ;; We don't use systemd, but these file systems are needed for elogind, | |
207 | ;; which was extracted from systemd. | |
208 | (list (file-system | |
209 | (device "none") | |
210 | (mount-point "/run/systemd") | |
211 | (type "tmpfs") | |
212 | (check? #f) | |
213 | (flags '(no-suid no-dev no-exec)) | |
214 | (options "mode=0755") | |
215 | (create-mount-point? #t)) | |
216 | (file-system | |
217 | (device "none") | |
218 | (mount-point "/run/user") | |
219 | (type "tmpfs") | |
220 | (check? #f) | |
221 | (flags '(no-suid no-dev no-exec)) | |
222 | (options "mode=0755") | |
a7e50a2a AW |
223 | (create-mount-point? #t)) |
224 | ;; Elogind uses cgroups to organize processes, allowing it to map PIDs | |
225 | ;; to sessions. Elogind's cgroup hierarchy isn't associated with any | |
226 | ;; resource controller ("subsystem"). | |
227 | (file-system | |
228 | (device "cgroup") | |
229 | (mount-point "/sys/fs/cgroup/elogind") | |
230 | (type "cgroup") | |
231 | (check? #f) | |
232 | (options "none,name=elogind") | |
233 | (create-mount-point? #t) | |
234 | (dependencies (list (car %control-groups)))))) | |
14454f0b | 235 | |
a69576ea LC |
236 | (define %base-file-systems |
237 | ;; List of basic file systems to be mounted. Note that /proc and /sys are | |
238 | ;; currently mounted by the initrd. | |
cc0e575a | 239 | (append (list %pseudo-terminal-file-system |
727636aa DT |
240 | %shared-memory-file-system |
241 | %immutable-store) | |
14454f0b | 242 | %elogind-file-systems |
727636aa | 243 | %control-groups)) |
a69576ea | 244 | |
c829bc80 DT |
245 | ;; File systems for Linux containers differ from %base-file-systems in that |
246 | ;; they impose additional restrictions such as no-exec or need different | |
247 | ;; options to function properly. | |
248 | ;; | |
249 | ;; The file system flags and options conform to the libcontainer | |
250 | ;; specification: | |
251 | ;; https://github.com/docker/libcontainer/blob/master/SPEC.md#filesystem | |
252 | (define %container-file-systems | |
253 | (list | |
b57ec5f6 | 254 | ;; Pseudo-terminal file system. |
c829bc80 DT |
255 | (file-system |
256 | (device "none") | |
257 | (mount-point "/dev/pts") | |
258 | (type "devpts") | |
259 | (flags '(no-exec no-suid)) | |
260 | (needed-for-boot? #t) | |
261 | (create-mount-point? #t) | |
262 | (check? #f) | |
263 | (options "newinstance,ptmxmode=0666,mode=620")) | |
264 | ;; Shared memory file system. | |
265 | (file-system | |
266 | (device "tmpfs") | |
267 | (mount-point "/dev/shm") | |
268 | (type "tmpfs") | |
269 | (flags '(no-exec no-suid no-dev)) | |
270 | (options "mode=1777,size=65536k") | |
271 | (needed-for-boot? #t) | |
272 | (create-mount-point? #t) | |
273 | (check? #f)) | |
274 | ;; Message queue file system. | |
275 | (file-system | |
276 | (device "mqueue") | |
277 | (mount-point "/dev/mqueue") | |
278 | (type "mqueue") | |
279 | (flags '(no-exec no-suid no-dev)) | |
280 | (needed-for-boot? #t) | |
281 | (create-mount-point? #t) | |
282 | (check? #f)))) | |
283 | ||
9110c2e9 DT |
284 | \f |
285 | ;;; | |
286 | ;;; Shared file systems, for VMs/containers. | |
287 | ;;; | |
288 | ||
289 | ;; Mapping of host file system SOURCE to mount point TARGET in the guest. | |
290 | (define-record-type* <file-system-mapping> file-system-mapping | |
291 | make-file-system-mapping | |
292 | file-system-mapping? | |
293 | (source file-system-mapping-source) ;string | |
294 | (target file-system-mapping-target) ;string | |
295 | (writable? file-system-mapping-writable? ;Boolean | |
296 | (default #f))) | |
297 | ||
298 | (define %store-mapping | |
299 | ;; Mapping of the host's store into the guest. | |
300 | (file-system-mapping | |
301 | (source (%store-prefix)) | |
302 | (target (%store-prefix)) | |
303 | (writable? #f))) | |
304 | ||
c5df1839 | 305 | ;;; file-systems.scm ends here |