1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2013, 2014, 2015, 2016 Ludovic Courtès <ludo@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 system file-systems)
20 #:use-module (ice-9 match)
21 #:use-module (guix gexp)
22 #:use-module (guix records)
23 #:use-module (guix store)
24 #:use-module ((gnu build file-systems)
25 #:select (string->uuid uuid->string))
26 #:re-export (string->uuid
28 #:export (<file-system>
33 file-system-mount-point
35 file-system-needed-for-boot?
40 file-system-create-mount-point?
41 file-system-dependencies
46 %fuse-control-file-system
47 %binary-format-file-system
48 %shared-memory-file-system
49 %pseudo-terminal-file-system
55 %container-file-systems
65 mapped-device-kind-open
66 mapped-device-kind-close
71 file-system-mapping-source
72 file-system-mapping-target
73 file-system-mapping-writable?
79 ;;; Declaring file systems to be mounted.
83 ;; File system declaration.
84 (define-record-type* <file-system> file-system
87 (device file-system-device) ; string
88 (title file-system-title ; 'device | 'label | 'uuid
90 (mount-point file-system-mount-point) ; string
91 (type file-system-type) ; string
92 (flags file-system-flags ; list of symbols
94 (options file-system-options ; string or #f
96 (mount? file-system-mount? ; Boolean
98 (needed-for-boot? %file-system-needed-for-boot? ; Boolean
100 (check? file-system-check? ; Boolean
102 (create-mount-point? file-system-create-mount-point? ; Boolean
104 (dependencies file-system-dependencies ; list of <file-system>
105 (default '()))) ; or <mapped-device>
107 (define-inlinable (file-system-needed-for-boot? fs)
108 "Return true if FS has the 'needed-for-boot?' flag set, or if it's the root
110 (or (%file-system-needed-for-boot? fs)
111 (string=? "/" (file-system-mount-point fs))))
113 (define (file-system->spec fs)
114 "Return a list corresponding to file-system FS that can be passed to the
117 (($ <file-system> device title mount-point type flags options _ _ check?)
118 (list device title mount-point type flags options check?))))
122 "Return the bytevector corresponding to the given UUID representation."
125 (string? (syntax->datum #'str))
126 ;; A literal string: do the conversion at expansion time.
127 (let ((bv (string->uuid (syntax->datum #'str))))
129 (syntax-violation 'uuid "invalid UUID" s))
130 (datum->syntax #'str bv)))
132 #'(string->uuid str)))))
136 ;;; Common file systems.
139 (define %fuse-control-file-system
140 ;; Control file system for Linux' file systems in user-space (FUSE).
143 (mount-point "/sys/fs/fuse/connections")
147 (define %binary-format-file-system
148 ;; Support for arbitrary executable binary format.
150 (device "binfmt_misc")
151 (mount-point "/proc/sys/fs/binfmt_misc")
156 ;; ID of the 'tty' group. Allocate it statically to make it easy to refer
157 ;; to it from here and from the 'tty' group definitions.
160 (define %pseudo-terminal-file-system
161 ;; The pseudo-terminal file system. It needs to be mounted so that
162 ;; statfs(2) returns DEVPTS_SUPER_MAGIC like libc's getpt(3) expects (and
163 ;; thus openpty(3) and its users, such as xterm.)
166 (mount-point "/dev/pts")
169 (needed-for-boot? #f)
170 (create-mount-point? #t)
171 (options (string-append "gid=" (number->string %tty-gid) ",mode=620"))))
173 (define %shared-memory-file-system
177 (mount-point "/dev/shm")
180 (flags '(no-suid no-dev))
181 (options "size=50%") ;TODO: make size configurable
182 (create-mount-point? #t)))
184 (define %immutable-store
185 ;; Read-only store to avoid users or daemons accidentally modifying it.
186 ;; 'guix-daemon' has provisions to remount it read-write in its own name
189 (device (%store-prefix))
190 (mount-point (%store-prefix))
193 (flags '(read-only bind-mount))))
195 (define %control-groups
196 (let ((parent (file-system
198 (mount-point "/sys/fs/cgroup")
202 (map (lambda (subsystem)
205 (mount-point (string-append "/sys/fs/cgroup/" subsystem))
209 (create-mount-point? #t)
211 ;; This must be mounted after, and unmounted before the
213 (dependencies (list parent))))
214 '("cpuset" "cpu" "cpuacct" "memory" "devices" "freezer"
215 "blkio" "perf_event" "hugetlb")))))
217 (define %elogind-file-systems
218 ;; We don't use systemd, but these file systems are needed for elogind,
219 ;; which was extracted from systemd.
222 (mount-point "/run/systemd")
225 (flags '(no-suid no-dev no-exec))
226 (options "mode=0755")
227 (create-mount-point? #t))
230 (mount-point "/run/user")
233 (flags '(no-suid no-dev no-exec))
234 (options "mode=0755")
235 (create-mount-point? #t))
236 ;; Elogind uses cgroups to organize processes, allowing it to map PIDs
237 ;; to sessions. Elogind's cgroup hierarchy isn't associated with any
238 ;; resource controller ("subsystem").
241 (mount-point "/sys/fs/cgroup/elogind")
244 (options "none,name=elogind")
245 (create-mount-point? #t)
246 (dependencies (list (car %control-groups))))))
248 (define %base-file-systems
249 ;; List of basic file systems to be mounted. Note that /proc and /sys are
250 ;; currently mounted by the initrd.
251 (append (list %pseudo-terminal-file-system
252 %shared-memory-file-system
254 %elogind-file-systems
257 ;; File systems for Linux containers differ from %base-file-systems in that
258 ;; they impose additional restrictions such as no-exec or need different
259 ;; options to function properly.
261 ;; The file system flags and options conform to the libcontainer
263 ;; https://github.com/docker/libcontainer/blob/master/SPEC.md#filesystem
264 (define %container-file-systems
266 ;; Pseudo-terminal file system.
269 (mount-point "/dev/pts")
271 (flags '(no-exec no-suid))
272 (needed-for-boot? #t)
273 (create-mount-point? #t)
275 (options "newinstance,ptmxmode=0666,mode=620"))
276 ;; Shared memory file system.
279 (mount-point "/dev/shm")
281 (flags '(no-exec no-suid no-dev))
282 (options "mode=1777,size=65536k")
283 (needed-for-boot? #t)
284 (create-mount-point? #t)
286 ;; Message queue file system.
289 (mount-point "/dev/mqueue")
291 (flags '(no-exec no-suid no-dev))
292 (needed-for-boot? #t)
293 (create-mount-point? #t)
299 ;;; Mapped devices, for Linux's device-mapper.
302 (define-record-type* <mapped-device> mapped-device
305 (source mapped-device-source) ;string
306 (target mapped-device-target) ;string
307 (type mapped-device-type)) ;<mapped-device-kind>
309 (define-record-type* <mapped-device-type> mapped-device-kind
310 make-mapped-device-kind
312 (open mapped-device-kind-open) ;source target -> gexp
313 (close mapped-device-kind-close ;source target -> gexp
314 (default (const #~(const #f)))))
318 ;;; Shared file systems, for VMs/containers.
321 ;; Mapping of host file system SOURCE to mount point TARGET in the guest.
322 (define-record-type* <file-system-mapping> file-system-mapping
323 make-file-system-mapping
325 (source file-system-mapping-source) ;string
326 (target file-system-mapping-target) ;string
327 (writable? file-system-mapping-writable? ;Boolean
330 (define %store-mapping
331 ;; Mapping of the host's store into the guest.
333 (source (%store-prefix))
334 (target (%store-prefix))
337 ;;; file-systems.scm ends here