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