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