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