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