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