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