1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2015 Mark H Weaver <mhw@netris.org>
4 ;;; Copyright © 2016 Andreas Enge <andreas@enge.fr>
5 ;;; Copyright © 2017 Marius Bakke <mbakke@fastmail.com>
6 ;;; Copyright © 2017, 2019 Tobias Geerinckx-Rice <me@tobias.gr>
7 ;;; Copyright © 2020 Florian Pelz <pelzflorian@pelzflorian.de>
8 ;;; Copyright © 2020 Efraim Flashner <efraim@flashner.co.il>
10 ;;; This file is part of GNU Guix.
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.
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.
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/>.
25 (define-module (gnu system install)
27 #:use-module (gnu system)
28 #:use-module (gnu bootloader u-boot)
29 #:use-module (guix gexp)
30 #:use-module (guix store)
31 #:use-module (guix monads)
32 #:use-module (guix modules)
33 #:use-module ((guix packages) #:select (package-version))
34 #:use-module ((guix store) #:select (%store-prefix))
35 #:use-module (gnu installer)
36 #:use-module (gnu system locale)
37 #:use-module (gnu services avahi)
38 #:use-module (gnu services dbus)
39 #:use-module (gnu services networking)
40 #:use-module (gnu services shepherd)
41 #:use-module (gnu services ssh)
42 #:use-module (gnu packages admin)
43 #:use-module (gnu packages bash)
44 #:use-module (gnu packages bootloaders)
45 #:use-module (gnu packages certs)
46 #:use-module (gnu packages compression)
47 #:use-module (gnu packages fonts)
48 #:use-module (gnu packages fontutils)
49 #:use-module (gnu packages guile)
50 #:use-module (gnu packages linux)
51 #:use-module (gnu packages package-management)
52 #:use-module (gnu packages texinfo)
53 #:use-module (gnu packages xorg)
54 #:use-module (ice-9 match)
55 #:use-module (srfi srfi-26)
56 #:export (installation-os
57 a20-olinuxino-lime-installation-os
58 a20-olinuxino-lime2-emmc-installation-os
59 a20-olinuxino-micro-installation-os
60 bananapi-m2-ultra-installation-os
61 beaglebone-black-installation-os
62 mx6cuboxi-installation-os
63 nintendo-nes-classic-edition-installation-os
64 novena-installation-os
65 firefly-rk3399-installation-os
66 pine64-plus-installation-os
67 pinebook-installation-os
68 rock64-installation-os
69 rockpro64-installation-os
70 rk3399-puma-installation-os
71 wandboard-installation-os
76 ;;; This module provides an 'operating-system' definition for use on images
77 ;;; for USB sticks etc., for the installation of the GNU system.
83 ;;; Documentation service.
86 (define %installation-node-names
87 ;; Translated name of the "System Installation" node of the manual. Ideally
88 ;; we'd extract it from the 'guix-manual' gettext domain, but that one is
89 ;; usually not available at run time, hence this hack.
90 '(("de" . "Systeminstallation")
91 ("en" . "System Installation")
92 ("es" . "Instalación del sistema")
93 ("fr" . "Installation du système")
94 ("ru" . "Установка системы")))
96 (define (log-to-info tty user)
97 "Return a script that spawns the Info reader on the right section of the
99 (program-file "log-to-info"
100 #~(let* ((tty (open-file #$(string-append "/dev/" tty)
102 (locale (cadr (command-line)))
103 (language (string-take locale
104 (string-index locale #\_)))
105 (infodir "/run/current-system/profile/share/info")
106 (per-lang (string-append infodir "/guix." language
108 (file (if (file-exists? per-lang)
110 (string-append infodir "/guix.info")))
111 (node (or (assoc-ref '#$%installation-node-names
113 "System Installation")))
114 (redirect-port tty (current-output-port))
115 (redirect-port tty (current-error-port))
116 (redirect-port tty (current-input-port))
118 (let ((pw (getpwnam #$user)))
119 (setgid (passwd:gid pw))
120 (setuid (passwd:uid pw)))
122 ;; 'gunzip' is needed to decompress the doc.
123 (setenv "PATH" (string-append #$gzip "/bin"))
125 ;; Change this process' locale so that command-line
126 ;; arguments to 'info' are properly encoded.
129 (setlocale LC_ALL locale)
130 (setenv "LC_ALL" locale))
132 ;; Sometimes LOCALE itself is not available. In that
133 ;; case pick the one UTF-8 locale that's known to work
134 ;; instead of failing.
135 (setlocale LC_ALL "en_US.utf8")
136 (setenv "LC_ALL" "en_US.utf8")))
138 (execl #$(file-append info-reader "/bin/info")
139 "info" "-d" infodir "-f" file "-n" node))))
141 (define (documentation-shepherd-service tty)
142 (list (shepherd-service
143 (provision (list (symbol-append 'term- (string->symbol tty))))
144 (requirement '(user-processes host-name udev virtual-terminal))
145 (start #~(lambda* (#:optional (locale "en_US.utf8"))
147 (list #$(log-to-info tty "documentation") locale)
148 #:environment-variables
149 `("GUIX_LOCPATH=/run/current-system/locale"
151 (stop #~(make-kill-destructor)))))
153 (define %documentation-users
154 ;; User account for the Info viewer.
155 (list (user-account (name "documentation")
158 (home-directory "/var/empty"))))
160 (define documentation-service-type
161 ;; Documentation viewer service.
162 (service-type (name 'documentation)
164 (list (service-extension shepherd-root-service-type
165 documentation-shepherd-service)
166 (service-extension account-service-type
167 (const %documentation-users))))
168 (description "Run the Info reader on a tty.")))
171 (define %backing-directory
172 ;; Sub-directory used as the backing store for copy-on-write.
175 (define cow-store-service-type
176 (shepherd-service-type
179 (define (import-module? module)
180 ;; Since we don't use deduplication support in 'populate-store', don't
181 ;; import (guix store deduplication) and its dependencies, which
182 ;; includes Guile-Gcrypt.
183 (and (guix-module-name? module)
184 (not (equal? module '(guix store deduplication)))))
187 (requirement '(root-file-system user-processes))
188 (provision '(cow-store))
190 "Make the store copy-on-write, with writes going to \
193 ;; This is meant to be explicitly started by the user.
196 (modules `((gnu build install)
199 (with-imported-modules (source-module-closure
200 '((gnu build install))
201 #:select? import-module?)
204 (mount-cow-store target #$%backing-directory)
207 ;; Do nothing, and mark the service as stopped.
209 (stop #~(lambda (target)
210 ;; Delete the temporary directory, but leave everything
211 ;; mounted as there may still be processes using it since
212 ;; 'user-processes' doesn't depend on us. The 'user-file-systems'
213 ;; service will unmount TARGET eventually.
214 (delete-file-recursively
215 (string-append target #$%backing-directory))))))
216 (description "Make the store copy-on-write, with writes going to \
217 the given target.")))
219 (define (cow-store-service)
220 "Return a service that makes the store copy-on-write, such that writes go to
221 the user's target storage device rather than on the RAM disk."
222 ;; See <http://bugs.gnu.org/18061> for the initial report.
223 (service cow-store-service-type 'mooooh!))
226 (define (/etc/configuration-files _)
227 "Return a list of tuples representing configuration templates to add to
230 (computed-file "configuration-templates"
231 (with-imported-modules '((guix build utils))
234 (for-each (lambda (file target)
236 (string-append #$output "/"
238 '(#$(local-file "examples/bare-bones.tmpl")
239 #$(local-file "examples/beaglebone-black.tmpl")
240 #$(local-file "examples/desktop.tmpl")
241 #$(local-file "examples/lightweight-desktop.tmpl"))
243 "beaglebone-black.scm"
245 "lightweight-desktop.scm"))
248 `(("configuration" ,directory)))
250 (define configuration-template-service-type
251 (service-type (name 'configuration-template)
253 (list (service-extension etc-service-type
254 /etc/configuration-files)))))
256 (define %configuration-template-service
257 (service configuration-template-service-type #t))
260 (define %nscd-minimal-caches
261 ;; Minimal in-memory caching policy for nscd.
262 (list (nscd-cache (database 'hosts)
263 (positive-time-to-live (* 3600 12))
265 ;; Do not cache lookup failures at all since they are
266 ;; quite likely (for instance when someone tries to ping a
267 ;; host before networking is functional.)
268 (negative-time-to-live 0)
271 (max-database-size (* 5 (expt 2 20)))))) ;5 MiB
274 ;; These define a service to load the uvesafb kernel module with the
275 ;; appropriate options. The GUI installer needs it when the machine does not
276 ;; support Kernel Mode Setting. Otherwise kmscon is missing /dev/fb0.
277 (define (uvesafb-shepherd-service _)
278 (list (shepherd-service
279 (documentation "Load the uvesafb kernel module if needed.")
280 (provision '(maybe-uvesafb))
281 (requirement '(file-systems))
283 ;; uvesafb is only supported on x86 and x86_64.
284 (or (not (and (string-suffix? "linux-gnu" %host-type)
285 (or (string-prefix? "x86_64" %host-type)
286 (string-prefix? "i686" %host-type))))
287 (file-exists? "/dev/fb0")
288 (invoke #+(file-append kmod "/bin/modprobe")
290 (string-append "v86d=" #$v86d "/sbin/v86d")
291 "mode_option=1024x768"))))
295 (define uvesafb-service-type
299 (list (service-extension shepherd-root-service-type
300 uvesafb-shepherd-service)))
302 "Load the @code{uvesafb} kernel module with the right options.")
305 (define %installation-services
306 ;; List of services of the installation system.
307 (let ((motd (plain-file "motd" "
308 \x1b[1;37mWelcome to the installation of GNU Guix!\x1b[0m
311 Using this shell, you can carry out the installation process \"manually.\"
312 Access documentation at any time by pressing Alt-F2.\x1b[0m
314 (define (normal-tty tty)
315 (mingetty-service (mingetty-configuration (tty tty)
319 (define bare-bones-os
320 (load "examples/bare-bones.tmpl"))
322 (list (service virtual-terminal-service-type)
324 (service kmscon-service-type
325 (kmscon-configuration
326 (virtual-terminal "tty1")
327 (login-program (installer-program))))
329 (login-service (login-configuration
332 ;; Documentation. The manual is in UTF-8, but
333 ;; 'console-font-service' sets up Unicode support and loads a font
334 ;; with all the useful glyphs like em dash and quotation marks.
335 (service documentation-service-type "tty2")
337 ;; Documentation add-on.
338 %configuration-template-service
340 ;; A bunch of 'root' ttys.
346 ;; The usual services.
349 ;; Use the Avahi daemon to discover substitute servers on the local
350 ;; network. It can be faster than fetching from remote servers.
351 (service avahi-service-type)
353 ;; The build daemon. Register the default substitute server key(s)
354 ;; as trusted to allow the installation process to use substitutes by
356 (service guix-service-type
357 (guix-configuration (authorize-key? #t)))
359 ;; Start udev so that useful device nodes are available.
360 ;; Use device-mapper rules for cryptsetup & co; enable the CRDA for
361 ;; regulations-compliant WiFi access.
362 (udev-service #:rules (list lvm2 crda))
364 ;; Add the 'cow-store' service, which users have to start manually
365 ;; since it takes the installation directory as an argument.
368 ;; Install Unicode support and a suitable font.
369 (service console-font-service-type
372 ;; Use a font that contains characters such as
373 ;; curly quotes as found in the manual.
374 '("tty2" . "LatGrkCyr-8x16"))
376 ;; Use a font that doesn't have more than 256
377 ;; glyphs so that we can use colors with varying
378 ;; brightness levels (see note in setfont(8)).
379 `(,tty . "lat9u-16")))
380 '("tty1" "tty2" "tty3" "tty4" "tty5" "tty6")))
382 ;; To facilitate copy/paste.
383 (service gpm-service-type)
385 ;; Add an SSH server to facilitate remote installs.
386 (service openssh-service-type
387 (openssh-configuration
389 (permit-root-login #t)
390 ;; The root account is passwordless, so make sure
391 ;; a password is set before allowing logins.
392 (allow-empty-passwords? #f)
393 (password-authentication? #t)
395 ;; Don't start it upfront.
398 ;; Since this is running on a USB stick with a overlayfs as the root
399 ;; file system, use an appropriate cache configuration.
400 (nscd-service (nscd-configuration
401 (caches %nscd-minimal-caches)))
403 ;; Having /bin/sh is a good idea. In particular it allows Tramp
404 ;; connections to this system to work.
405 (service special-files-service-type
406 `(("/bin/sh" ,(file-append bash "/bin/sh"))))
408 ;; Loopback device, needed by OpenSSH notably.
409 (service static-networking-service-type
410 (list (static-networking (interface "lo")
413 (provision '(loopback)))))
415 (service wpa-supplicant-service-type)
417 (service connman-service-type
418 (connman-configuration
421 ;; Keep a reference to BARE-BONES-OS to make sure it can be
422 ;; installed without downloading/building anything. Also keep the
423 ;; things needed by 'profile-derivation' to minimize the amount of
425 (service gc-root-service-type
431 %default-locale-libcs))
433 ;; Machines without Kernel Mode Setting (those with many old and
434 ;; current AMD GPUs, SiS GPUs, ...) need uvesafb to show the GUI
435 ;; installer. Some may also need a kernel parameter like nomodeset
436 ;; or vga=793, but we leave that for the user to specify in GRUB.
437 (service uvesafb-service-type))))
442 \x1b[1;37mThis is an installation image of the GNU system. Welcome.\x1b[0m
444 \x1b[1;33mUse Alt-F2 for documentation.\x1b[0m
447 (define installation-os
448 ;; The operating system used on installation images for USB sticks etc.
451 (timezone "Europe/Paris")
452 (locale "en_US.utf8")
453 (name-service-switch %mdns-host-lookup-nss)
454 (bootloader (bootloader-configuration
455 (bootloader grub-bootloader)
456 (target "/dev/sda")))
457 (label (string-append "GNU Guix installation "
458 (package-version guix)))
460 ;; XXX: The AMD Radeon driver is reportedly broken, which makes kmscon
462 ;; <https://lists.gnu.org/archive/html/guix-devel/2019-03/msg00441.html>.
463 ;; Thus, blacklist it.
464 (kernel-arguments '("quiet" "modprobe.blacklist=radeon"))
467 ;; Note: the disk image build code overrides this root file system with
468 ;; the appropriate one.
471 (device (file-system-label "Guix_image"))
474 ;; Make /tmp a tmpfs instead of keeping the overlayfs. This
475 ;; originally was used for unionfs because FUSE creates
476 ;; '.fuse_hiddenXYZ' files for each open file, and this confuses
477 ;; Guix's test suite, for instance (see
478 ;; <http://bugs.gnu.org/23056>). We keep this for overlayfs to be
486 ;; XXX: This should be %BASE-FILE-SYSTEMS but we don't need
487 ;; elogind's cgroup file systems.
488 (list %pseudo-terminal-file-system
489 %shared-memory-file-system
493 (users (list (user-account
496 (supplementary-groups '("wheel")) ; allow use of sudo
498 (comment "Guest of GNU"))))
501 (services %installation-services)
503 ;; We don't need setuid programs, except for 'passwd', which can be handy
504 ;; if one is to allow remote SSH login to the machine being installed.
505 (setuid-programs (list (file-append shadow "/bin/passwd")))
508 ;; Explicitly allow for empty passwords.
509 (base-pam-services #:allow-empty-passwords? #t))
512 (list glibc ; for 'tzselect' & co.
514 font-dejavu font-gnu-unifont
515 grub ; mostly so xrefs to its manual work
516 nss-certs) ; To access HTTPS, use git, etc.
517 %base-packages-disk-utilities
520 (define* (os-with-u-boot os board #:key (bootloader-target "/dev/mmcblk0")
521 (triplet "arm-linux-gnueabihf"))
522 "Given OS, amend it with the u-boot bootloader for BOARD,
523 installed to BOOTLOADER-TARGET (a drive), compiled for TRIPLET.
525 If you want a serial console, make sure to specify one in your
526 operating-system's kernel-arguments (\"console=ttyS0\" or similar)."
527 (operating-system (inherit os)
528 (bootloader (bootloader-configuration
529 (bootloader (bootloader (inherit u-boot-bootloader)
530 (package (make-u-boot-package board triplet))))
531 (target bootloader-target)))))
533 (define* (embedded-installation-os bootloader bootloader-target tty
534 #:key (extra-modules '()))
535 "Return an installation os for embedded systems.
536 The initrd gets the extra modules EXTRA-MODULES.
537 A getty is provided on TTY.
538 The bootloader BOOTLOADER is installed to BOOTLOADER-TARGET."
540 (inherit installation-os)
541 (bootloader (bootloader-configuration
542 (bootloader bootloader)
543 (target bootloader-target)))
546 (cons (string-append "console=" tty)
547 (operating-system-user-kernel-arguments installation-os)))
548 (initrd-modules (append extra-modules %base-initrd-modules))))
550 (define beaglebone-black-installation-os
551 (embedded-installation-os u-boot-beaglebone-black-bootloader
555 ;; This module is required to mount the sd card.
559 (define a20-olinuxino-lime-installation-os
560 (embedded-installation-os u-boot-a20-olinuxino-lime-bootloader
561 "/dev/mmcblk0" ; SD card storage
564 (define a20-olinuxino-lime2-emmc-installation-os
565 (embedded-installation-os u-boot-a20-olinuxino-lime2-bootloader
566 "/dev/mmcblk1" ; eMMC storage
569 (define a20-olinuxino-micro-installation-os
570 (embedded-installation-os u-boot-a20-olinuxino-micro-bootloader
571 "/dev/mmcblk0" ; SD card storage
574 (define bananapi-m2-ultra-installation-os
575 (embedded-installation-os u-boot-bananapi-m2-ultra-bootloader
576 "/dev/mmcblk1" ; eMMC storage
579 (define firefly-rk3399-installation-os
580 (embedded-installation-os u-boot-firefly-rk3399-bootloader
581 "/dev/mmcblk0" ; SD card/eMMC (SD priority) storage
582 "ttyS2")) ; UART2 connected on the Pi2 bus
584 (define mx6cuboxi-installation-os
585 (embedded-installation-os u-boot-mx6cuboxi-bootloader
586 "/dev/mmcblk0" ; SD card storage
589 (define novena-installation-os
590 (embedded-installation-os u-boot-novena-bootloader
591 "/dev/mmcblk1" ; SD card storage
594 (define nintendo-nes-classic-edition-installation-os
595 (embedded-installation-os u-boot-nintendo-nes-classic-edition-bootloader
596 "/dev/mmcblk0" ; SD card (solder it yourself)
599 (define pine64-plus-installation-os
600 (embedded-installation-os u-boot-pine64-plus-bootloader
601 "/dev/mmcblk0" ; SD card storage
604 (define pinebook-installation-os
605 (embedded-installation-os u-boot-pinebook-bootloader
606 "/dev/mmcblk0" ; SD card storage
609 (define rock64-installation-os
610 (embedded-installation-os u-boot-rock64-rk3328-bootloader
611 "/dev/mmcblk0" ; SD card/eMMC (SD priority) storage
612 "ttyS2")) ; UART2 connected on the Pi2 bus
614 (define rockpro64-installation-os
615 (embedded-installation-os u-boot-rockpro64-rk3399-bootloader
616 "/dev/mmcblk0" ; SD card/eMMC (SD priority) storage
617 "ttyS2")) ; UART2 connected on the Pi2 bus
619 (define rk3399-puma-installation-os
620 (embedded-installation-os u-boot-puma-rk3399-bootloader
621 "/dev/mmcblk0" ; SD card storage
624 (define wandboard-installation-os
625 (embedded-installation-os u-boot-wandboard-bootloader
626 "/dev/mmcblk0" ; SD card storage
629 ;; Return the default os here so 'guix system' can consume it directly.
632 ;;; install.scm ends here