gnu: Add perl-opengl.
[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 (if (string-contains device ":/")
320 device ; nfs-root
321 ;; It used to be that we would not distinguish between labels and
322 ;; device names. Try to infer the right thing here.
323 (if (string-prefix? "/" device)
324 device
325 (file-system-label device))))))
326
327 (match (read port)
328 (('boot-parameters ('version 0)
329 ('label label) ('root-device root)
330 ('kernel kernel)
331 rest ...)
332 (boot-parameters
333 (label label)
334 (root-device (device-sexp->device root))
335
336 (bootloader-name
337 (match (assq 'bootloader-name rest)
338 ((_ args) args)
339 (#f 'grub))) ; for compatibility reasons.
340
341 (bootloader-menu-entries
342 (match (assq 'bootloader-menu-entries rest)
343 ((_ entries) (map sexp->menu-entry entries))
344 (#f '())))
345
346 ;; In the past, we would store the directory name of linux instead of
347 ;; the absolute file name of its image. Detect that and correct it.
348 (kernel (if (string=? kernel (direct-store-path kernel))
349 (string-append kernel "/"
350 (system-linux-image-file-name))
351 kernel))
352
353 (kernel-arguments
354 (match (assq 'kernel-arguments rest)
355 ((_ args) args)
356 (#f '()))) ;the old format
357
358 (initrd
359 (match (assq 'initrd rest)
360 (('initrd ('string-append directory file)) ;the old format
361 (string-append directory file))
362 (('initrd (? string? file))
363 file)
364 (#f #f)))
365
366 (multiboot-modules
367 (match (assq 'multiboot-modules rest)
368 ((_ args) args)
369 (#f '())))
370
371 (store-device
372 ;; Linux device names like "/dev/sda1" are not suitable GRUB device
373 ;; identifiers, so we just filter them out.
374 (ensure-not-/dev
375 (match (assq 'store rest)
376 (('store ('device #f) _ ...)
377 root-device)
378 (('store ('device device) _ ...)
379 (device-sexp->device device))
380 (_ ;the old format
381 root-device))))
382
383 (store-mount-point
384 (match (assq 'store rest)
385 (('store ('device _) ('mount-point mount-point) _ ...)
386 mount-point)
387 (_ ;the old format
388 "/")))))
389 (x ;unsupported format
390 (warning (G_ "unrecognized boot parameters at '~a'~%")
391 (port-filename port))
392 #f)))
393
394 (define (read-boot-parameters-file system)
395 "Read boot parameters from SYSTEM's (system or generation) \"parameters\"
396 file and returns the corresponding <boot-parameters> object or #f if the
397 format is unrecognized.
398 The object has its kernel-arguments extended in order to make it bootable."
399 (let* ((file (string-append system "/parameters"))
400 (params (call-with-input-file file read-boot-parameters))
401 (root (boot-parameters-root-device params)))
402 (boot-parameters
403 (inherit params)
404 (kernel-arguments (append (bootable-kernel-arguments system root)
405 (boot-parameters-kernel-arguments params))))))
406
407 (define (boot-parameters->menu-entry conf)
408 (let* ((kernel (boot-parameters-kernel conf))
409 (multiboot-modules (boot-parameters-multiboot-modules conf))
410 (multiboot? (pair? multiboot-modules)))
411 (menu-entry
412 (label (boot-parameters-label conf))
413 (device (boot-parameters-store-device conf))
414 (device-mount-point (boot-parameters-store-mount-point conf))
415 (linux (and (not multiboot?) kernel))
416 (linux-arguments (if (not multiboot?)
417 (boot-parameters-kernel-arguments conf)
418 '()))
419 (initrd (boot-parameters-initrd conf))
420 (multiboot-kernel (and multiboot? kernel))
421 (multiboot-arguments (if multiboot?
422 (boot-parameters-kernel-arguments conf)
423 '()))
424 (multiboot-modules (if multiboot?
425 (boot-parameters-multiboot-modules conf)
426 '())))))
427
428 \f
429 ;;;
430 ;;; Services.
431 ;;;
432
433 (define (non-boot-file-system-service os)
434 "Return the file system service for the file systems of OS that are not
435 marked as 'needed-for-boot'."
436 (define file-systems
437 (remove file-system-needed-for-boot?
438 (operating-system-file-systems os)))
439
440 (define mapped-devices-for-boot
441 (operating-system-boot-mapped-devices os))
442
443 (define (device-mappings fs)
444 (let ((device (file-system-device fs)))
445 (if (string? device) ;title is 'device
446 (filter (lambda (md)
447 (string=? (string-append "/dev/mapper/"
448 (mapped-device-target md))
449 device))
450 (operating-system-mapped-devices os))
451 '())))
452
453 (define (add-dependencies fs)
454 ;; Add the dependencies due to device mappings to FS.
455 (file-system
456 (inherit fs)
457 (dependencies
458 (delete-duplicates
459 (remove (cut member <> mapped-devices-for-boot)
460 (append (device-mappings fs)
461 (file-system-dependencies fs)))
462 eq?))))
463
464 (service file-system-service-type
465 (map add-dependencies file-systems)))
466
467 (define (mapped-device-users device file-systems)
468 "Return the subset of FILE-SYSTEMS that use DEVICE."
469 (let ((target (string-append "/dev/mapper/" (mapped-device-target device))))
470 (filter (lambda (fs)
471 (or (member device (file-system-dependencies fs))
472 (and (string? (file-system-device fs))
473 (string=? (file-system-device fs) target))))
474 file-systems)))
475
476 (define (operating-system-user-mapped-devices os)
477 "Return the subset of mapped devices that can be installed in
478 user-land--i.e., those not needed during boot."
479 (let ((devices (operating-system-mapped-devices os))
480 (file-systems (operating-system-file-systems os)))
481 (filter (lambda (md)
482 (let ((users (mapped-device-users md file-systems)))
483 (not (any file-system-needed-for-boot? users))))
484 devices)))
485
486 (define (operating-system-boot-mapped-devices os)
487 "Return the subset of mapped devices that must be installed during boot,
488 from the initrd."
489 (let ((devices (operating-system-mapped-devices os))
490 (file-systems (operating-system-file-systems os)))
491 (filter (lambda (md)
492 (let ((users (mapped-device-users md file-systems)))
493 (any file-system-needed-for-boot? users)))
494 devices)))
495
496 (define (device-mapping-services os)
497 "Return the list of device-mapping services for OS as a list."
498 (map device-mapping-service
499 (operating-system-user-mapped-devices os)))
500
501 (define (swap-services os)
502 "Return the list of swap services for OS."
503 (map swap-service (operating-system-swap-devices os)))
504
505 (define* (system-linux-image-file-name #:optional
506 (target (or (%current-target-system)
507 (%current-system))))
508 "Return the basename of the kernel image file for TARGET."
509 (cond
510 ((string-prefix? "arm" target) "zImage")
511 ((string-prefix? "mips" target) "vmlinuz")
512 ((string-prefix? "aarch64" target) "Image")
513 (else "bzImage")))
514
515 (define (operating-system-kernel-file os)
516 "Return an object representing the absolute file name of the kernel image of
517 OS."
518 (if (operating-system-hurd os)
519 (file-append (operating-system-kernel os) "/boot/gnumach")
520 (file-append (operating-system-kernel os)
521 "/" (system-linux-image-file-name))))
522
523 (define (package-for-kernel target-kernel module-package)
524 "Return a package like MODULE-PACKAGE, adapted for TARGET-KERNEL, if
525 possible (that is if there's a LINUX keyword argument in the build system)."
526 (package
527 (inherit module-package)
528 (arguments
529 (substitute-keyword-arguments (package-arguments module-package)
530 ((#:linux kernel #f)
531 target-kernel)))))
532
533 (define %default-modprobe-blacklist
534 ;; List of kernel modules to blacklist by default.
535 '("usbmouse" ;races with bcm5974, see <https://bugs.gnu.org/35574>
536 "usbkbd")) ;races with usbhid, see <https://issues.guix.gnu.org/35574#18>
537
538 (define %default-kernel-arguments
539 ;; Default arguments passed to the kernel.
540 (list (string-append "modprobe.blacklist="
541 (string-join %default-modprobe-blacklist ","))
542 "quiet"))
543
544 (define* (operating-system-directory-base-entries os)
545 "Return the basic entries of the 'system' directory of OS for use as the
546 value of the SYSTEM-SERVICE-TYPE service."
547 (let* ((locale (operating-system-locale-directory os))
548 (kernel (operating-system-kernel os))
549 (hurd (operating-system-hurd os))
550 (modules (operating-system-kernel-loadable-modules os))
551 (kernel (if hurd
552 kernel
553 (profile
554 (content (packages->manifest
555 (cons kernel
556 (map (lambda (module)
557 (if (package? module)
558 (package-for-kernel kernel
559 module)
560 module))
561 modules))))
562 (hooks (list linux-module-database)))))
563 (initrd (and (not hurd) (operating-system-initrd-file os)))
564 (params (operating-system-boot-parameters-file os)))
565 `(("kernel" ,kernel)
566 ,@(if hurd `(("hurd" ,hurd)) '())
567 ("parameters" ,params)
568 ,@(if initrd `(("initrd" ,initrd)) '())
569 ("locale" ,locale)))) ;used by libc
570
571 (define (operating-system-default-essential-services os)
572 "Return the list of essential services for OS. These are special services
573 that implement part of what's declared in OS are responsible for low-level
574 bookkeeping."
575 (define known-fs
576 (map file-system-mount-point (operating-system-file-systems os)))
577
578 (let* ((mappings (device-mapping-services os))
579 (root-fs (root-file-system-service))
580 (other-fs (non-boot-file-system-service os))
581 (swaps (swap-services os))
582 (procs (service user-processes-service-type))
583 (host-name (host-name-service (operating-system-host-name os)))
584 (entries (operating-system-directory-base-entries os)))
585 (cons* (service system-service-type entries)
586 %boot-service
587
588 ;; %SHEPHERD-ROOT-SERVICE must come last so that the gexp that
589 ;; execs shepherd comes last in the boot script (XXX). Likewise,
590 ;; the cleanup service must come first so that its gexp runs before
591 ;; activation code.
592 (service cleanup-service-type #f)
593 %activation-service
594 %shepherd-root-service
595
596 (pam-root-service (operating-system-pam-services os))
597 (account-service (append (operating-system-accounts os)
598 (operating-system-groups os))
599 (operating-system-skeletons os))
600 (operating-system-etc-service os)
601 (service fstab-service-type
602 (filter file-system-needed-for-boot?
603 (operating-system-file-systems os)))
604 (session-environment-service
605 (operating-system-environment-variables os))
606 host-name procs root-fs
607 (service setuid-program-service-type
608 (operating-system-setuid-programs os))
609 (service profile-service-type
610 (operating-system-packages os))
611 other-fs
612 (append mappings swaps
613
614 ;; Add the firmware service.
615 (list %linux-bare-metal-service
616 (service firmware-service-type
617 (operating-system-firmware os)))))))
618
619 (define (hurd-default-essential-services os)
620 (let ((entries (operating-system-directory-base-entries os)))
621 (list (service system-service-type entries)
622 %boot-service
623 %hurd-startup-service
624 %activation-service
625 %shepherd-root-service
626 (service user-processes-service-type)
627 (account-service (append (operating-system-accounts os)
628 (operating-system-groups os))
629 (operating-system-skeletons os))
630 (root-file-system-service)
631 (service file-system-service-type '())
632 (service fstab-service-type
633 (filter file-system-needed-for-boot?
634 (operating-system-file-systems os)))
635 (pam-root-service (operating-system-pam-services os))
636 (operating-system-etc-service os)
637 (service setuid-program-service-type
638 (operating-system-setuid-programs os))
639 (service profile-service-type (operating-system-packages os)))))
640
641 (define* (operating-system-services os)
642 "Return all the services of OS, including \"essential\" services."
643 (instantiate-missing-services
644 (append (operating-system-user-services os)
645 (operating-system-essential-services os))))
646
647 (define (operating-system-with-gc-roots os roots)
648 "Return a variant of OS where ROOTS are registered as GC roots."
649 (operating-system
650 (inherit os)
651
652 ;; We use this procedure for the installation OS, which already defines GC
653 ;; roots. Add ROOTS to those.
654 (services (cons (simple-service 'extra-root
655 gc-root-service-type roots)
656 (operating-system-user-services os)))))
657
658 (define (operating-system-configuration-file os)
659 "Return the configuration file of OS, based on its 'location' field, or #f
660 if it could not be determined."
661 (let ((file (and=> (operating-system-location os)
662 location-file)))
663 (and file
664 (or (and (string-prefix? "/" file) file)
665 (search-path %load-path file)))))
666
667 (define* (operating-system-with-provenance os
668 #:optional
669 (config-file
670 (operating-system-configuration-file
671 os)))
672 "Return a variant of OS that stores its own provenance information,
673 including CONFIG-FILE, if available. This is achieved by adding an instance
674 of PROVENANCE-SERVICE-TYPE to its services."
675 (operating-system
676 (inherit os)
677 (services (cons (service provenance-service-type config-file)
678 (operating-system-user-services os)))))
679
680 \f
681 ;;;
682 ;;; /etc.
683 ;;;
684
685 (define %base-firmware
686 ;; Firmware usable by default.
687 (list ath9k-htc-firmware
688 openfwwf-firmware))
689
690 (define %base-packages-utils
691 ;; Default set of utilities packages.
692 (cons* procps psmisc which
693 (@ (gnu packages admin) shadow) ;for 'passwd'
694
695 guile-3.0-latest
696
697 ;; The packages below are also in %FINAL-INPUTS, so take them from
698 ;; there to avoid duplication.
699 (list bash coreutils findutils grep sed
700 diffutils patch gawk tar gzip bzip2 xz lzip)))
701
702 (define %base-packages-linux
703 ;; Default set of linux specific packages.
704 (list pciutils usbutils
705 util-linux+udev
706 ;; Get 'insmod' & co. from kmod, not module-init-tools, since udev
707 ;; already depends on it anyway.
708 kmod eudev))
709
710 (define %base-packages-interactive
711 ;; Default set of common interactive packages.
712 (list less zile nano
713 man-db
714 info-reader ;the standalone Info reader (no Perl)
715 bash-completion
716 kbd
717 ;; The 'sudo' command is already in %SETUID-PROGRAMS, but we also
718 ;; want the other commands and the man pages (notably because
719 ;; auto-completion in Emacs shell relies on man pages.)
720 sudo
721 guile-readline guile-colorized))
722
723 (define %base-packages-networking
724 ;; Default set of networking packages.
725 (list inetutils isc-dhcp
726 iproute
727 ;; wireless-tools is deprecated in favor of iw, but it's still what
728 ;; many people are familiar with, so keep it around.
729 iw wireless-tools))
730
731 (define %base-packages
732 ;; Default set of packages globally visible. It should include anything
733 ;; required for basic administrator tasks.
734 (append (list e2fsprogs)
735 %base-packages-interactive
736 %base-packages-linux
737 %base-packages-networking
738 %base-packages-utils))
739
740 (define %default-issue
741 ;; Default contents for /etc/issue.
742 "
743 This is the GNU system. Welcome.\n")
744
745 (define (local-host-aliases host-name)
746 "Return aliases for HOST-NAME, to be used in /etc/hosts."
747 (string-append "127.0.0.1 localhost " host-name "\n"
748 "::1 localhost " host-name "\n"))
749
750 (define (default-/etc/hosts host-name)
751 "Return the default /etc/hosts file."
752 (plain-file "hosts" (local-host-aliases host-name)))
753
754 (define (validated-sudoers-file file)
755 "Return a copy of FILE, a sudoers file, after checking that it is
756 syntactically correct."
757 (computed-file "sudoers"
758 (with-imported-modules '((guix build utils))
759 #~(begin
760 (use-modules (guix build utils))
761
762 (invoke #+(file-append sudo "/sbin/visudo")
763 "--check" "--file" #$file)
764 (copy-file #$file #$output)))))
765
766 (define* (operating-system-etc-service os)
767 "Return a <service> that builds containing the static part of the /etc
768 directory."
769 (let* ((login.defs
770 (plain-file "login.defs"
771 (string-append
772 "# Default paths for non-login shells started by su(1).\n"
773 "ENV_PATH /run/setuid-programs:"
774 "/run/current-system/profile/bin:"
775 "/run/current-system/profile/sbin\n"
776 "ENV_SUPATH /run/setuid-programs:"
777 "/run/current-system/profile/bin:"
778 "/run/current-system/profile/sbin\n")))
779
780 (hurd (operating-system-hurd os))
781 (issue (plain-file "issue" (operating-system-issue os)))
782 (nsswitch (operating-system-name-service-switch os))
783 (nsswitch (and nsswitch
784 (plain-file "nsswitch.conf"
785 (name-service-switch->string nsswitch))))
786 (sudoers (operating-system-sudoers-file os))
787
788 ;; Startup file for POSIX-compliant login shells, which set system-wide
789 ;; environment variables.
790 (profile (mixed-text-file "profile" "\
791 # Crucial variables that could be missing in the profiles' 'etc/profile'
792 # because they would require combining both profiles.
793 # FIXME: See <http://bugs.gnu.org/20255>.
794 export MANPATH=$HOME/.guix-profile/share/man:/run/current-system/profile/share/man
795 export INFOPATH=$HOME/.guix-profile/share/info:/run/current-system/profile/share/info
796 export XDG_DATA_DIRS=$HOME/.guix-profile/share:/run/current-system/profile/share
797 export XDG_CONFIG_DIRS=$HOME/.guix-profile/etc/xdg:/run/current-system/profile/etc/xdg
798
799 # Make sure libXcursor finds cursors installed into user or system profiles. See <http://bugs.gnu.org/24445>
800 export XCURSOR_PATH=$HOME/.icons:$HOME/.guix-profile/share/icons:/run/current-system/profile/share/icons
801
802 # Ignore the default value of 'PATH'.
803 unset PATH
804
805 # Load the system profile's settings.
806 GUIX_PROFILE=/run/current-system/profile ; \\
807 . /run/current-system/profile/etc/profile
808
809 # Since 'lshd' does not use pam_env, /etc/environment must be explicitly
810 # loaded when someone logs in via SSH. See <http://bugs.gnu.org/22175>.
811 # We need 'PATH' to be defined here, for 'cat' and 'cut'. Do this before
812 # reading the user's 'etc/profile' to allow variables to be overridden.
813 if [ -f /etc/environment -a -n \"$SSH_CLIENT\" \\
814 -a -z \"$LINUX_MODULE_DIRECTORY\" ]
815 then
816 . /etc/environment
817 export `cat /etc/environment | cut -d= -f1`
818 fi
819
820 # Arrange so that ~/.config/guix/current comes first.
821 for profile in \"$HOME/.guix-profile\" \"$HOME/.config/guix/current\"
822 do
823 if [ -f \"$profile/etc/profile\" ]
824 then
825 # Load the user profile's settings.
826 GUIX_PROFILE=\"$profile\" ; \\
827 . \"$profile/etc/profile\"
828 else
829 # At least define this one so that basic things just work
830 # when the user installs their first package.
831 export PATH=\"$profile/bin:$PATH\"
832 fi
833 done
834
835 # Prepend setuid programs.
836 export PATH=/run/setuid-programs:$PATH
837
838 # Arrange so that ~/.config/guix/current/share/info comes first.
839 export INFOPATH=\"$HOME/.config/guix/current/share/info:$INFOPATH\"
840
841 # Set the umask, notably for users logging in via 'lsh'.
842 # See <http://bugs.gnu.org/22650>.
843 umask 022
844
845 # Allow Hunspell-based applications (IceCat, LibreOffice, etc.) to
846 # find dictionaries.
847 export DICPATH=\"$HOME/.guix-profile/share/hunspell:/run/current-system/profile/share/hunspell\"
848
849 # Allow GStreamer-based applications to find plugins.
850 export GST_PLUGIN_PATH=\"$HOME/.guix-profile/lib/gstreamer-1.0\"
851
852 if [ -n \"$BASH_VERSION\" -a -f /etc/bashrc ]
853 then
854 # Load Bash-specific initialization code.
855 . /etc/bashrc
856 fi
857 "))
858
859 (bashrc (plain-file "bashrc" "\
860 # Bash-specific initialization.
861
862 # The 'bash-completion' package.
863 if [ -f /run/current-system/profile/etc/profile.d/bash_completion.sh ]
864 then
865 # Bash-completion sources ~/.bash_completion. It installs a dynamic
866 # completion loader that searches its own completion files as well
867 # as those in ~/.guix-profile and /run/current-system/profile.
868 source /run/current-system/profile/etc/profile.d/bash_completion.sh
869 fi\n")))
870 (etc-service
871 `(("services" ,(file-append net-base "/etc/services"))
872 ("protocols" ,(file-append net-base "/etc/protocols"))
873 ("rpc" ,(file-append net-base "/etc/rpc"))
874 ("login.defs" ,#~#$login.defs)
875 ("issue" ,#~#$issue)
876 ,@(if nsswitch `(("nsswitch.conf" ,#~#$nsswitch)) '())
877 ("profile" ,#~#$profile)
878 ("bashrc" ,#~#$bashrc)
879 ("hosts" ,#~#$(or (operating-system-hosts-file os)
880 (default-/etc/hosts (operating-system-host-name os))))
881 ;; Write the operating-system-host-name to /etc/hostname to prevent
882 ;; NetworkManager from changing the system's hostname when connecting
883 ;; to certain networks. Some discussion at
884 ;; https://lists.gnu.org/archive/html/help-guix/2017-09/msg00037.html
885 ("hostname" ,(plain-file "hostname" (operating-system-host-name os)))
886 ;; Some programs (e.g., GLib) look at /etc/timezone to find the
887 ;; name of the current timezone. For details, see
888 ;; https://lists.gnu.org/archive/html/guix-devel/2019-07/msg00166.html
889 ("timezone" ,(plain-file "timezone" (operating-system-timezone os)))
890 ("localtime" ,(file-append tzdata "/share/zoneinfo/"
891 (operating-system-timezone os)))
892 ,@(if sudoers
893 `(("sudoers" ,(validated-sudoers-file sudoers)))
894 '())
895 ,@(if hurd
896 `(("login" ,(file-append hurd "/etc/login"))
897 ("motd" ,(file-append hurd "/etc/motd"))
898 ("ttys" ,(file-append hurd "/etc/ttys")))
899 '())))))
900
901 (define %root-account
902 ;; Default root account.
903 (user-account
904 (name "root")
905 (password "")
906 (uid 0) (group "root")
907 (comment "System administrator")
908 (home-directory "/root")))
909
910 (define (operating-system-accounts os)
911 "Return the user accounts for OS, including an obligatory 'root' account,
912 and excluding accounts requested by services."
913 ;; Make sure there's a root account.
914 (if (find (lambda (user)
915 (and=> (user-account-uid user) zero?))
916 (operating-system-users os))
917 (operating-system-users os)
918 (cons %root-account (operating-system-users os))))
919
920 (define (maybe-string->file file-name thing)
921 "If THING is a string, return a <plain-file> with THING as its content.
922 Otherwise just return THING.
923
924 This is for backward-compatibility of fields that used to be strings and are
925 now file-like objects.."
926 (match thing
927 ((? string?)
928 (warning (G_ "using a string for file '~a' is deprecated; \
929 use 'plain-file' instead~%")
930 file-name)
931 (plain-file file-name thing))
932 (x
933 x)))
934
935 (define (maybe-file->monadic file-name thing)
936 "If THING is a value in %STORE-MONAD, return it as is; otherwise return
937 THING in the %STORE-MONAD.
938
939 This is for backward-compatibility of fields that used to be monadic values
940 and are now file-like objects."
941 (with-monad %store-monad
942 (match thing
943 ((? procedure?)
944 (warning (G_ "using a monadic value for '~a' is deprecated; \
945 use 'plain-file' instead~%")
946 file-name)
947 thing)
948 (x
949 (return x)))))
950
951 (define (operating-system-etc-directory os)
952 "Return that static part of the /etc directory of OS."
953 (etc-directory
954 (fold-services (operating-system-services os)
955 #:target-type etc-service-type)))
956
957 (define (operating-system-environment-variables os)
958 "Return the environment variables of OS for
959 @var{session-environment-service-type}, to be used in @file{/etc/environment}."
960 `(("LANG" . ,(operating-system-locale os))
961 ;; Note: No need to set 'TZ' since (1) we provide /etc/localtime, and (2)
962 ;; it doesn't work for setuid binaries. See <https://bugs.gnu.org/29212>.
963 ("TZDIR" . ,(file-append tzdata "/share/zoneinfo"))
964 ;; Tell 'modprobe' & co. where to look for modules.
965 ("LINUX_MODULE_DIRECTORY" . "/run/booted-system/kernel/lib/modules")
966 ;; These variables are honored by OpenSSL (libssl) and Git.
967 ("SSL_CERT_DIR" . "/etc/ssl/certs")
968 ("SSL_CERT_FILE" . "/etc/ssl/certs/ca-certificates.crt")
969 ("GIT_SSL_CAINFO" . "/etc/ssl/certs/ca-certificates.crt")
970
971 ;; 'GTK_DATA_PREFIX' must name one directory where GTK+ themes are
972 ;; searched for.
973 ("GTK_DATA_PREFIX" . "/run/current-system/profile")
974
975 ;; By default, applications that use D-Bus, such as Emacs, abort at startup
976 ;; when /etc/machine-id is missing. Make sure these warnings are non-fatal.
977 ("DBUS_FATAL_WARNINGS" . "0")
978
979 ;; XXX: Normally we wouldn't need to do this, but our glibc@2.23 package
980 ;; used to look things up in 'PREFIX/lib/locale' instead of
981 ;; '/run/current-system/locale' as was intended. Keep this hack around so
982 ;; that people who still have glibc@2.23-using packages in their profiles
983 ;; can use them correctly.
984 ;; TODO: Remove when glibc@2.23 is long gone.
985 ("GUIX_LOCPATH" . "/run/current-system/locale")))
986
987 (define %setuid-programs
988 ;; Default set of setuid-root programs.
989 (let ((shadow (@ (gnu packages admin) shadow)))
990 (list (file-append shadow "/bin/passwd")
991 (file-append shadow "/bin/sg")
992 (file-append shadow "/bin/su")
993 (file-append shadow "/bin/newgrp")
994 (file-append shadow "/bin/newuidmap")
995 (file-append shadow "/bin/newgidmap")
996 (file-append inetutils "/bin/ping")
997 (file-append inetutils "/bin/ping6")
998 (file-append sudo "/bin/sudo")
999 (file-append sudo "/bin/sudoedit")
1000 (file-append fuse "/bin/fusermount")
1001
1002 ;; To allow mounts with the "user" option, "mount" and "umount" must
1003 ;; be setuid-root.
1004 (file-append util-linux "/bin/mount")
1005 (file-append util-linux "/bin/umount"))))
1006
1007 (define %sudoers-specification
1008 ;; Default /etc/sudoers contents: 'root' and all members of the 'wheel'
1009 ;; group can do anything. See
1010 ;; <http://www.sudo.ws/sudo/man/1.8.10/sudoers.man.html>.
1011 ;; TODO: Add a declarative API.
1012 (plain-file "sudoers" "\
1013 root ALL=(ALL) ALL
1014 %wheel ALL=(ALL) ALL\n"))
1015
1016 (define* (operating-system-activation-script os)
1017 "Return the activation script for OS---i.e., the code that \"activates\" the
1018 stateful part of OS, including user accounts and groups, special directories,
1019 etc."
1020 (let* ((services (operating-system-services os))
1021 (activation (fold-services services
1022 #:target-type activation-service-type)))
1023 (activation-service->script activation)))
1024
1025 (define* (operating-system-boot-script os)
1026 "Return the boot script for OS---i.e., the code started by the initrd once
1027 we're running in the final root."
1028 (let* ((services (operating-system-services os))
1029 (boot (fold-services services #:target-type boot-service-type)))
1030 (service-value boot)))
1031
1032 (define (operating-system-user-accounts os)
1033 "Return the list of user accounts of OS."
1034 (let* ((services (operating-system-services os))
1035 (account (fold-services services
1036 #:target-type account-service-type)))
1037 (filter user-account?
1038 (service-value account))))
1039
1040 (define (operating-system-shepherd-service-names os)
1041 "Return the list of Shepherd service names for OS."
1042 (append-map shepherd-service-provision
1043 (service-value
1044 (fold-services (operating-system-services os)
1045 #:target-type
1046 shepherd-root-service-type))))
1047
1048 (define* (operating-system-derivation os)
1049 "Return a derivation that builds OS."
1050 (let* ((services (operating-system-services os))
1051 (system (fold-services services)))
1052 ;; SYSTEM contains the derivation as a monadic value.
1053 (service-value system)))
1054
1055 (define* (operating-system-profile os)
1056 "Return a derivation that builds the system profile of OS."
1057 (mlet* %store-monad
1058 ((services -> (operating-system-services os))
1059 (profile (fold-services services
1060 #:target-type profile-service-type)))
1061 (match profile
1062 (("profile" profile)
1063 (return profile)))))
1064
1065 (define (operating-system-root-file-system os)
1066 "Return the root file system of OS."
1067 (or (find (lambda (fs)
1068 (string=? "/" (file-system-mount-point fs)))
1069 (operating-system-file-systems os))
1070 (raise (condition
1071 (&message (message "missing root file system"))
1072 (&error-location
1073 (location (operating-system-location os)))))))
1074
1075 (define (operating-system-initrd-file os)
1076 "Return a gexp denoting the initrd file of OS."
1077 (define boot-file-systems
1078 (filter file-system-needed-for-boot?
1079 (operating-system-file-systems os)))
1080
1081 (define mapped-devices
1082 (operating-system-boot-mapped-devices os))
1083
1084 (define make-initrd
1085 (operating-system-initrd os))
1086
1087 (make-initrd boot-file-systems
1088 #:linux (operating-system-kernel os)
1089 #:linux-modules
1090 (operating-system-initrd-modules os)
1091 #:mapped-devices mapped-devices
1092 #:keyboard-layout (operating-system-keyboard-layout os)))
1093
1094 (define* (operating-system-uuid os #:optional (type 'dce))
1095 "Compute UUID object with a deterministic \"UUID\" for OS, of the given
1096 TYPE (one of 'iso9660 or 'dce). Return a UUID object."
1097 ;; Note: For this to be deterministic, we must not hash things that contains
1098 ;; (directly or indirectly) procedures, for example. That rules out
1099 ;; anything that contains gexps, thunk or delayed record fields, etc.
1100
1101 (define service-name
1102 (compose service-type-name service-kind))
1103
1104 (define (file-system-digest fs)
1105 ;; Return a hashable digest that does not contain 'dependencies' since
1106 ;; this field can contain procedures.
1107 (let ((device (file-system-device fs)))
1108 (list (file-system-mount-point fs)
1109 (file-system-type fs)
1110 (file-system-device->string device)
1111 (file-system-options fs))))
1112
1113 (if (eq? type 'iso9660)
1114 (let ((pad (compose (cut string-pad <> 2 #\0)
1115 number->string))
1116 (h (hash (map service-name (operating-system-services os))
1117 3600)))
1118 (bytevector->uuid
1119 (string->iso9660-uuid
1120 (string-append "1970-01-01-"
1121 (pad (hash (operating-system-host-name os) 24)) "-"
1122 (pad (quotient h 60)) "-"
1123 (pad (modulo h 60)) "-"
1124 (pad (hash (map file-system-digest
1125 (operating-system-file-systems os))
1126 100))))
1127 'iso9660))
1128 (bytevector->uuid
1129 (uint-list->bytevector
1130 (list (hash (map file-system-digest
1131 (operating-system-file-systems os))
1132 (- (expt 2 32) 1))
1133 (hash (operating-system-host-name os)
1134 (- (expt 2 32) 1))
1135 (hash (map service-name (operating-system-services os))
1136 (- (expt 2 32) 1))
1137 (hash (map file-system-digest (operating-system-file-systems os))
1138 (- (expt 2 32) 1)))
1139 (endianness little)
1140 4)
1141 type)))
1142
1143 (define (locale-name->definition* name)
1144 "Variant of 'locale-name->definition' that raises an error upon failure."
1145 (match (locale-name->definition name)
1146 (#f
1147 (raise (formatted-message (G_ "~a: invalid locale name") name)))
1148 (def def)))
1149
1150 (define (operating-system-locale-directory os)
1151 "Return the directory containing the locales compiled for the definitions
1152 listed in OS. The C library expects to find it under
1153 /run/current-system/locale."
1154 (define name
1155 (operating-system-locale os))
1156
1157 (define definitions
1158 ;; While we're at it, check whether NAME is defined and add it if needed.
1159 (if (member name (map locale-definition-name
1160 (operating-system-locale-definitions os)))
1161 (operating-system-locale-definitions os)
1162 (cons (locale-name->definition* name)
1163 (operating-system-locale-definitions os))))
1164
1165 (locale-directory definitions
1166 #:libcs (operating-system-locale-libcs os)))
1167
1168 (define* (kernel->boot-label kernel #:key hurd)
1169 "Return a label for the bootloader menu entry that boots KERNEL."
1170 (cond ((package? hurd)
1171 (string-append "GNU with the "
1172 (string-titlecase (package-name hurd)) " "
1173 (package-version hurd)))
1174 ((package? kernel)
1175 (string-append "GNU with "
1176 (string-titlecase (package-name kernel)) " "
1177 (package-version kernel)))
1178 ((inferior-package? kernel)
1179 (string-append "GNU with "
1180 (string-titlecase (inferior-package-name kernel)) " "
1181 (inferior-package-version kernel)))
1182 (else "GNU")))
1183
1184 (define (operating-system-default-label os)
1185 "Return the default label for OS, as it will appear in the bootloader menu
1186 entry."
1187 (kernel->boot-label (operating-system-kernel os)
1188 #:hurd (operating-system-hurd os)))
1189
1190 (define (store-file-system file-systems)
1191 "Return the file system object among FILE-SYSTEMS that contains the store."
1192 (match (filter (lambda (fs)
1193 (and (file-system-mount? fs)
1194 (not (memq 'bind-mount (file-system-flags fs)))
1195 (string-prefix? (file-system-mount-point fs)
1196 (%store-prefix))))
1197 file-systems)
1198 ((and candidates (head . tail))
1199 (reduce (lambda (fs1 fs2)
1200 (if (> (string-length (file-system-mount-point fs1))
1201 (string-length (file-system-mount-point fs2)))
1202 fs1
1203 fs2))
1204 head
1205 candidates))))
1206
1207 (define (operating-system-store-file-system os)
1208 "Return the file system that contains the store of OS."
1209 (store-file-system (operating-system-file-systems os)))
1210
1211 (define* (operating-system-bootcfg os #:optional (old-entries '()))
1212 "Return the bootloader configuration file for OS. Use OLD-ENTRIES,
1213 a list of <menu-entry>, to populate the \"old entries\" menu."
1214 (let* ((file-systems (operating-system-file-systems os))
1215 (root-fs (operating-system-root-file-system os))
1216 (root-device (file-system-device root-fs))
1217 (params (operating-system-boot-parameters
1218 os root-device
1219 #:system-kernel-arguments? #t))
1220 (entry (boot-parameters->menu-entry params))
1221 (bootloader-conf (operating-system-bootloader os)))
1222
1223 (define generate-config-file
1224 (bootloader-configuration-file-generator
1225 (bootloader-configuration-bootloader bootloader-conf)))
1226
1227 (generate-config-file bootloader-conf (list entry)
1228 #:old-entries old-entries
1229 #:store-directory-prefix
1230 (btrfs-store-subvolume-file-name file-systems))))
1231
1232 (define (operating-system-multiboot-modules os)
1233 (if (operating-system-hurd os) (hurd-multiboot-modules os) '()))
1234
1235 (define (hurd-multiboot-modules os)
1236 (let* ((hurd (operating-system-hurd os))
1237 (root-file-system-command
1238 (list (file-append hurd "/hurd/ext2fs.static")
1239 "ext2fs"
1240 "--multiboot-command-line='${kernel-command-line}'"
1241 "--host-priv-port='${host-port}'"
1242 "--device-master-port='${device-port}'"
1243 "--exec-server-task='${exec-task}'"
1244 "--store-type=typed"
1245 "--x-xattr-translator-records"
1246 "'${root}'" "'$(task-create)'" "'$(task-resume)'"))
1247 (target (%current-target-system))
1248 (libc (if target
1249 (with-parameters ((%current-target-system #f))
1250 ;; TODO: cross-libc has extra patches for the Hurd;
1251 ;; remove in next rebuild cycle
1252 (cross-libc target))
1253 glibc))
1254 (exec-server-command
1255 (list (file-append libc "/lib/ld.so.1") "exec"
1256 (file-append hurd "/hurd/exec") "'$(exec-task=task-create)'")))
1257 (list root-file-system-command exec-server-command)))
1258
1259 (define* (operating-system-boot-parameters os root-device
1260 #:key system-kernel-arguments?)
1261 "Return a monadic <boot-parameters> record that describes the boot
1262 parameters of OS. When SYSTEM-KERNEL-ARGUMENTS? is true, add kernel arguments
1263 such as '--root' and '--load' to <boot-parameters>."
1264 (let* ((initrd (and (not (operating-system-hurd os))
1265 (operating-system-initrd-file os)))
1266 (store (operating-system-store-file-system os))
1267 (bootloader (bootloader-configuration-bootloader
1268 (operating-system-bootloader os)))
1269 (bootloader-name (bootloader-name bootloader))
1270 (label (operating-system-label os))
1271 (multiboot-modules (operating-system-multiboot-modules os)))
1272 (boot-parameters
1273 (label label)
1274 (root-device root-device)
1275 (kernel (operating-system-kernel-file os))
1276 (kernel-arguments
1277 (if system-kernel-arguments?
1278 (operating-system-kernel-arguments os root-device)
1279 (operating-system-user-kernel-arguments os)))
1280 (initrd initrd)
1281 (multiboot-modules multiboot-modules)
1282 (bootloader-name bootloader-name)
1283 (bootloader-menu-entries
1284 (bootloader-configuration-menu-entries (operating-system-bootloader os)))
1285 (store-device (ensure-not-/dev (file-system-device store)))
1286 (store-mount-point (file-system-mount-point store)))))
1287
1288 (define (device->sexp device)
1289 "Serialize DEVICE as an sexp (really, as an object with a read syntax.)"
1290 (match device
1291 ((? uuid? uuid)
1292 `(uuid ,(uuid-type uuid) ,(uuid-bytevector uuid)))
1293 ((? file-system-label? label)
1294 `(file-system-label ,(file-system-label->string label)))
1295 (_
1296 device)))
1297
1298 (define* (operating-system-boot-parameters-file os
1299 #:key system-kernel-arguments?)
1300 "Return a file that describes the boot parameters of OS. The primary use of
1301 this file is the reconstruction of GRUB menu entries for old configurations.
1302
1303 When SYSTEM-KERNEL-ARGUMENTS? is true, add kernel arguments such as '--root'
1304 and '--load' to the returned file (since the returned file is then usually
1305 stored into the content-addressed \"system\" directory, it's usually not a
1306 good idea to give it because the content hash would change by the content hash
1307 being stored into the \"parameters\" file)."
1308 (let* ((root (operating-system-root-file-system os))
1309 (device (file-system-device root))
1310 (params (operating-system-boot-parameters
1311 os device
1312 #:system-kernel-arguments?
1313 system-kernel-arguments?)))
1314 (scheme-file "parameters"
1315 #~(boot-parameters
1316 (version 0)
1317 (label #$(boot-parameters-label params))
1318 (root-device
1319 #$(device->sexp
1320 (boot-parameters-root-device params)))
1321 (kernel #$(boot-parameters-kernel params))
1322 (kernel-arguments
1323 #$(boot-parameters-kernel-arguments params))
1324 #$@(if (boot-parameters-initrd params)
1325 #~((initrd #$(boot-parameters-initrd params)))
1326 #~())
1327 #$@(if (pair? (boot-parameters-multiboot-modules params))
1328 #~((multiboot-modules
1329 #$(boot-parameters-multiboot-modules params)))
1330 #~())
1331 (bootloader-name #$(boot-parameters-bootloader-name params))
1332 (bootloader-menu-entries
1333 #$(map menu-entry->sexp
1334 (or (and=> (operating-system-bootloader os)
1335 bootloader-configuration-menu-entries)
1336 '())))
1337 (store
1338 (device
1339 #$(device->sexp (boot-parameters-store-device params)))
1340 (mount-point #$(boot-parameters-store-mount-point
1341 params))))
1342 #:set-load-path? #f)))
1343
1344 (define-gexp-compiler (operating-system-compiler (os <operating-system>)
1345 system target)
1346 ((store-lift
1347 (lambda (store)
1348 ;; XXX: This is not super elegant but we can't pass SYSTEM and TARGET to
1349 ;; 'operating-system-derivation'.
1350 (run-with-store store (operating-system-derivation os)
1351 #:system system
1352 #:target target)))))
1353
1354 ;;; system.scm ends here