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