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