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