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