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