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