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