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