1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014, 2015, 2016, 2017, 2018, 2019 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>
9 ;;; This file is part of GNU Guix.
11 ;;; GNU Guix is free software; you can redistribute it and/or modify it
12 ;;; under the terms of the GNU General Public License as published by
13 ;;; the Free Software Foundation; either version 3 of the License, or (at
14 ;;; your option) any later version.
16 ;;; GNU Guix is distributed in the hope that it will be useful, but
17 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;;; GNU General Public License for more details.
21 ;;; You should have received a copy of the GNU General Public License
22 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
24 (define-module (gnu system install)
26 #:use-module (gnu system)
27 #:use-module (gnu bootloader u-boot)
28 #:use-module (guix gexp)
29 #:use-module (guix store)
30 #:use-module (guix monads)
31 #:use-module (guix modules)
32 #:use-module ((guix packages) #:select (package-version))
33 #:use-module ((guix store) #:select (%store-prefix))
34 #:use-module (gnu installer)
35 #:use-module (gnu system locale)
36 #:use-module (gnu services dbus)
37 #:use-module (gnu services networking)
38 #:use-module (gnu services shepherd)
39 #:use-module (gnu services ssh)
40 #:use-module (gnu packages admin)
41 #:use-module (gnu packages bash)
42 #:use-module (gnu packages bootloaders)
43 #:use-module (gnu packages certs)
44 #:use-module (gnu packages file-systems)
45 #:use-module (gnu packages fonts)
46 #:use-module (gnu packages fontutils)
47 #:use-module (gnu packages guile)
48 #:use-module (gnu packages linux)
49 #:use-module (gnu packages ssh)
50 #:use-module (gnu packages cryptsetup)
51 #:use-module (gnu packages package-management)
52 #:use-module (gnu packages disk)
53 #:use-module (gnu packages texinfo)
54 #:use-module (gnu packages compression)
55 #:use-module (gnu packages nvi)
56 #:use-module (gnu packages xorg)
57 #:use-module (ice-9 match)
58 #:use-module (srfi srfi-26)
59 #:export (installation-os
60 a20-olinuxino-lime-installation-os
61 a20-olinuxino-lime2-emmc-installation-os
62 a20-olinuxino-micro-installation-os
63 bananapi-m2-ultra-installation-os
64 beaglebone-black-installation-os
65 mx6cuboxi-installation-os
66 nintendo-nes-classic-edition-installation-os
67 novena-installation-os
68 firefly-rk3399-installation-os
69 pine64-plus-installation-os
70 pinebook-installation-os
71 rock64-installation-os
72 rockpro64-installation-os
73 rk3399-puma-installation-os
74 wandboard-installation-os
79 ;;; This module provides an 'operating-system' definition for use on images
80 ;;; for USB sticks etc., for the installation of the GNU system.
86 ;;; Documentation service.
89 (define %installation-node-names
90 ;; Translated name of the "System Installation" node of the manual. Ideally
91 ;; we'd extract it from the 'guix-manual' gettext domain, but that one is
92 ;; usually not available at run time, hence this hack.
93 '(("de" . "Systeminstallation")
94 ("en" . "System Installation")
95 ("es" . "Instalación del sistema")
96 ("fr" . "Installation du système")
97 ("ru" . "Установка системы")))
99 (define (log-to-info tty user)
100 "Return a script that spawns the Info reader on the right section of the
102 (program-file "log-to-info"
103 #~(let* ((tty (open-file #$(string-append "/dev/" tty)
105 (locale (cadr (command-line)))
106 (language (string-take locale
107 (string-index locale #\_)))
108 (infodir "/run/current-system/profile/share/info")
109 (per-lang (string-append infodir "/guix." language
111 (file (if (file-exists? per-lang)
113 (string-append infodir "/guix.info")))
114 (node (or (assoc-ref '#$%installation-node-names
116 "System Installation")))
117 (redirect-port tty (current-output-port))
118 (redirect-port tty (current-error-port))
119 (redirect-port tty (current-input-port))
121 (let ((pw (getpwnam #$user)))
122 (setgid (passwd:gid pw))
123 (setuid (passwd:uid pw)))
125 ;; 'gunzip' is needed to decompress the doc.
126 (setenv "PATH" (string-append #$gzip "/bin"))
128 ;; Change this process' locale so that command-line
129 ;; arguments to 'info' are properly encoded.
132 (setlocale LC_ALL locale)
133 (setenv "LC_ALL" locale))
135 ;; Sometimes LOCALE itself is not available. In that
136 ;; case pick the one UTF-8 locale that's known to work
137 ;; instead of failing.
138 (setlocale LC_ALL "en_US.utf8")
139 (setenv "LC_ALL" "en_US.utf8")))
141 (execl #$(file-append info-reader "/bin/info")
142 "info" "-d" infodir "-f" file "-n" node))))
144 (define (documentation-shepherd-service tty)
145 (list (shepherd-service
146 (provision (list (symbol-append 'term- (string->symbol tty))))
147 (requirement '(user-processes host-name udev virtual-terminal))
148 (start #~(lambda* (#:optional (locale "en_US.utf8"))
150 (list #$(log-to-info tty "documentation") locale)
151 #:environment-variables
152 `("GUIX_LOCPATH=/run/current-system/locale"
154 (stop #~(make-kill-destructor)))))
156 (define %documentation-users
157 ;; User account for the Info viewer.
158 (list (user-account (name "documentation")
161 (home-directory "/var/empty"))))
163 (define documentation-service-type
164 ;; Documentation viewer service.
165 (service-type (name 'documentation)
167 (list (service-extension shepherd-root-service-type
168 documentation-shepherd-service)
169 (service-extension account-service-type
170 (const %documentation-users))))
171 (description "Run the Info reader on a tty.")))
174 (define %backing-directory
175 ;; Sub-directory used as the backing store for copy-on-write.
178 (define cow-store-service-type
179 (shepherd-service-type
183 (requirement '(root-file-system user-processes))
184 (provision '(cow-store))
186 "Make the store copy-on-write, with writes going to \
189 ;; This is meant to be explicitly started by the user.
192 (modules `((gnu build install)
195 (with-imported-modules (source-module-closure
196 '((gnu build install)))
199 (mount-cow-store target #$%backing-directory)
202 ;; Do nothing, and mark the service as stopped.
204 (stop #~(lambda (target)
205 ;; Delete the temporary directory, but leave everything
206 ;; mounted as there may still be processes using it since
207 ;; 'user-processes' doesn't depend on us. The 'user-file-systems'
208 ;; service will unmount TARGET eventually.
209 (delete-file-recursively
210 (string-append target #$%backing-directory))))))))
212 (define (cow-store-service)
213 "Return a service that makes the store copy-on-write, such that writes go to
214 the user's target storage device rather than on the RAM disk."
215 ;; See <http://bugs.gnu.org/18061> for the initial report.
216 (service cow-store-service-type 'mooooh!))
219 (define (/etc/configuration-files _)
220 "Return a list of tuples representing configuration templates to add to
223 (computed-file "configuration-templates"
224 (with-imported-modules '((guix build utils))
227 (for-each (lambda (file target)
229 (string-append #$output "/"
231 '(#$(local-file "examples/bare-bones.tmpl")
232 #$(local-file "examples/beaglebone-black.tmpl")
233 #$(local-file "examples/desktop.tmpl")
234 #$(local-file "examples/lightweight-desktop.tmpl"))
236 "beaglebone-black.scm"
238 "lightweight-desktop.scm"))
241 `(("configuration" ,directory)))
243 (define configuration-template-service-type
244 (service-type (name 'configuration-template)
246 (list (service-extension etc-service-type
247 /etc/configuration-files)))))
249 (define %configuration-template-service
250 (service configuration-template-service-type #t))
253 (define %nscd-minimal-caches
254 ;; Minimal in-memory caching policy for nscd.
255 (list (nscd-cache (database 'hosts)
256 (positive-time-to-live (* 3600 12))
258 ;; Do not cache lookup failures at all since they are
259 ;; quite likely (for instance when someone tries to ping a
260 ;; host before networking is functional.)
261 (negative-time-to-live 0)
264 (max-database-size (* 5 (expt 2 20)))))) ;5 MiB
267 ;; These define a service to load the uvesafb kernel module with the
268 ;; appropriate options. The GUI installer needs it when the machine does not
269 ;; support Kernel Mode Setting. Otherwise kmscon is missing /dev/fb0.
270 (define (uvesafb-shepherd-service _)
271 (list (shepherd-service
272 (documentation "Load the uvesafb kernel module if needed.")
273 (provision '(maybe-uvesafb))
274 (requirement '(file-systems))
276 ;; uvesafb is only supported on x86 and x86_64.
277 (or (not (and (string-suffix? "linux-gnu" %host-type)
278 (or (string-prefix? "x86_64" %host-type)
279 (string-prefix? "i686" %host-type))))
280 (file-exists? "/dev/fb0")
281 (invoke #+(file-append kmod "/bin/modprobe")
283 (string-append "v86d=" #$v86d "/sbin/v86d")
284 "mode_option=1024x768"))))
288 (define uvesafb-service-type
292 (list (service-extension shepherd-root-service-type
293 uvesafb-shepherd-service)))
295 "Load the @code{uvesafb} kernel module with the right options.")
298 (define %installation-services
299 ;; List of services of the installation system.
300 (let ((motd (plain-file "motd" "
301 \x1b[1;37mWelcome to the installation of GNU Guix!\x1b[0m
304 Using this shell, you can carry out the installation process \"manually.\"
305 Access documentation at any time by pressing Alt-F2.\x1b[0m
307 (define (normal-tty tty)
308 (mingetty-service (mingetty-configuration (tty tty)
312 (define bare-bones-os
313 (load "examples/bare-bones.tmpl"))
315 (list (service virtual-terminal-service-type)
317 (service kmscon-service-type
318 (kmscon-configuration
319 (virtual-terminal "tty1")
320 (login-program (installer-program))))
322 (login-service (login-configuration
325 ;; Documentation. The manual is in UTF-8, but
326 ;; 'console-font-service' sets up Unicode support and loads a font
327 ;; with all the useful glyphs like em dash and quotation marks.
328 (service documentation-service-type "tty2")
330 ;; Documentation add-on.
331 %configuration-template-service
333 ;; A bunch of 'root' ttys.
339 ;; The usual services.
342 ;; The build daemon. Register the default substitute server key(s)
343 ;; as trusted to allow the installation process to use substitutes by
345 (service guix-service-type
346 (guix-configuration (authorize-key? #t)))
348 ;; Start udev so that useful device nodes are available.
349 ;; Use device-mapper rules for cryptsetup & co; enable the CRDA for
350 ;; regulations-compliant WiFi access.
351 (udev-service #:rules (list lvm2 crda))
353 ;; Add the 'cow-store' service, which users have to start manually
354 ;; since it takes the installation directory as an argument.
357 ;; Install Unicode support and a suitable font.
358 (service console-font-service-type
361 ;; Use a font that contains characters such as
362 ;; curly quotes as found in the manual.
363 '("tty2" . "LatGrkCyr-8x16"))
365 ;; Use a font that doesn't have more than 256
366 ;; glyphs so that we can use colors with varying
367 ;; brightness levels (see note in setfont(8)).
368 `(,tty . "lat9u-16")))
369 '("tty1" "tty2" "tty3" "tty4" "tty5" "tty6")))
371 ;; To facilitate copy/paste.
372 (service gpm-service-type)
374 ;; Add an SSH server to facilitate remote installs.
375 (service openssh-service-type
376 (openssh-configuration
378 (permit-root-login #t)
379 ;; The root account is passwordless, so make sure
380 ;; a password is set before allowing logins.
381 (allow-empty-passwords? #f)
382 (password-authentication? #t)
384 ;; Don't start it upfront.
387 ;; Since this is running on a USB stick with a overlayfs as the root
388 ;; file system, use an appropriate cache configuration.
389 (nscd-service (nscd-configuration
390 (caches %nscd-minimal-caches)))
392 ;; Having /bin/sh is a good idea. In particular it allows Tramp
393 ;; connections to this system to work.
394 (service special-files-service-type
395 `(("/bin/sh" ,(file-append bash "/bin/sh"))))
397 ;; Loopback device, needed by OpenSSH notably.
398 (service static-networking-service-type
399 (list (static-networking (interface "lo")
402 (provision '(loopback)))))
404 (service wpa-supplicant-service-type)
406 (service connman-service-type
407 (connman-configuration
410 ;; Keep a reference to BARE-BONES-OS to make sure it can be
411 ;; installed without downloading/building anything. Also keep the
412 ;; things needed by 'profile-derivation' to minimize the amount of
414 (service gc-root-service-type
420 %default-locale-libcs))
422 ;; Machines without Kernel Mode Setting (those with many old and
423 ;; current AMD GPUs, SiS GPUs, ...) need uvesafb to show the GUI
424 ;; installer. Some may also need a kernel parameter like nomodeset
425 ;; or vga=793, but we leave that for the user to specify in GRUB.
426 (service uvesafb-service-type))))
431 \x1b[1;37mThis is an installation image of the GNU system. Welcome.\x1b[0m
433 \x1b[1;33mUse Alt-F2 for documentation.\x1b[0m
436 (define installation-os
437 ;; The operating system used on installation images for USB sticks etc.
440 (timezone "Europe/Paris")
441 (locale "en_US.utf8")
442 (bootloader (bootloader-configuration
443 (bootloader grub-bootloader)
444 (target "/dev/sda")))
445 (label (string-append "GNU Guix installation "
446 (package-version guix)))
449 ;; Note: the disk image build code overrides this root file system with
450 ;; the appropriate one.
453 (device (file-system-label "Guix_image"))
456 ;; Make /tmp a tmpfs instead of keeping the overlayfs. This
457 ;; originally was used for unionfs because FUSE creates
458 ;; '.fuse_hiddenXYZ' files for each open file, and this confuses
459 ;; Guix's test suite, for instance (see
460 ;; <http://bugs.gnu.org/23056>). We keep this for overlayfs to be
468 ;; XXX: This should be %BASE-FILE-SYSTEMS but we don't need
469 ;; elogind's cgroup file systems.
470 (list %pseudo-terminal-file-system
471 %shared-memory-file-system
475 (users (list (user-account
478 (supplementary-groups '("wheel")) ; allow use of sudo
480 (comment "Guest of GNU"))))
483 (services %installation-services)
485 ;; We don't need setuid programs, except for 'passwd', which can be handy
486 ;; if one is to allow remote SSH login to the machine being installed.
487 (setuid-programs (list (file-append shadow "/bin/passwd")))
490 ;; Explicitly allow for empty passwords.
491 (base-pam-services #:allow-empty-passwords? #t))
493 (packages (cons* glibc ;for 'tzselect' & co.
494 parted gptfdisk ddrescue
496 font-dejavu font-gnu-unifont
497 grub ;mostly so xrefs to its manual work
500 dosfstools ;mkfs.fat, for the UEFI boot partition
504 openssh ;we already have sshd, having ssh/scp can help
505 wireless-tools iw wpa-supplicant-minimal iproute
506 ;; XXX: We used to have GNU fdisk here, but as of version
507 ;; 2.0.0a, that pulls Guile 1.8, which takes unreasonable
508 ;; space; furthermore util-linux's fdisk is already
509 ;; available here, so we keep that.
512 nss-certs ; To access HTTPS, use git, etc.
515 (define* (os-with-u-boot os board #:key (bootloader-target "/dev/mmcblk0")
516 (triplet "arm-linux-gnueabihf"))
517 "Given OS, amend it with the u-boot bootloader for BOARD,
518 installed to BOOTLOADER-TARGET (a drive), compiled for TRIPLET.
520 If you want a serial console, make sure to specify one in your
521 operating-system's kernel-arguments (\"console=ttyS0\" or similar)."
522 (operating-system (inherit os)
523 (bootloader (bootloader-configuration
524 (bootloader (bootloader (inherit u-boot-bootloader)
525 (package (make-u-boot-package board triplet))))
526 (target bootloader-target)))))
528 (define* (embedded-installation-os bootloader bootloader-target tty
529 #:key (extra-modules '()))
530 "Return an installation os for embedded systems.
531 The initrd gets the extra modules EXTRA-MODULES.
532 A getty is provided on TTY.
533 The bootloader BOOTLOADER is installed to BOOTLOADER-TARGET."
535 (inherit installation-os)
536 (bootloader (bootloader-configuration
537 (bootloader bootloader)
538 (target bootloader-target)))
541 (cons (string-append "console=" tty)
542 (operating-system-user-kernel-arguments installation-os)))
543 (initrd-modules (append extra-modules %base-initrd-modules))))
545 (define beaglebone-black-installation-os
546 (embedded-installation-os u-boot-beaglebone-black-bootloader
550 ;; This module is required to mount the sd card.
554 (define a20-olinuxino-lime-installation-os
555 (embedded-installation-os u-boot-a20-olinuxino-lime-bootloader
556 "/dev/mmcblk0" ; SD card storage
559 (define a20-olinuxino-lime2-emmc-installation-os
560 (embedded-installation-os u-boot-a20-olinuxino-lime2-bootloader
561 "/dev/mmcblk1" ; eMMC storage
564 (define a20-olinuxino-micro-installation-os
565 (embedded-installation-os u-boot-a20-olinuxino-micro-bootloader
566 "/dev/mmcblk0" ; SD card storage
569 (define bananapi-m2-ultra-installation-os
570 (embedded-installation-os u-boot-bananapi-m2-ultra-bootloader
571 "/dev/mmcblk1" ; eMMC storage
574 (define firefly-rk3399-installation-os
575 (embedded-installation-os u-boot-firefly-rk3399-bootloader
576 "/dev/mmcblk0" ; SD card/eMMC (SD priority) storage
577 "ttyS2")) ; UART2 connected on the Pi2 bus
579 (define mx6cuboxi-installation-os
580 (embedded-installation-os u-boot-mx6cuboxi-bootloader
581 "/dev/mmcblk0" ; SD card storage
584 (define novena-installation-os
585 (embedded-installation-os u-boot-novena-bootloader
586 "/dev/mmcblk1" ; SD card storage
589 (define nintendo-nes-classic-edition-installation-os
590 (embedded-installation-os u-boot-nintendo-nes-classic-edition-bootloader
591 "/dev/mmcblk0" ; SD card (solder it yourself)
594 (define pine64-plus-installation-os
595 (embedded-installation-os u-boot-pine64-plus-bootloader
596 "/dev/mmcblk0" ; SD card storage
599 (define pinebook-installation-os
600 (embedded-installation-os u-boot-pinebook-bootloader
601 "/dev/mmcblk0" ; SD card storage
604 (define rock64-installation-os
605 (embedded-installation-os u-boot-rock64-rk3328-bootloader
606 "/dev/mmcblk0" ; SD card/eMMC (SD priority) storage
607 "ttyS2")) ; UART2 connected on the Pi2 bus
609 (define rockpro64-installation-os
610 (embedded-installation-os u-boot-rockpro64-rk3399-bootloader
611 "/dev/mmcblk0" ; SD card/eMMC (SD priority) storage
612 "ttyS2")) ; UART2 connected on the Pi2 bus
614 (define rk3399-puma-installation-os
615 (embedded-installation-os u-boot-puma-rk3399-bootloader
616 "/dev/mmcblk0" ; SD card storage
619 (define wandboard-installation-os
620 (embedded-installation-os u-boot-wandboard-bootloader
621 "/dev/mmcblk0" ; SD card storage
624 ;; Return the default os here so 'guix system' can consume it directly.
627 ;;; install.scm ends here