Commit | Line | Data |
---|---|---|
033adfe7 | 1 | ;;; GNU Guix --- Functional package management for GNU |
cda75110 | 2 | ;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org> |
5e738ac2 | 3 | ;;; Copyright © 2015 Mark H Weaver <mhw@netris.org> |
5dccaffe | 4 | ;;; Copyright © 2015, 2016 Alex Kost <alezost@gmail.com> |
1ef8b72a | 5 | ;;; Copyright © 2016 Chris Marusich <cmmarusich@gmail.com> |
c76b3046 | 6 | ;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com> |
5144df2c | 7 | ;;; Copyright © 2019 Meiyo Peng <meiyo.peng@gmail.com> |
5c79f238 | 8 | ;;; Copyright © 2020 Danny Milosavljevic <dannym@scratchpost.org> |
93664fee | 9 | ;;; Copyright © 2020 Brice Waegeneire <brice@waegenei.re> |
e06664da | 10 | ;;; Copyright © 2020 Florian Pelz <pelzflorian@pelzflorian.de> |
b460ba79 | 11 | ;;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer@gmail.com> |
033adfe7 LC |
12 | ;;; |
13 | ;;; This file is part of GNU Guix. | |
14 | ;;; | |
15 | ;;; GNU Guix is free software; you can redistribute it and/or modify it | |
16 | ;;; under the terms of the GNU General Public License as published by | |
17 | ;;; the Free Software Foundation; either version 3 of the License, or (at | |
18 | ;;; your option) any later version. | |
19 | ;;; | |
20 | ;;; GNU Guix is distributed in the hope that it will be useful, but | |
21 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
23 | ;;; GNU General Public License for more details. | |
24 | ;;; | |
25 | ;;; You should have received a copy of the GNU General Public License | |
26 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | |
27 | ||
28 | (define-module (gnu system) | |
bdc61ff9 | 29 | #:use-module (guix inferior) |
033adfe7 LC |
30 | #:use-module (guix store) |
31 | #:use-module (guix monads) | |
02100028 | 32 | #:use-module (guix gexp) |
033adfe7 LC |
33 | #:use-module (guix records) |
34 | #:use-module (guix packages) | |
35 | #:use-module (guix derivations) | |
29fce8b6 | 36 | #:use-module (guix profiles) |
84765839 | 37 | #:use-module (guix ui) |
f91ad0b1 | 38 | #:use-module (guix utils) |
033adfe7 LC |
39 | #:use-module (gnu packages base) |
40 | #:use-module (gnu packages bash) | |
bdb36958 | 41 | #:use-module (gnu packages guile) |
01ac0e6b | 42 | #:use-module (gnu packages guile-xyz) |
9de46ffb | 43 | #:use-module (gnu packages admin) |
8a07c289 | 44 | #:use-module (gnu packages linux) |
a96a82d7 | 45 | #:use-module (gnu packages pciutils) |
033adfe7 | 46 | #:use-module (gnu packages package-management) |
6f436c54 LC |
47 | #:use-module (gnu packages less) |
48 | #:use-module (gnu packages zile) | |
55e70e65 | 49 | #:use-module (gnu packages nano) |
a68c6967 | 50 | #:use-module (gnu packages gawk) |
18316d86 | 51 | #:use-module (gnu packages man) |
939c5c31 | 52 | #:use-module (gnu packages texinfo) |
a68c6967 | 53 | #:use-module (gnu packages compression) |
f34c56be | 54 | #:use-module (gnu packages firmware) |
db4fdc04 | 55 | #:use-module (gnu services) |
0190c1c0 | 56 | #:use-module (gnu services shepherd) |
db4fdc04 | 57 | #:use-module (gnu services base) |
b09a8da4 | 58 | #:use-module (gnu bootloader) |
033adfe7 | 59 | #:use-module (gnu system shadow) |
996ed739 | 60 | #:use-module (gnu system nss) |
598e19dc | 61 | #:use-module (gnu system locale) |
6e828634 | 62 | #:use-module (gnu system pam) |
735c6dd7 | 63 | #:use-module (gnu system linux-initrd) |
9b336338 | 64 | #:use-module (gnu system uuid) |
c5df1839 | 65 | #:use-module (gnu system file-systems) |
060d62a7 | 66 | #:use-module (gnu system mapped-devices) |
033adfe7 LC |
67 | #:use-module (ice-9 match) |
68 | #:use-module (srfi srfi-1) | |
69 | #:use-module (srfi srfi-26) | |
598e19dc LC |
70 | #:use-module (srfi srfi-34) |
71 | #:use-module (srfi srfi-35) | |
3382bfe9 | 72 | #:use-module (rnrs bytevectors) |
033adfe7 LC |
73 | #:export (operating-system |
74 | operating-system? | |
d8bead6c | 75 | this-operating-system |
d5b429ab LC |
76 | |
77 | operating-system-bootloader | |
033adfe7 | 78 | operating-system-services |
69cae3d3 | 79 | operating-system-essential-services |
f8885eca | 80 | operating-system-default-essential-services |
217a5b85 | 81 | operating-system-user-services |
033adfe7 | 82 | operating-system-packages |
fd3bfc44 | 83 | operating-system-host-name |
c65e1834 | 84 | operating-system-hosts-file |
fd3bfc44 | 85 | operating-system-kernel |
44d5f54e | 86 | operating-system-kernel-file |
33f0aa88 | 87 | operating-system-kernel-arguments |
3f03a198 LC |
88 | operating-system-label |
89 | operating-system-default-label | |
bc499b11 | 90 | operating-system-initrd-modules |
fd3bfc44 LC |
91 | operating-system-initrd |
92 | operating-system-users | |
93 | operating-system-groups | |
548d4c13 | 94 | operating-system-issue |
fd3bfc44 LC |
95 | operating-system-timezone |
96 | operating-system-locale | |
598e19dc | 97 | operating-system-locale-definitions |
34760ae7 | 98 | operating-system-locale-libcs |
5dae0186 | 99 | operating-system-mapped-devices |
83bcd0b8 | 100 | operating-system-file-systems |
6b779207 | 101 | operating-system-store-file-system |
2bdd7ac1 LC |
102 | operating-system-user-mapped-devices |
103 | operating-system-boot-mapped-devices | |
b25937e3 | 104 | operating-system-activation-script |
b2fef041 LC |
105 | operating-system-user-accounts |
106 | operating-system-shepherd-service-names | |
20abb8c4 | 107 | operating-system-user-kernel-arguments |
9ef37e81 BW |
108 | operating-system-firmware |
109 | operating-system-keyboard-layout | |
110 | operating-system-name-service-switch | |
111 | operating-system-pam-services | |
112 | operating-system-setuid-programs | |
113 | operating-system-skeletons | |
114 | operating-system-sudoers-file | |
115 | operating-system-swap-devices | |
a9f2c210 | 116 | operating-system-kernel-loadable-modules |
033adfe7 | 117 | |
1aa0033b | 118 | operating-system-derivation |
83bcd0b8 | 119 | operating-system-profile |
c76b3046 | 120 | operating-system-bootcfg |
239db054 DT |
121 | operating-system-etc-directory |
122 | operating-system-locale-directory | |
123 | operating-system-boot-script | |
78fbf2bd | 124 | operating-system-uuid |
239db054 | 125 | |
43fe431c | 126 | system-linux-image-file-name |
9fcfe30d | 127 | operating-system-with-gc-roots |
33b7cb7a | 128 | operating-system-with-provenance |
43fe431c | 129 | |
b8300494 AK |
130 | boot-parameters |
131 | boot-parameters? | |
132 | boot-parameters-label | |
133 | boot-parameters-root-device | |
f96752e3 | 134 | boot-parameters-bootloader-name |
a28cfee8 | 135 | boot-parameters-bootloader-menu-entries |
1ef8b72a CM |
136 | boot-parameters-store-device |
137 | boot-parameters-store-mount-point | |
b8300494 AK |
138 | boot-parameters-kernel |
139 | boot-parameters-kernel-arguments | |
d7b342d8 | 140 | boot-parameters-initrd |
4e4e0185 | 141 | read-boot-parameters |
9530e73b | 142 | read-boot-parameters-file |
1975c754 | 143 | boot-parameters->menu-entry |
b8300494 | 144 | |
568841d4 | 145 | local-host-aliases |
d0f3a672 | 146 | %root-account |
df5ce088 | 147 | %setuid-programs |
f6b95031 | 148 | %sudoers-specification |
5dae0186 | 149 | %base-packages |
93664fee BW |
150 | %base-packages-interactive |
151 | %base-packages-linux | |
152 | %base-packages-networking | |
153 | %base-packages-utils | |
e06664da FP |
154 | %base-firmware |
155 | %default-kernel-arguments)) | |
033adfe7 LC |
156 | |
157 | ;;; Commentary: | |
158 | ;;; | |
159 | ;;; This module supports whole-system configuration. | |
160 | ;;; | |
161 | ;;; Code: | |
162 | ||
a7ef45d9 LC |
163 | (define (bootable-kernel-arguments system root-device) |
164 | "Return a list of kernel arguments (gexps) to boot SYSTEM from ROOT-DEVICE." | |
165 | (list (string-append "--root=" | |
99e676db MC |
166 | ;; Note: Always use the DCE format because that's what |
167 | ;; (gnu build linux-boot) expects for the '--root' | |
168 | ;; kernel command-line option. | |
169 | (file-system-device->string root-device | |
170 | #:uuid-type 'dce)) | |
a7ef45d9 LC |
171 | #~(string-append "--system=" #$system) |
172 | #~(string-append "--load=" #$system "/boot"))) | |
33f0aa88 | 173 | |
033adfe7 LC |
174 | ;; System-wide configuration. |
175 | ;; TODO: Add per-field docstrings/stexi. | |
176 | (define-record-type* <operating-system> operating-system | |
177 | make-operating-system | |
178 | operating-system? | |
d8bead6c LC |
179 | this-operating-system |
180 | ||
033adfe7 | 181 | (kernel operating-system-kernel ; package |
57082417 | 182 | (default linux-libre)) |
5c79f238 DM |
183 | (kernel-loadable-modules operating-system-kernel-loadable-modules |
184 | (default '())) ; list of packages | |
af98d25a | 185 | (kernel-arguments operating-system-user-kernel-arguments |
e06664da | 186 | (default %default-kernel-arguments)) ; list of gexps/strings |
b09a8da4 | 187 | (bootloader operating-system-bootloader) ; <bootloader-configuration> |
3f03a198 LC |
188 | (label operating-system-label ; string |
189 | (thunked) | |
190 | (default (operating-system-default-label this-operating-system))) | |
d5b429ab | 191 | |
ae7a316b LC |
192 | (keyboard-layout operating-system-keyboard-layout ;#f | <keyboard-layout> |
193 | (default #f)) | |
e34ae75d | 194 | (initrd operating-system-initrd ; (list fs) -> file-like |
060238ae | 195 | (default base-initrd)) |
bc499b11 LC |
196 | (initrd-modules operating-system-initrd-modules ; list of strings |
197 | (thunked) ; it's system-dependent | |
198 | (default %base-initrd-modules)) | |
199 | ||
f34c56be LC |
200 | (firmware operating-system-firmware ; list of packages |
201 | (default %base-firmware)) | |
033adfe7 LC |
202 | |
203 | (host-name operating-system-host-name) ; string | |
24e02c28 | 204 | (hosts-file operating-system-hosts-file ; file-like | #f |
c65e1834 | 205 | (default #f)) |
033adfe7 | 206 | |
5dae0186 LC |
207 | (mapped-devices operating-system-mapped-devices ; list of <mapped-device> |
208 | (default '())) | |
8a6d2731 | 209 | (file-systems operating-system-file-systems) ; list of fs |
2a13d05e LC |
210 | (swap-devices operating-system-swap-devices ; list of strings |
211 | (default '())) | |
033adfe7 LC |
212 | |
213 | (users operating-system-users ; list of user accounts | |
bf87f38a | 214 | (default %base-user-accounts)) |
033adfe7 | 215 | (groups operating-system-groups ; list of user groups |
773e956d | 216 | (default %base-groups)) |
033adfe7 | 217 | |
ac3c14fb | 218 | (skeletons operating-system-skeletons ; list of name/file-like value |
40281c54 | 219 | (default (default-skeletons))) |
548d4c13 LC |
220 | (issue operating-system-issue ; string |
221 | (default %default-issue)) | |
40281c54 | 222 | |
033adfe7 | 223 | (packages operating-system-packages ; list of (PACKAGE OUTPUT...) |
6f436c54 | 224 | (default %base-packages)) ; or just PACKAGE |
033adfe7 LC |
225 | |
226 | (timezone operating-system-timezone) ; string | |
8a6d2731 | 227 | (locale operating-system-locale ; string |
598e19dc LC |
228 | (default "en_US.utf8")) |
229 | (locale-definitions operating-system-locale-definitions ; list of <locale-definition> | |
230 | (default %default-locale-definitions)) | |
34760ae7 LC |
231 | (locale-libcs operating-system-locale-libcs ; list of <packages> |
232 | (default %default-locale-libcs)) | |
996ed739 LC |
233 | (name-service-switch operating-system-name-service-switch ; <name-service-switch> |
234 | (default %default-nss)) | |
033adfe7 | 235 | |
69cae3d3 LC |
236 | (essential-services operating-system-essential-services ; list of services |
237 | (thunked) | |
f8885eca LC |
238 | (default (operating-system-default-essential-services |
239 | this-operating-system))) | |
ac3c14fb | 240 | (services operating-system-user-services ; list of services |
09e028f4 LC |
241 | (default %base-services)) |
242 | ||
243 | (pam-services operating-system-pam-services ; list of PAM services | |
244 | (default (base-pam-services))) | |
245 | (setuid-programs operating-system-setuid-programs | |
69689380 | 246 | (default %setuid-programs)) ; list of string-valued gexps |
033adfe7 | 247 | |
f5a9ffa0 AK |
248 | (sudoers-file operating-system-sudoers-file ; file-like |
249 | (default %sudoers-specification))) | |
033adfe7 | 250 | |
a7ef45d9 | 251 | (define (operating-system-kernel-arguments os root-device) |
33f0aa88 DM |
252 | "Return all the kernel arguments, including the ones not specified |
253 | directly by the user." | |
a7ef45d9 LC |
254 | (append (bootable-kernel-arguments os root-device) |
255 | (operating-system-user-kernel-arguments os))) | |
33f0aa88 | 256 | |
2717a89a | 257 | \f |
8e815c5b LC |
258 | ;;; |
259 | ;;; Boot parameters | |
260 | ;;; | |
261 | ||
262 | (define-record-type* <boot-parameters> | |
263 | boot-parameters make-boot-parameters boot-parameters? | |
264 | (label boot-parameters-label) | |
265 | ;; Because we will use the 'store-device' to create the GRUB search command, | |
266 | ;; the 'store-device' has slightly different semantics than 'root-device'. | |
267 | ;; The 'store-device' can be a file system uuid, a file system label, or #f, | |
268 | ;; but it cannot be a device path such as "/dev/sda3", since GRUB would not | |
269 | ;; understand that. The 'root-device', on the other hand, corresponds | |
270 | ;; exactly to the device field of the <file-system> object representing the | |
271 | ;; OS's root file system, so it might be a device path like "/dev/sda3". | |
272 | (root-device boot-parameters-root-device) | |
f96752e3 | 273 | (bootloader-name boot-parameters-bootloader-name) |
a28cfee8 LC |
274 | (bootloader-menu-entries ;list of <menu-entry> |
275 | boot-parameters-bootloader-menu-entries) | |
8e815c5b LC |
276 | (store-device boot-parameters-store-device) |
277 | (store-mount-point boot-parameters-store-mount-point) | |
278 | (kernel boot-parameters-kernel) | |
279 | (kernel-arguments boot-parameters-kernel-arguments) | |
280 | (initrd boot-parameters-initrd)) | |
281 | ||
90d23ed9 LC |
282 | (define (ensure-not-/dev device) |
283 | "If DEVICE starts with a slash, return #f. This is meant to filter out | |
284 | Linux device names such as /dev/sda, and to preserve GRUB device names and | |
285 | file system labels." | |
286 | (if (and (string? device) (string-prefix? "/" device)) | |
287 | #f | |
288 | device)) | |
289 | ||
8e815c5b LC |
290 | (define (read-boot-parameters port) |
291 | "Read boot parameters from PORT and return the corresponding | |
292 | <boot-parameters> object or #f if the format is unrecognized." | |
075681d3 LC |
293 | (define device-sexp->device |
294 | (match-lambda | |
295 | (('uuid (? symbol? type) (? bytevector? bv)) | |
296 | (bytevector->uuid bv type)) | |
a5acc17a LC |
297 | (('file-system-label (? string? label)) |
298 | (file-system-label label)) | |
075681d3 LC |
299 | ((? bytevector? bv) ;old format |
300 | (bytevector->uuid bv 'dce)) | |
301 | ((? string? device) | |
a5acc17a LC |
302 | ;; It used to be that we would not distinguish between labels and |
303 | ;; device names. Try to infer the right thing here. | |
304 | (if (string-prefix? "/dev/" device) | |
305 | device | |
306 | (file-system-label device))))) | |
075681d3 | 307 | |
8e815c5b LC |
308 | (match (read port) |
309 | (('boot-parameters ('version 0) | |
310 | ('label label) ('root-device root) | |
311 | ('kernel linux) | |
312 | rest ...) | |
313 | (boot-parameters | |
314 | (label label) | |
7940188e | 315 | (root-device (device-sexp->device root)) |
8e815c5b | 316 | |
f96752e3 MO |
317 | (bootloader-name |
318 | (match (assq 'bootloader-name rest) | |
bcaf67c4 MO |
319 | ((_ args) args) |
320 | (#f 'grub))) ; for compatibility reasons. | |
321 | ||
a28cfee8 LC |
322 | (bootloader-menu-entries |
323 | (match (assq 'bootloader-menu-entries rest) | |
324 | ((_ entries) (map sexp->menu-entry entries)) | |
325 | (#f '()))) | |
326 | ||
8e815c5b LC |
327 | ;; In the past, we would store the directory name of the kernel instead |
328 | ;; of the absolute file name of its image. Detect that and correct it. | |
329 | (kernel (if (string=? linux (direct-store-path linux)) | |
330 | (string-append linux "/" | |
331 | (system-linux-image-file-name)) | |
332 | linux)) | |
333 | ||
334 | (kernel-arguments | |
335 | (match (assq 'kernel-arguments rest) | |
336 | ((_ args) args) | |
337 | (#f '()))) ;the old format | |
338 | ||
339 | (initrd | |
340 | (match (assq 'initrd rest) | |
341 | (('initrd ('string-append directory file)) ;the old format | |
342 | (string-append directory file)) | |
343 | (('initrd (? string? file)) | |
344 | file))) | |
345 | ||
346 | (store-device | |
db4e8fd5 LC |
347 | ;; Linux device names like "/dev/sda1" are not suitable GRUB device |
348 | ;; identifiers, so we just filter them out. | |
349 | (ensure-not-/dev | |
350 | (match (assq 'store rest) | |
351 | (('store ('device #f) _ ...) | |
352 | root-device) | |
353 | (('store ('device device) _ ...) | |
354 | (device-sexp->device device)) | |
355 | (_ ;the old format | |
356 | root-device)))) | |
8e815c5b LC |
357 | |
358 | (store-mount-point | |
359 | (match (assq 'store rest) | |
360 | (('store ('device _) ('mount-point mount-point) _ ...) | |
361 | mount-point) | |
362 | (_ ;the old format | |
363 | "/"))))) | |
364 | (x ;unsupported format | |
b1059b38 LC |
365 | (warning (G_ "unrecognized boot parameters at '~a'~%") |
366 | (port-filename port)) | |
8e815c5b LC |
367 | #f))) |
368 | ||
369 | (define (read-boot-parameters-file system) | |
370 | "Read boot parameters from SYSTEM's (system or generation) \"parameters\" | |
371 | file and returns the corresponding <boot-parameters> object or #f if the | |
372 | format is unrecognized. | |
373 | The object has its kernel-arguments extended in order to make it bootable." | |
374 | (let* ((file (string-append system "/parameters")) | |
375 | (params (call-with-input-file file read-boot-parameters)) | |
a7ef45d9 LC |
376 | (root (boot-parameters-root-device params))) |
377 | (boot-parameters | |
378 | (inherit params) | |
379 | (kernel-arguments (append (bootable-kernel-arguments system root) | |
380 | (boot-parameters-kernel-arguments params)))))) | |
8b22107e | 381 | |
1975c754 DM |
382 | (define (boot-parameters->menu-entry conf) |
383 | (menu-entry | |
384 | (label (boot-parameters-label conf)) | |
385 | (device (boot-parameters-store-device conf)) | |
386 | (device-mount-point (boot-parameters-store-mount-point conf)) | |
387 | (linux (boot-parameters-kernel conf)) | |
388 | (linux-arguments (boot-parameters-kernel-arguments conf)) | |
389 | (initrd (boot-parameters-initrd conf)))) | |
390 | ||
8b22107e | 391 | |
8e815c5b | 392 | \f |
40281c54 LC |
393 | ;;; |
394 | ;;; Services. | |
395 | ;;; | |
396 | ||
aa1145df LC |
397 | (define (non-boot-file-system-service os) |
398 | "Return the file system service for the file systems of OS that are not | |
399 | marked as 'needed-for-boot'." | |
023f391c | 400 | (define file-systems |
4d6b879c | 401 | (remove file-system-needed-for-boot? |
023f391c LC |
402 | (operating-system-file-systems os))) |
403 | ||
68a58775 LC |
404 | (define mapped-devices-for-boot |
405 | (operating-system-boot-mapped-devices os)) | |
406 | ||
5dae0186 | 407 | (define (device-mappings fs) |
ab64483f | 408 | (let ((device (file-system-device fs))) |
29824d80 | 409 | (if (string? device) ;title is 'device |
ab64483f LC |
410 | (filter (lambda (md) |
411 | (string=? (string-append "/dev/mapper/" | |
412 | (mapped-device-target md)) | |
413 | device)) | |
414 | (operating-system-mapped-devices os)) | |
415 | '()))) | |
5dae0186 | 416 | |
e502bf89 LC |
417 | (define (add-dependencies fs) |
418 | ;; Add the dependencies due to device mappings to FS. | |
419 | (file-system | |
420 | (inherit fs) | |
421 | (dependencies | |
68a58775 LC |
422 | (delete-duplicates |
423 | (remove (cut member <> mapped-devices-for-boot) | |
424 | (append (device-mappings fs) | |
425 | (file-system-dependencies fs))) | |
426 | eq?)))) | |
e502bf89 | 427 | |
aa1145df LC |
428 | (service file-system-service-type |
429 | (map add-dependencies file-systems))) | |
023f391c | 430 | |
68a58775 LC |
431 | (define (mapped-device-users device file-systems) |
432 | "Return the subset of FILE-SYSTEMS that use DEVICE." | |
de1c158f | 433 | (let ((target (string-append "/dev/mapper/" (mapped-device-target device)))) |
68a58775 LC |
434 | (filter (lambda (fs) |
435 | (or (member device (file-system-dependencies fs)) | |
436 | (and (string? (file-system-device fs)) | |
437 | (string=? (file-system-device fs) target)))) | |
438 | file-systems))) | |
de1c158f LC |
439 | |
440 | (define (operating-system-user-mapped-devices os) | |
441 | "Return the subset of mapped devices that can be installed in | |
442 | user-land--i.e., those not needed during boot." | |
9cb426b8 LC |
443 | (let ((devices (operating-system-mapped-devices os)) |
444 | (file-systems (operating-system-file-systems os))) | |
445 | (filter (lambda (md) | |
68a58775 LC |
446 | (let ((users (mapped-device-users md file-systems))) |
447 | (not (any file-system-needed-for-boot? users)))) | |
9cb426b8 | 448 | devices))) |
de1c158f LC |
449 | |
450 | (define (operating-system-boot-mapped-devices os) | |
451 | "Return the subset of mapped devices that must be installed during boot, | |
452 | from the initrd." | |
9cb426b8 LC |
453 | (let ((devices (operating-system-mapped-devices os)) |
454 | (file-systems (operating-system-file-systems os))) | |
455 | (filter (lambda (md) | |
68a58775 LC |
456 | (let ((users (mapped-device-users md file-systems))) |
457 | (any file-system-needed-for-boot? users))) | |
9cb426b8 | 458 | devices))) |
de1c158f | 459 | |
5dae0186 | 460 | (define (device-mapping-services os) |
be1c2c54 | 461 | "Return the list of device-mapping services for OS as a list." |
4da8c19e | 462 | (map device-mapping-service |
be1c2c54 | 463 | (operating-system-user-mapped-devices os))) |
5dae0186 | 464 | |
2a13d05e | 465 | (define (swap-services os) |
be1c2c54 LC |
466 | "Return the list of swap services for OS." |
467 | (map swap-service (operating-system-swap-devices os))) | |
2a13d05e | 468 | |
d4ddf22d | 469 | (define* (system-linux-image-file-name) |
44d5f54e LC |
470 | "Return the basename of the kernel image file for SYSTEM." |
471 | ;; FIXME: Evaluate the conditional based on the actual current system. | |
d4ddf22d MO |
472 | (let ((target (or (%current-target-system) (%current-system)))) |
473 | (cond | |
474 | ((string-prefix? "arm" target) "zImage") | |
475 | ((string-prefix? "mips" target) "vmlinuz") | |
476 | ((string-prefix? "aarch64" target) "Image") | |
477 | (else "bzImage")))) | |
44d5f54e LC |
478 | |
479 | (define (operating-system-kernel-file os) | |
480 | "Return an object representing the absolute file name of the kernel image of | |
481 | OS." | |
482 | (file-append (operating-system-kernel os) | |
d4ddf22d | 483 | "/" (system-linux-image-file-name))) |
44d5f54e | 484 | |
f91ad0b1 DM |
485 | (define (package-for-kernel target-kernel module-package) |
486 | "Return a package like MODULE-PACKAGE, adapted for TARGET-KERNEL, if | |
487 | possible (that is if there's a LINUX keyword argument in the build system)." | |
488 | (package | |
489 | (inherit module-package) | |
490 | (arguments | |
491 | (substitute-keyword-arguments (package-arguments module-package) | |
492 | ((#:linux kernel #f) | |
493 | target-kernel))))) | |
494 | ||
e06664da FP |
495 | (define %default-modprobe-blacklist |
496 | ;; List of kernel modules to blacklist by default. | |
fd31731b FP |
497 | '("usbmouse" ;races with bcm5974, see <https://bugs.gnu.org/35574> |
498 | "usbkbd")) ;races with usbhid, see <https://issues.guix.gnu.org/35574#18> | |
e06664da FP |
499 | |
500 | (define %default-kernel-arguments | |
501 | ;; Default arguments passed to the kernel. | |
502 | (list (string-append "modprobe.blacklist=" | |
503 | (string-join %default-modprobe-blacklist ",")) | |
504 | "quiet")) | |
505 | ||
69cae3d3 | 506 | (define* (operating-system-directory-base-entries os) |
d62e201c LC |
507 | "Return the basic entries of the 'system' directory of OS for use as the |
508 | value of the SYSTEM-SERVICE-TYPE service." | |
cda75110 LC |
509 | (let* ((locale (operating-system-locale-directory os)) |
510 | (kernel (operating-system-kernel os)) | |
511 | (modules (operating-system-kernel-loadable-modules os)) | |
512 | (kernel (profile | |
513 | (content (packages->manifest | |
514 | (cons kernel | |
515 | (map (lambda (module) | |
516 | (if (package? module) | |
517 | (package-for-kernel kernel | |
518 | module) | |
519 | module)) | |
520 | modules)))) | |
521 | (hooks (list linux-module-database)))) | |
522 | (initrd (operating-system-initrd-file os)) | |
523 | (params (operating-system-boot-parameters-file os))) | |
0e5c2d5e LC |
524 | `(("kernel" ,kernel) |
525 | ("parameters" ,params) | |
526 | ("initrd" ,initrd) | |
527 | ("locale" ,locale)))) ;used by libc | |
69cae3d3 | 528 | |
f8885eca | 529 | (define (operating-system-default-essential-services os) |
217a5b85 LC |
530 | "Return the list of essential services for OS. These are special services |
531 | that implement part of what's declared in OS are responsible for low-level | |
69cae3d3 | 532 | bookkeeping." |
d6e2a622 LC |
533 | (define known-fs |
534 | (map file-system-mount-point (operating-system-file-systems os))) | |
535 | ||
be1c2c54 LC |
536 | (let* ((mappings (device-mapping-services os)) |
537 | (root-fs (root-file-system-service)) | |
aa1145df | 538 | (other-fs (non-boot-file-system-service os)) |
be1c2c54 | 539 | (swaps (swap-services os)) |
206a28d8 | 540 | (procs (service user-processes-service-type)) |
d62e201c | 541 | (host-name (host-name-service (operating-system-host-name os))) |
69cae3d3 | 542 | (entries (operating-system-directory-base-entries os))) |
d62e201c LC |
543 | (cons* (service system-service-type entries) |
544 | %boot-service | |
0adfe95a | 545 | |
661c237b | 546 | ;; %SHEPHERD-ROOT-SERVICE must come last so that the gexp that |
d4053c71 | 547 | ;; execs shepherd comes last in the boot script (XXX). Likewise, |
661c237b | 548 | ;; the cleanup service must come first so that its gexp runs before |
d4053c71 | 549 | ;; activation code. |
be7be9e8 | 550 | (service cleanup-service-type #f) |
661c237b LC |
551 | %activation-service |
552 | %shepherd-root-service | |
0adfe95a LC |
553 | |
554 | (pam-root-service (operating-system-pam-services os)) | |
555 | (account-service (append (operating-system-accounts os) | |
556 | (operating-system-groups os)) | |
557 | (operating-system-skeletons os)) | |
558 | (operating-system-etc-service os) | |
aea1a42e LC |
559 | (service fstab-service-type |
560 | (filter file-system-needed-for-boot? | |
561 | (operating-system-file-systems os))) | |
6bad7524 SB |
562 | (session-environment-service |
563 | (operating-system-environment-variables os)) | |
6c445817 | 564 | host-name procs root-fs |
0adfe95a LC |
565 | (service setuid-program-service-type |
566 | (operating-system-setuid-programs os)) | |
af4c3fd5 LC |
567 | (service profile-service-type |
568 | (operating-system-packages os)) | |
aa1145df LC |
569 | other-fs |
570 | (append mappings swaps | |
0adfe95a | 571 | |
69cae3d3 LC |
572 | ;; Add the firmware service. |
573 | (list %linux-bare-metal-service | |
574 | (service firmware-service-type | |
575 | (operating-system-firmware os))))))) | |
576 | ||
577 | (define* (operating-system-services os) | |
578 | "Return all the services of OS, including \"essential\" services." | |
d466b1fc LC |
579 | (instantiate-missing-services |
580 | (append (operating-system-user-services os) | |
69cae3d3 | 581 | (operating-system-essential-services os)))) |
217a5b85 | 582 | |
9fcfe30d LC |
583 | (define (operating-system-with-gc-roots os roots) |
584 | "Return a variant of OS where ROOTS are registered as GC roots." | |
585 | (operating-system | |
586 | (inherit os) | |
587 | ||
588 | ;; We use this procedure for the installation OS, which already defines GC | |
589 | ;; roots. Add ROOTS to those. | |
590 | (services (cons (simple-service 'extra-root | |
591 | gc-root-service-type roots) | |
592 | (operating-system-user-services os))))) | |
593 | ||
33b7cb7a LC |
594 | (define* (operating-system-with-provenance os #:optional config-file) |
595 | "Return a variant of OS that stores its own provenance information, | |
596 | including CONFIG-FILE, if available. This is achieved by adding an instance | |
597 | of PROVENANCE-SERVICE-TYPE to its services." | |
598 | (operating-system | |
599 | (inherit os) | |
600 | (services (cons (service provenance-service-type config-file) | |
601 | (operating-system-user-services os))))) | |
602 | ||
40281c54 LC |
603 | \f |
604 | ;;; | |
605 | ;;; /etc. | |
606 | ;;; | |
607 | ||
f34c56be LC |
608 | (define %base-firmware |
609 | ;; Firmware usable by default. | |
52db41af EB |
610 | (list ath9k-htc-firmware |
611 | openfwwf-firmware)) | |
f34c56be | 612 | |
93664fee BW |
613 | (define %base-packages-utils |
614 | ;; Default set of utilities packages. | |
615 | (cons* procps psmisc which | |
616 | (@ (gnu packages admin) shadow) ;for 'passwd' | |
617 | ||
030f6f48 | 618 | guile-3.0 |
93664fee BW |
619 | |
620 | ;; The packages below are also in %FINAL-INPUTS, so take them from | |
621 | ;; there to avoid duplication. | |
030f6f48 MB |
622 | (list bash coreutils findutils grep sed |
623 | diffutils patch gawk tar gzip bzip2 xz lzip))) | |
93664fee BW |
624 | |
625 | (define %base-packages-linux | |
626 | ;; Default set of linux specific packages. | |
627 | (list pciutils usbutils | |
628 | util-linux+udev | |
629 | ;; Get 'insmod' & co. from kmod, not module-init-tools, since udev | |
630 | ;; already depends on it anyway. | |
631 | kmod eudev)) | |
632 | ||
633 | (define %base-packages-interactive | |
634 | ;; Default set of common interactive packages. | |
635 | (list less zile nano | |
636 | man-db | |
637 | info-reader ;the standalone Info reader (no Perl) | |
638 | bash-completion | |
639 | kbd | |
640 | ;; The 'sudo' command is already in %SETUID-PROGRAMS, but we also | |
641 | ;; want the other commands and the man pages (notably because | |
642 | ;; auto-completion in Emacs shell relies on man pages.) | |
643 | sudo | |
644 | guile-readline guile-colorized)) | |
645 | ||
646 | (define %base-packages-networking | |
647 | ;; Default set of networking packages. | |
648 | (list inetutils isc-dhcp | |
649 | iproute | |
650 | ;; wireless-tools is deprecated in favor of iw, but it's still what | |
651 | ;; many people are familiar with, so keep it around. | |
652 | iw wireless-tools)) | |
653 | ||
6f436c54 LC |
654 | (define %base-packages |
655 | ;; Default set of packages globally visible. It should include anything | |
656 | ;; required for basic administrator tasks. | |
93664fee BW |
657 | (append (list e2fsprogs) |
658 | %base-packages-interactive | |
659 | %base-packages-linux | |
660 | %base-packages-networking | |
661 | %base-packages-utils)) | |
6f436c54 | 662 | |
548d4c13 LC |
663 | (define %default-issue |
664 | ;; Default contents for /etc/issue. | |
665 | " | |
666 | This is the GNU system. Welcome.\n") | |
667 | ||
568841d4 LC |
668 | (define (local-host-aliases host-name) |
669 | "Return aliases for HOST-NAME, to be used in /etc/hosts." | |
670 | (string-append "127.0.0.1 localhost " host-name "\n" | |
671 | "::1 localhost " host-name "\n")) | |
672 | ||
c65e1834 LC |
673 | (define (default-/etc/hosts host-name) |
674 | "Return the default /etc/hosts file." | |
24e02c28 | 675 | (plain-file "hosts" (local-host-aliases host-name))) |
c65e1834 | 676 | |
0adfe95a LC |
677 | (define* (operating-system-etc-service os) |
678 | "Return a <service> that builds containing the static part of the /etc | |
679 | directory." | |
e453da13 LF |
680 | (let ((login.defs |
681 | (plain-file "login.defs" | |
682 | (string-append | |
683 | "# Default paths for non-login shells started by su(1).\n" | |
684 | "ENV_PATH /run/setuid-programs:" | |
685 | "/run/current-system/profile/bin:" | |
686 | "/run/current-system/profile/sbin\n" | |
687 | "ENV_SUPATH /run/setuid-programs:" | |
688 | "/run/current-system/profile/bin:" | |
689 | "/run/current-system/profile/sbin\n"))) | |
0adfe95a | 690 | |
0adfe95a LC |
691 | (issue (plain-file "issue" (operating-system-issue os))) |
692 | (nsswitch (plain-file "nsswitch.conf" | |
693 | (name-service-switch->string | |
694 | (operating-system-name-service-switch os)))) | |
695 | ||
696 | ;; Startup file for POSIX-compliant login shells, which set system-wide | |
697 | ;; environment variables. | |
698 | (profile (mixed-text-file "profile" "\ | |
c05c4321 | 699 | # Crucial variables that could be missing in the profiles' 'etc/profile' |
d9959421 LC |
700 | # because they would require combining both profiles. |
701 | # FIXME: See <http://bugs.gnu.org/20255>. | |
97ab2c0f | 702 | export MANPATH=$HOME/.guix-profile/share/man:/run/current-system/profile/share/man |
8d09bfe2 | 703 | export INFOPATH=$HOME/.guix-profile/share/info:/run/current-system/profile/share/info |
00239d05 SB |
704 | export XDG_DATA_DIRS=$HOME/.guix-profile/share:/run/current-system/profile/share |
705 | export XDG_CONFIG_DIRS=$HOME/.guix-profile/etc/xdg:/run/current-system/profile/etc/xdg | |
706 | ||
ce380150 TD |
707 | # Make sure libXcursor finds cursors installed into user or system profiles. See <http://bugs.gnu.org/24445> |
708 | export XCURSOR_PATH=$HOME/.icons:$HOME/.guix-profile/share/icons:/run/current-system/profile/share/icons | |
709 | ||
d9959421 LC |
710 | # Ignore the default value of 'PATH'. |
711 | unset PATH | |
712 | ||
713 | # Load the system profile's settings. | |
bd7e136d | 714 | GUIX_PROFILE=/run/current-system/profile ; \\ |
669786da | 715 | . /run/current-system/profile/etc/profile |
d9959421 | 716 | |
cad7e6ab CSLL |
717 | # Since 'lshd' does not use pam_env, /etc/environment must be explicitly |
718 | # loaded when someone logs in via SSH. See <http://bugs.gnu.org/22175>. | |
719 | # We need 'PATH' to be defined here, for 'cat' and 'cut'. Do this before | |
720 | # reading the user's 'etc/profile' to allow variables to be overridden. | |
721 | if [ -f /etc/environment -a -n \"$SSH_CLIENT\" \\ | |
722 | -a -z \"$LINUX_MODULE_DIRECTORY\" ] | |
723 | then | |
724 | . /etc/environment | |
725 | export `cat /etc/environment | cut -d= -f1` | |
726 | fi | |
727 | ||
8d09bfe2 LC |
728 | # Arrange so that ~/.config/guix/current comes first. |
729 | for profile in \"$HOME/.guix-profile\" \"$HOME/.config/guix/current\" | |
cdc5b932 LC |
730 | do |
731 | if [ -f \"$profile/etc/profile\" ] | |
732 | then | |
733 | # Load the user profile's settings. | |
734 | GUIX_PROFILE=\"$profile\" ; \\ | |
735 | . \"$profile/etc/profile\" | |
736 | else | |
737 | # At least define this one so that basic things just work | |
738 | # when the user installs their first package. | |
739 | export PATH=\"$profile/bin:$PATH\" | |
740 | fi | |
741 | done | |
d9959421 | 742 | |
a854525a LC |
743 | # Prepend setuid programs. |
744 | export PATH=/run/setuid-programs:$PATH | |
745 | ||
8d09bfe2 LC |
746 | # Arrange so that ~/.config/guix/current/share/info comes first. |
747 | export INFOPATH=\"$HOME/.config/guix/current/share/info:$INFOPATH\" | |
748 | ||
11202482 LC |
749 | # Set the umask, notably for users logging in via 'lsh'. |
750 | # See <http://bugs.gnu.org/22650>. | |
751 | umask 022 | |
2a5f0db4 | 752 | |
c08da2ee LC |
753 | # Allow Hunspell-based applications (IceCat, LibreOffice, etc.) to |
754 | # find dictionaries. | |
755 | export DICPATH=\"$HOME/.guix-profile/share/hunspell:/run/current-system/profile/share/hunspell\" | |
756 | ||
4af7c83b LC |
757 | # Allow GStreamer-based applications to find plugins. |
758 | export GST_PLUGIN_PATH=\"$HOME/.guix-profile/lib/gstreamer-1.0\" | |
759 | ||
1d167b6e LC |
760 | if [ -n \"$BASH_VERSION\" -a -f /etc/bashrc ] |
761 | then | |
762 | # Load Bash-specific initialization code. | |
669786da | 763 | . /etc/bashrc |
1d167b6e | 764 | fi |
40281c54 | 765 | ")) |
1d167b6e | 766 | |
0adfe95a | 767 | (bashrc (plain-file "bashrc" "\ |
1d167b6e LC |
768 | # Bash-specific initialization. |
769 | ||
770 | # The 'bash-completion' package. | |
771 | if [ -f /run/current-system/profile/etc/profile.d/bash_completion.sh ] | |
772 | then | |
773 | # Bash-completion sources ~/.bash_completion. It installs a dynamic | |
774 | # completion loader that searches its own completion files as well | |
775 | # as those in ~/.guix-profile and /run/current-system/profile. | |
776 | source /run/current-system/profile/etc/profile.d/bash_completion.sh | |
0adfe95a LC |
777 | fi\n"))) |
778 | (etc-service | |
9e41130b LC |
779 | `(("services" ,(file-append net-base "/etc/services")) |
780 | ("protocols" ,(file-append net-base "/etc/protocols")) | |
781 | ("rpc" ,(file-append net-base "/etc/rpc")) | |
0adfe95a LC |
782 | ("login.defs" ,#~#$login.defs) |
783 | ("issue" ,#~#$issue) | |
784 | ("nsswitch.conf" ,#~#$nsswitch) | |
0adfe95a LC |
785 | ("profile" ,#~#$profile) |
786 | ("bashrc" ,#~#$bashrc) | |
787 | ("hosts" ,#~#$(or (operating-system-hosts-file os) | |
788 | (default-/etc/hosts (operating-system-host-name os)))) | |
c694520b TD |
789 | ;; Write the operating-system-host-name to /etc/hostname to prevent |
790 | ;; NetworkManager from changing the system's hostname when connecting | |
791 | ;; to certain networks. Some discussion at | |
792 | ;; https://lists.gnu.org/archive/html/help-guix/2017-09/msg00037.html | |
793 | ("hostname" ,(plain-file "hostname" (operating-system-host-name os))) | |
2a80d9e5 TS |
794 | ;; Some programs (e.g., GLib) look at /etc/timezone to find the |
795 | ;; name of the current timezone. For details, see | |
796 | ;; https://lists.gnu.org/archive/html/guix-devel/2019-07/msg00166.html | |
797 | ("timezone" ,(plain-file "timezone" (operating-system-timezone os))) | |
9e41130b LC |
798 | ("localtime" ,(file-append tzdata "/share/zoneinfo/" |
799 | (operating-system-timezone os))) | |
0adfe95a | 800 | ("sudoers" ,(operating-system-sudoers-file os)))))) |
033adfe7 | 801 | |
ab6a279a LC |
802 | (define %root-account |
803 | ;; Default root account. | |
804 | (user-account | |
805 | (name "root") | |
806 | (password "") | |
807 | (uid 0) (group "root") | |
808 | (comment "System administrator") | |
809 | (home-directory "/root"))) | |
810 | ||
0b6f49ef | 811 | (define (operating-system-accounts os) |
0adfe95a LC |
812 | "Return the user accounts for OS, including an obligatory 'root' account, |
813 | and excluding accounts requested by services." | |
814 | ;; Make sure there's a root account. | |
815 | (if (find (lambda (user) | |
816 | (and=> (user-account-uid user) zero?)) | |
817 | (operating-system-users os)) | |
818 | (operating-system-users os) | |
819 | (cons %root-account (operating-system-users os)))) | |
0b6f49ef | 820 | |
84765839 LC |
821 | (define (maybe-string->file file-name thing) |
822 | "If THING is a string, return a <plain-file> with THING as its content. | |
823 | Otherwise just return THING. | |
824 | ||
825 | This is for backward-compatibility of fields that used to be strings and are | |
826 | now file-like objects.." | |
827 | (match thing | |
828 | ((? string?) | |
69daee23 | 829 | (warning (G_ "using a string for file '~a' is deprecated; \ |
84765839 LC |
830 | use 'plain-file' instead~%") |
831 | file-name) | |
832 | (plain-file file-name thing)) | |
833 | (x | |
834 | x))) | |
835 | ||
24e02c28 LC |
836 | (define (maybe-file->monadic file-name thing) |
837 | "If THING is a value in %STORE-MONAD, return it as is; otherwise return | |
838 | THING in the %STORE-MONAD. | |
839 | ||
840 | This is for backward-compatibility of fields that used to be monadic values | |
841 | and are now file-like objects." | |
842 | (with-monad %store-monad | |
843 | (match thing | |
844 | ((? procedure?) | |
69daee23 | 845 | (warning (G_ "using a monadic value for '~a' is deprecated; \ |
24e02c28 LC |
846 | use 'plain-file' instead~%") |
847 | file-name) | |
848 | thing) | |
849 | (x | |
850 | (return x))))) | |
851 | ||
0b6f49ef LC |
852 | (define (operating-system-etc-directory os) |
853 | "Return that static part of the /etc directory of OS." | |
0adfe95a LC |
854 | (etc-directory |
855 | (fold-services (operating-system-services os) | |
856 | #:target-type etc-service-type))) | |
033adfe7 | 857 | |
6bad7524 SB |
858 | (define (operating-system-environment-variables os) |
859 | "Return the environment variables of OS for | |
860 | @var{session-environment-service-type}, to be used in @file{/etc/environment}." | |
861 | `(("LANG" . ,(operating-system-locale os)) | |
54757499 LC |
862 | ;; Note: No need to set 'TZ' since (1) we provide /etc/localtime, and (2) |
863 | ;; it doesn't work for setuid binaries. See <https://bugs.gnu.org/29212>. | |
9e41130b | 864 | ("TZDIR" . ,(file-append tzdata "/share/zoneinfo")) |
6bad7524 SB |
865 | ;; Tell 'modprobe' & co. where to look for modules. |
866 | ("LINUX_MODULE_DIRECTORY" . "/run/booted-system/kernel/lib/modules") | |
867 | ;; These variables are honored by OpenSSL (libssl) and Git. | |
868 | ("SSL_CERT_DIR" . "/etc/ssl/certs") | |
869 | ("SSL_CERT_FILE" . "/etc/ssl/certs/ca-certificates.crt") | |
870 | ("GIT_SSL_CAINFO" . "/etc/ssl/certs/ca-certificates.crt") | |
ae05e366 LC |
871 | |
872 | ;; 'GTK_DATA_PREFIX' must name one directory where GTK+ themes are | |
873 | ;; searched for. | |
874 | ("GTK_DATA_PREFIX" . "/run/current-system/profile") | |
875 | ||
6bad7524 SB |
876 | ;; By default, applications that use D-Bus, such as Emacs, abort at startup |
877 | ;; when /etc/machine-id is missing. Make sure these warnings are non-fatal. | |
946465bb LC |
878 | ("DBUS_FATAL_WARNINGS" . "0") |
879 | ||
880 | ;; XXX: Normally we wouldn't need to do this, but our glibc@2.23 package | |
881 | ;; used to look things up in 'PREFIX/lib/locale' instead of | |
882 | ;; '/run/current-system/locale' as was intended. Keep this hack around so | |
883 | ;; that people who still have glibc@2.23-using packages in their profiles | |
884 | ;; can use them correctly. | |
885 | ;; TODO: Remove when glibc@2.23 is long gone. | |
886 | ("GUIX_LOCPATH" . "/run/current-system/locale"))) | |
6bad7524 | 887 | |
09e028f4 LC |
888 | (define %setuid-programs |
889 | ;; Default set of setuid-root programs. | |
3b65abac | 890 | (let ((shadow (@ (gnu packages admin) shadow))) |
9e41130b LC |
891 | (list (file-append shadow "/bin/passwd") |
892 | (file-append shadow "/bin/su") | |
852241eb SB |
893 | (file-append shadow "/bin/newuidmap") |
894 | (file-append shadow "/bin/newgidmap") | |
9e41130b LC |
895 | (file-append inetutils "/bin/ping") |
896 | (file-append inetutils "/bin/ping6") | |
897 | (file-append sudo "/bin/sudo") | |
5144df2c | 898 | (file-append sudo "/bin/sudoedit") |
19944227 LC |
899 | (file-append fuse "/bin/fusermount") |
900 | ||
901 | ;; To allow mounts with the "user" option, "mount" and "umount" must | |
902 | ;; be setuid-root. | |
903 | (file-append util-linux "/bin/mount") | |
904 | (file-append util-linux "/bin/umount")))) | |
69689380 LC |
905 | |
906 | (define %sudoers-specification | |
907 | ;; Default /etc/sudoers contents: 'root' and all members of the 'wheel' | |
908 | ;; group can do anything. See | |
909 | ;; <http://www.sudo.ws/sudo/man/1.8.10/sudoers.man.html>. | |
910 | ;; TODO: Add a declarative API. | |
84765839 LC |
911 | (plain-file "sudoers" "\ |
912 | root ALL=(ALL) ALL | |
913 | %wheel ALL=(ALL) ALL\n")) | |
09e028f4 | 914 | |
69cae3d3 | 915 | (define* (operating-system-activation-script os) |
484a2b3a LC |
916 | "Return the activation script for OS---i.e., the code that \"activates\" the |
917 | stateful part of OS, including user accounts and groups, special directories, | |
918 | etc." | |
69cae3d3 | 919 | (let* ((services (operating-system-services os)) |
0adfe95a LC |
920 | (activation (fold-services services |
921 | #:target-type activation-service-type))) | |
922 | (activation-service->script activation))) | |
484a2b3a | 923 | |
69cae3d3 | 924 | (define* (operating-system-boot-script os) |
484a2b3a | 925 | "Return the boot script for OS---i.e., the code started by the initrd once |
69cae3d3 LC |
926 | we're running in the final root." |
927 | (let* ((services (operating-system-services os)) | |
d62e201c | 928 | (boot (fold-services services #:target-type boot-service-type))) |
efe7d19a | 929 | (service-value boot))) |
2106d3fc | 930 | |
b2fef041 LC |
931 | (define (operating-system-user-accounts os) |
932 | "Return the list of user accounts of OS." | |
933 | (let* ((services (operating-system-services os)) | |
934 | (account (fold-services services | |
935 | #:target-type account-service-type))) | |
936 | (filter user-account? | |
efe7d19a | 937 | (service-value account)))) |
b2fef041 LC |
938 | |
939 | (define (operating-system-shepherd-service-names os) | |
940 | "Return the list of Shepherd service names for OS." | |
941 | (append-map shepherd-service-provision | |
efe7d19a | 942 | (service-value |
b2fef041 LC |
943 | (fold-services (operating-system-services os) |
944 | #:target-type | |
945 | shepherd-root-service-type)))) | |
946 | ||
69cae3d3 | 947 | (define* (operating-system-derivation os) |
d62e201c | 948 | "Return a derivation that builds OS." |
69cae3d3 | 949 | (let* ((services (operating-system-services os)) |
d62e201c LC |
950 | (system (fold-services services))) |
951 | ;; SYSTEM contains the derivation as a monadic value. | |
efe7d19a | 952 | (service-value system))) |
d62e201c | 953 | |
69cae3d3 | 954 | (define* (operating-system-profile os) |
af4c3fd5 LC |
955 | "Return a derivation that builds the system profile of OS." |
956 | (mlet* %store-monad | |
69cae3d3 | 957 | ((services -> (operating-system-services os)) |
af4c3fd5 LC |
958 | (profile (fold-services services |
959 | #:target-type profile-service-type))) | |
960 | (match profile | |
961 | (("profile" profile) | |
962 | (return profile))))) | |
963 | ||
83bcd0b8 LC |
964 | (define (operating-system-root-file-system os) |
965 | "Return the root file system of OS." | |
a48d3450 LC |
966 | (find (lambda (fs) |
967 | (string=? "/" (file-system-mount-point fs))) | |
83bcd0b8 LC |
968 | (operating-system-file-systems os))) |
969 | ||
b4140694 LC |
970 | (define (operating-system-initrd-file os) |
971 | "Return a gexp denoting the initrd file of OS." | |
83bcd0b8 | 972 | (define boot-file-systems |
4d6b879c | 973 | (filter file-system-needed-for-boot? |
83bcd0b8 LC |
974 | (operating-system-file-systems os))) |
975 | ||
de1c158f LC |
976 | (define mapped-devices |
977 | (operating-system-boot-mapped-devices os)) | |
978 | ||
979 | (define make-initrd | |
980 | (operating-system-initrd os)) | |
981 | ||
d422cbb3 LC |
982 | (make-initrd boot-file-systems |
983 | #:linux (operating-system-kernel os) | |
984 | #:linux-modules | |
985 | (operating-system-initrd-modules os) | |
ae7a316b LC |
986 | #:mapped-devices mapped-devices |
987 | #:keyboard-layout (operating-system-keyboard-layout os))) | |
b4140694 | 988 | |
78fbf2bd MO |
989 | (define* (operating-system-uuid os #:optional (type 'dce)) |
990 | "Compute UUID object with a deterministic \"UUID\" for OS, of the given | |
991 | TYPE (one of 'iso9660 or 'dce). Return a UUID object." | |
992 | ;; Note: For this to be deterministic, we must not hash things that contains | |
993 | ;; (directly or indirectly) procedures, for example. That rules out | |
994 | ;; anything that contains gexps, thunk or delayed record fields, etc. | |
995 | ||
996 | (define service-name | |
997 | (compose service-type-name service-kind)) | |
998 | ||
999 | (define (file-system-digest fs) | |
1000 | ;; Return a hashable digest that does not contain 'dependencies' since | |
1001 | ;; this field can contain procedures. | |
1002 | (let ((device (file-system-device fs))) | |
1003 | (list (file-system-mount-point fs) | |
1004 | (file-system-type fs) | |
1005 | (file-system-device->string device) | |
1006 | (file-system-options fs)))) | |
1007 | ||
1008 | (if (eq? type 'iso9660) | |
1009 | (let ((pad (compose (cut string-pad <> 2 #\0) | |
1010 | number->string)) | |
1011 | (h (hash (map service-name (operating-system-services os)) | |
1012 | 3600))) | |
1013 | (bytevector->uuid | |
1014 | (string->iso9660-uuid | |
1015 | (string-append "1970-01-01-" | |
1016 | (pad (hash (operating-system-host-name os) 24)) "-" | |
1017 | (pad (quotient h 60)) "-" | |
1018 | (pad (modulo h 60)) "-" | |
1019 | (pad (hash (map file-system-digest | |
1020 | (operating-system-file-systems os)) | |
1021 | 100)))) | |
1022 | 'iso9660)) | |
1023 | (bytevector->uuid | |
1024 | (uint-list->bytevector | |
1025 | (list (hash (map file-system-digest | |
1026 | (operating-system-file-systems os)) | |
1027 | (- (expt 2 32) 1)) | |
1028 | (hash (operating-system-host-name os) | |
1029 | (- (expt 2 32) 1)) | |
1030 | (hash (map service-name (operating-system-services os)) | |
1031 | (- (expt 2 32) 1)) | |
1032 | (hash (map file-system-digest (operating-system-file-systems os)) | |
1033 | (- (expt 2 32) 1))) | |
1034 | (endianness little) | |
1035 | 4) | |
1036 | type))) | |
1037 | ||
f5582b2c LC |
1038 | (define (locale-name->definition* name) |
1039 | "Variant of 'locale-name->definition' that raises an error upon failure." | |
1040 | (match (locale-name->definition name) | |
1041 | (#f | |
1042 | (raise (condition | |
1043 | (&message | |
69daee23 | 1044 | (message (format #f (G_ "~a: invalid locale name") name)))))) |
f5582b2c LC |
1045 | (def def))) |
1046 | ||
598e19dc LC |
1047 | (define (operating-system-locale-directory os) |
1048 | "Return the directory containing the locales compiled for the definitions | |
1049 | listed in OS. The C library expects to find it under | |
1050 | /run/current-system/locale." | |
f5582b2c LC |
1051 | (define name |
1052 | (operating-system-locale os)) | |
1053 | ||
1054 | (define definitions | |
1055 | ;; While we're at it, check whether NAME is defined and add it if needed. | |
1056 | (if (member name (map locale-definition-name | |
1057 | (operating-system-locale-definitions os))) | |
1058 | (operating-system-locale-definitions os) | |
1059 | (cons (locale-name->definition* name) | |
1060 | (operating-system-locale-definitions os)))) | |
1061 | ||
1062 | (locale-directory definitions | |
34760ae7 | 1063 | #:libcs (operating-system-locale-libcs os))) |
598e19dc | 1064 | |
c2e9942b MO |
1065 | (define (kernel->boot-label kernel) |
1066 | "Return a label for the bootloader menu entry that boots KERNEL." | |
bdc61ff9 P |
1067 | (cond ((package? kernel) |
1068 | (string-append "GNU with " | |
1069 | (string-titlecase (package-name kernel)) " " | |
4ce3a326 | 1070 | (package-version kernel))) |
bdc61ff9 P |
1071 | ((inferior-package? kernel) |
1072 | (string-append "GNU with " | |
b12f8720 | 1073 | (string-titlecase (inferior-package-name kernel)) " " |
4ce3a326 | 1074 | (inferior-package-version kernel))) |
bdc61ff9 | 1075 | (else "GNU"))) |
2d23e6f0 | 1076 | |
3f03a198 LC |
1077 | (define (operating-system-default-label os) |
1078 | "Return the default label for OS, as it will appear in the bootloader menu | |
1079 | entry." | |
1080 | (kernel->boot-label (operating-system-kernel os))) | |
1081 | ||
6b779207 LC |
1082 | (define (store-file-system file-systems) |
1083 | "Return the file system object among FILE-SYSTEMS that contains the store." | |
1084 | (match (filter (lambda (fs) | |
1085 | (and (file-system-mount? fs) | |
1086 | (not (memq 'bind-mount (file-system-flags fs))) | |
1087 | (string-prefix? (file-system-mount-point fs) | |
1088 | (%store-prefix)))) | |
1089 | file-systems) | |
1090 | ((and candidates (head . tail)) | |
1091 | (reduce (lambda (fs1 fs2) | |
1092 | (if (> (string-length (file-system-mount-point fs1)) | |
1093 | (string-length (file-system-mount-point fs2))) | |
1094 | fs1 | |
1095 | fs2)) | |
1096 | head | |
1097 | candidates)))) | |
1098 | ||
1099 | (define (operating-system-store-file-system os) | |
1100 | "Return the file system that contains the store of OS." | |
1101 | (store-file-system (operating-system-file-systems os))) | |
1102 | ||
c76b3046 | 1103 | (define* (operating-system-bootcfg os #:optional (old-entries '())) |
5ece56dc LC |
1104 | "Return the bootloader configuration file for OS. Use OLD-ENTRIES, |
1105 | a list of <menu-entry>, to populate the \"old entries\" menu." | |
b460ba79 MC |
1106 | (let* ((file-systems (operating-system-file-systems os)) |
1107 | (root-fs (operating-system-root-file-system os)) | |
9782c822 LC |
1108 | (root-device (file-system-device root-fs)) |
1109 | (params (operating-system-boot-parameters | |
1110 | os root-device | |
1111 | #:system-kernel-arguments? #t)) | |
1112 | (entry (boot-parameters->menu-entry params)) | |
1113 | (bootloader-conf (operating-system-bootloader os))) | |
b460ba79 | 1114 | |
46c296dc LC |
1115 | (define generate-config-file |
1116 | (bootloader-configuration-file-generator | |
1117 | (bootloader-configuration-bootloader bootloader-conf))) | |
1118 | ||
9782c822 | 1119 | (generate-config-file bootloader-conf (list entry) |
b460ba79 MC |
1120 | #:old-entries old-entries |
1121 | #:btrfs-subvolume-file-name | |
1122 | (btrfs-store-subvolume-file-name file-systems)))) | |
b4140694 | 1123 | |
a7ef45d9 LC |
1124 | (define* (operating-system-boot-parameters os root-device |
1125 | #:key system-kernel-arguments?) | |
1126 | "Return a monadic <boot-parameters> record that describes the boot | |
1127 | parameters of OS. When SYSTEM-KERNEL-ARGUMENTS? is true, add kernel arguments | |
1128 | such as '--root' and '--load' to <boot-parameters>." | |
35b44681 LC |
1129 | (let* ((initrd (operating-system-initrd-file os)) |
1130 | (store (operating-system-store-file-system os)) | |
1131 | (bootloader (bootloader-configuration-bootloader | |
1132 | (operating-system-bootloader os))) | |
1133 | (bootloader-name (bootloader-name bootloader)) | |
3f03a198 | 1134 | (label (operating-system-label os))) |
35b44681 LC |
1135 | (boot-parameters |
1136 | (label label) | |
1137 | (root-device root-device) | |
1138 | (kernel (operating-system-kernel-file os)) | |
1139 | (kernel-arguments | |
1140 | (if system-kernel-arguments? | |
1141 | (operating-system-kernel-arguments os root-device) | |
1142 | (operating-system-user-kernel-arguments os))) | |
1143 | (initrd initrd) | |
1144 | (bootloader-name bootloader-name) | |
a28cfee8 LC |
1145 | (bootloader-menu-entries |
1146 | (bootloader-configuration-menu-entries (operating-system-bootloader os))) | |
35b44681 LC |
1147 | (store-device (ensure-not-/dev (file-system-device store))) |
1148 | (store-mount-point (file-system-mount-point store))))) | |
40fad1c2 | 1149 | |
9b336338 LC |
1150 | (define (device->sexp device) |
1151 | "Serialize DEVICE as an sexp (really, as an object with a read syntax.)" | |
1152 | (match device | |
1153 | ((? uuid? uuid) | |
075681d3 | 1154 | `(uuid ,(uuid-type uuid) ,(uuid-bytevector uuid))) |
a5acc17a LC |
1155 | ((? file-system-label? label) |
1156 | `(file-system-label ,(file-system-label->string label))) | |
9b336338 LC |
1157 | (_ |
1158 | device))) | |
1159 | ||
a7ef45d9 LC |
1160 | (define* (operating-system-boot-parameters-file os |
1161 | #:key system-kernel-arguments?) | |
40fad1c2 DM |
1162 | "Return a file that describes the boot parameters of OS. The primary use of |
1163 | this file is the reconstruction of GRUB menu entries for old configurations. | |
a7ef45d9 LC |
1164 | |
1165 | When SYSTEM-KERNEL-ARGUMENTS? is true, add kernel arguments such as '--root' | |
1166 | and '--load' to the returned file (since the returned file is then usually | |
1167 | stored into the content-addressed \"system\" directory, it's usually not a | |
1168 | good idea to give it because the content hash would change by the content hash | |
40fad1c2 | 1169 | being stored into the \"parameters\" file)." |
35b44681 LC |
1170 | (let* ((root (operating-system-root-file-system os)) |
1171 | (device (file-system-device root)) | |
1172 | (params (operating-system-boot-parameters | |
1173 | os device | |
1174 | #:system-kernel-arguments? | |
1175 | system-kernel-arguments?))) | |
2e37d158 LC |
1176 | (scheme-file "parameters" |
1177 | #~(boot-parameters | |
1178 | (version 0) | |
1179 | (label #$(boot-parameters-label params)) | |
1180 | (root-device | |
1181 | #$(device->sexp | |
1182 | (boot-parameters-root-device params))) | |
1183 | (kernel #$(boot-parameters-kernel params)) | |
1184 | (kernel-arguments | |
1185 | #$(boot-parameters-kernel-arguments params)) | |
1186 | (initrd #$(boot-parameters-initrd params)) | |
1187 | (bootloader-name #$(boot-parameters-bootloader-name params)) | |
1188 | (bootloader-menu-entries | |
1189 | #$(map menu-entry->sexp | |
1190 | (or (and=> (operating-system-bootloader os) | |
1191 | bootloader-configuration-menu-entries) | |
1192 | '()))) | |
1193 | (store | |
1194 | (device | |
1195 | #$(device->sexp (boot-parameters-store-device params))) | |
1196 | (mount-point #$(boot-parameters-store-mount-point | |
1197 | params)))) | |
1198 | #:set-load-path? #f))) | |
64e40dbb | 1199 | |
96da5d62 LC |
1200 | (define-gexp-compiler (operating-system-compiler (os <operating-system>) |
1201 | system target) | |
1202 | ((store-lift | |
1203 | (lambda (store) | |
1204 | ;; XXX: This is not super elegant but we can't pass SYSTEM and TARGET to | |
1205 | ;; 'operating-system-derivation'. | |
1206 | (run-with-store store (operating-system-derivation os) | |
1207 | #:system system | |
1208 | #:target target))))) | |
1209 | ||
033adfe7 | 1210 | ;;; system.scm ends here |