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 (make-cow-store target)
179 "Return a gexp that makes the store copy-on-write, using TARGET as the
180 backing store. This is useful when TARGET is on a hard disk, whereas the
181 current store is on a RAM disk."
183 (define (set-store-permissions directory)
184 ;; Set the right perms on DIRECTORY to use it as the store.
186 (chown #$directory 0 30000) ;use the fixed 'guixbuild' GID
187 (chmod #$directory #o1775)))
190 ;; Bind-mount TARGET's /tmp in case we need space to build things.
191 (let ((tmpdir (string-append #$target "/tmp")))
193 (mount tmpdir "/tmp" "none" MS_BIND))
195 (let* ((rw-dir (string-append target #$%backing-directory))
196 (work-dir (string-append rw-dir "/../.overlayfs-workdir")))
199 (mkdir-p "/.rw-store")
200 #$(set-store-permissions #~rw-dir)
201 #$(set-store-permissions "/.rw-store")
203 ;; Mount the overlay, then atomically make it the store.
204 (mount "none" "/.rw-store" "overlay" 0
205 (string-append "lowerdir=" #$(%store-prefix) ","
206 "upperdir=" rw-dir ","
207 "workdir=" work-dir))
208 (mount "/.rw-store" #$(%store-prefix) "" MS_MOVE)
209 (rmdir "/.rw-store"))))
211 (define cow-store-service-type
212 (shepherd-service-type
216 (requirement '(root-file-system user-processes))
217 (provision '(cow-store))
219 "Make the store copy-on-write, with writes going to \
222 ;; This is meant to be explicitly started by the user.
225 (start #~(case-lambda
227 #$(make-cow-store #~target)
230 ;; Do nothing, and mark the service as stopped.
232 (stop #~(lambda (target)
233 ;; Delete the temporary directory, but leave everything
234 ;; mounted as there may still be processes using it since
235 ;; 'user-processes' doesn't depend on us. The 'user-file-systems'
236 ;; service will unmount TARGET eventually.
237 (delete-file-recursively
238 (string-append target #$%backing-directory))))))))
240 (define (cow-store-service)
241 "Return a service that makes the store copy-on-write, such that writes go to
242 the user's target storage device rather than on the RAM disk."
243 ;; See <http://bugs.gnu.org/18061> for the initial report.
244 (service cow-store-service-type 'mooooh!))
247 (define (/etc/configuration-files _)
248 "Return a list of tuples representing configuration templates to add to
251 (computed-file "configuration-templates"
252 (with-imported-modules '((guix build utils))
255 (for-each (lambda (file target)
257 (string-append #$output "/"
259 '(#$(local-file "examples/bare-bones.tmpl")
260 #$(local-file "examples/beaglebone-black.tmpl")
261 #$(local-file "examples/desktop.tmpl")
262 #$(local-file "examples/lightweight-desktop.tmpl"))
264 "beaglebone-black.scm"
266 "lightweight-desktop.scm"))
269 `(("configuration" ,directory)))
271 (define configuration-template-service-type
272 (service-type (name 'configuration-template)
274 (list (service-extension etc-service-type
275 /etc/configuration-files)))))
277 (define %configuration-template-service
278 (service configuration-template-service-type #t))
281 (define %nscd-minimal-caches
282 ;; Minimal in-memory caching policy for nscd.
283 (list (nscd-cache (database 'hosts)
284 (positive-time-to-live (* 3600 12))
286 ;; Do not cache lookup failures at all since they are
287 ;; quite likely (for instance when someone tries to ping a
288 ;; host before networking is functional.)
289 (negative-time-to-live 0)
292 (max-database-size (* 5 (expt 2 20)))))) ;5 MiB
295 ;; These define a service to load the uvesafb kernel module with the
296 ;; appropriate options. The GUI installer needs it when the machine does not
297 ;; support Kernel Mode Setting. Otherwise kmscon is missing /dev/fb0.
298 (define (uvesafb-shepherd-service _)
299 (list (shepherd-service
300 (documentation "Load the uvesafb kernel module if needed.")
301 (provision '(maybe-uvesafb))
302 (requirement '(file-systems))
304 ;; uvesafb is only supported on x86 and x86_64.
305 (or (not (and (string-suffix? "linux-gnu" %host-type)
306 (or (string-prefix? "x86_64" %host-type)
307 (string-prefix? "i686" %host-type))))
308 (file-exists? "/dev/fb0")
309 (invoke #+(file-append kmod "/bin/modprobe")
311 (string-append "v86d=" #$v86d "/sbin/v86d")
312 "mode_option=1024x768"))))
316 (define uvesafb-service-type
320 (list (service-extension shepherd-root-service-type
321 uvesafb-shepherd-service)))
323 "Load the @code{uvesafb} kernel module with the right options.")
326 (define %installation-services
327 ;; List of services of the installation system.
328 (let ((motd (plain-file "motd" "
329 \x1b[1;37mWelcome to the installation of GNU Guix!\x1b[0m
332 Using this shell, you can carry out the installation process \"manually.\"
333 Access documentation at any time by pressing Alt-F2.\x1b[0m
335 (define (normal-tty tty)
336 (mingetty-service (mingetty-configuration (tty tty)
340 (define bare-bones-os
341 (load "examples/bare-bones.tmpl"))
343 (list (service virtual-terminal-service-type)
345 (service kmscon-service-type
346 (kmscon-configuration
347 (virtual-terminal "tty1")
348 (login-program (installer-program))))
350 (login-service (login-configuration
353 ;; Documentation. The manual is in UTF-8, but
354 ;; 'console-font-service' sets up Unicode support and loads a font
355 ;; with all the useful glyphs like em dash and quotation marks.
356 (service documentation-service-type "tty2")
358 ;; Documentation add-on.
359 %configuration-template-service
361 ;; A bunch of 'root' ttys.
367 ;; The usual services.
370 ;; The build daemon. Register the default substitute server key(s)
371 ;; as trusted to allow the installation process to use substitutes by
373 (service guix-service-type
374 (guix-configuration (authorize-key? #t)))
376 ;; Start udev so that useful device nodes are available.
377 ;; Use device-mapper rules for cryptsetup & co; enable the CRDA for
378 ;; regulations-compliant WiFi access.
379 (udev-service #:rules (list lvm2 crda))
381 ;; Add the 'cow-store' service, which users have to start manually
382 ;; since it takes the installation directory as an argument.
385 ;; Install Unicode support and a suitable font.
386 (service console-font-service-type
389 ;; Use a font that contains characters such as
390 ;; curly quotes as found in the manual.
391 '("tty2" . "LatGrkCyr-8x16"))
393 ;; Use a font that doesn't have more than 256
394 ;; glyphs so that we can use colors with varying
395 ;; brightness levels (see note in setfont(8)).
396 `(,tty . "lat9u-16")))
397 '("tty1" "tty2" "tty3" "tty4" "tty5" "tty6")))
399 ;; To facilitate copy/paste.
400 (service gpm-service-type)
402 ;; Add an SSH server to facilitate remote installs.
403 (service openssh-service-type
404 (openssh-configuration
406 (permit-root-login #t)
407 ;; The root account is passwordless, so make sure
408 ;; a password is set before allowing logins.
409 (allow-empty-passwords? #f)
410 (password-authentication? #t)
412 ;; Don't start it upfront.
415 ;; Since this is running on a USB stick with a overlayfs as the root
416 ;; file system, use an appropriate cache configuration.
417 (nscd-service (nscd-configuration
418 (caches %nscd-minimal-caches)))
420 ;; Having /bin/sh is a good idea. In particular it allows Tramp
421 ;; connections to this system to work.
422 (service special-files-service-type
423 `(("/bin/sh" ,(file-append bash "/bin/sh"))))
425 ;; Loopback device, needed by OpenSSH notably.
426 (service static-networking-service-type
427 (list (static-networking (interface "lo")
430 (provision '(loopback)))))
432 (service wpa-supplicant-service-type)
434 (service connman-service-type
435 (connman-configuration
438 ;; Keep a reference to BARE-BONES-OS to make sure it can be
439 ;; installed without downloading/building anything. Also keep the
440 ;; things needed by 'profile-derivation' to minimize the amount of
442 (service gc-root-service-type
448 %default-locale-libcs))
450 ;; Machines without Kernel Mode Setting (those with many old and
451 ;; current AMD GPUs, SiS GPUs, ...) need uvesafb to show the GUI
452 ;; installer. Some may also need a kernel parameter like nomodeset
453 ;; or vga=793, but we leave that for the user to specify in GRUB.
454 (service uvesafb-service-type))))
459 \x1b[1;37mThis is an installation image of the GNU system. Welcome.\x1b[0m
461 \x1b[1;33mUse Alt-F2 for documentation.\x1b[0m
464 (define installation-os
465 ;; The operating system used on installation images for USB sticks etc.
468 (timezone "Europe/Paris")
469 (locale "en_US.utf8")
470 (bootloader (bootloader-configuration
471 (bootloader grub-bootloader)
472 (target "/dev/sda")))
473 (label (string-append "GNU Guix installation "
474 (package-version guix)))
477 ;; Note: the disk image build code overrides this root file system with
478 ;; the appropriate one.
481 (device (file-system-label "Guix_image"))
484 ;; Make /tmp a tmpfs instead of keeping the overlayfs. This
485 ;; originally was used for unionfs because FUSE creates
486 ;; '.fuse_hiddenXYZ' files for each open file, and this confuses
487 ;; Guix's test suite, for instance (see
488 ;; <http://bugs.gnu.org/23056>). We keep this for overlayfs to be
496 ;; XXX: This should be %BASE-FILE-SYSTEMS but we don't need
497 ;; elogind's cgroup file systems.
498 (list %pseudo-terminal-file-system
499 %shared-memory-file-system
502 (users (list (user-account
505 (supplementary-groups '("wheel")) ; allow use of sudo
507 (comment "Guest of GNU"))))
510 (services %installation-services)
512 ;; We don't need setuid programs, except for 'passwd', which can be handy
513 ;; if one is to allow remote SSH login to the machine being installed.
514 (setuid-programs (list (file-append shadow "/bin/passwd")))
517 ;; Explicitly allow for empty passwords.
518 (base-pam-services #:allow-empty-passwords? #t))
520 (packages (cons* glibc ;for 'tzselect' & co.
521 parted gptfdisk ddrescue
523 font-dejavu font-gnu-unifont
524 grub ;mostly so xrefs to its manual work
527 dosfstools ;mkfs.fat, for the UEFI boot partition
531 openssh ;we already have sshd, having ssh/scp can help
532 wireless-tools iw wpa-supplicant-minimal iproute
533 ;; XXX: We used to have GNU fdisk here, but as of version
534 ;; 2.0.0a, that pulls Guile 1.8, which takes unreasonable
535 ;; space; furthermore util-linux's fdisk is already
536 ;; available here, so we keep that.
539 nss-certs ; To access HTTPS, use git, etc.
542 (define* (os-with-u-boot os board #:key (bootloader-target "/dev/mmcblk0")
543 (triplet "arm-linux-gnueabihf"))
544 "Given OS, amend it with the u-boot bootloader for BOARD,
545 installed to BOOTLOADER-TARGET (a drive), compiled for TRIPLET.
547 If you want a serial console, make sure to specify one in your
548 operating-system's kernel-arguments (\"console=ttyS0\" or similar)."
549 (operating-system (inherit os)
550 (bootloader (bootloader-configuration
551 (bootloader (bootloader (inherit u-boot-bootloader)
552 (package (make-u-boot-package board triplet))))
553 (target bootloader-target)))))
555 (define* (embedded-installation-os bootloader bootloader-target tty
556 #:key (extra-modules '()))
557 "Return an installation os for embedded systems.
558 The initrd gets the extra modules EXTRA-MODULES.
559 A getty is provided on TTY.
560 The bootloader BOOTLOADER is installed to BOOTLOADER-TARGET."
562 (inherit installation-os)
563 (bootloader (bootloader-configuration
564 (bootloader bootloader)
565 (target bootloader-target)))
568 (cons (string-append "console=" tty)
569 (operating-system-user-kernel-arguments installation-os)))
570 (initrd-modules (append extra-modules %base-initrd-modules))))
572 (define beaglebone-black-installation-os
573 (embedded-installation-os u-boot-beaglebone-black-bootloader
577 ;; This module is required to mount the sd card.
581 (define a20-olinuxino-lime-installation-os
582 (embedded-installation-os u-boot-a20-olinuxino-lime-bootloader
583 "/dev/mmcblk0" ; SD card storage
586 (define a20-olinuxino-lime2-emmc-installation-os
587 (embedded-installation-os u-boot-a20-olinuxino-lime2-bootloader
588 "/dev/mmcblk1" ; eMMC storage
591 (define a20-olinuxino-micro-installation-os
592 (embedded-installation-os u-boot-a20-olinuxino-micro-bootloader
593 "/dev/mmcblk0" ; SD card storage
596 (define bananapi-m2-ultra-installation-os
597 (embedded-installation-os u-boot-bananapi-m2-ultra-bootloader
598 "/dev/mmcblk1" ; eMMC storage
601 (define firefly-rk3399-installation-os
602 (embedded-installation-os u-boot-firefly-rk3399-bootloader
603 "/dev/mmcblk0" ; SD card/eMMC (SD priority) storage
604 "ttyS2")) ; UART2 connected on the Pi2 bus
606 (define mx6cuboxi-installation-os
607 (embedded-installation-os u-boot-mx6cuboxi-bootloader
608 "/dev/mmcblk0" ; SD card storage
611 (define novena-installation-os
612 (embedded-installation-os u-boot-novena-bootloader
613 "/dev/mmcblk1" ; SD card storage
616 (define nintendo-nes-classic-edition-installation-os
617 (embedded-installation-os u-boot-nintendo-nes-classic-edition-bootloader
618 "/dev/mmcblk0" ; SD card (solder it yourself)
621 (define pine64-plus-installation-os
622 (embedded-installation-os u-boot-pine64-plus-bootloader
623 "/dev/mmcblk0" ; SD card storage
626 (define pinebook-installation-os
627 (embedded-installation-os u-boot-pinebook-bootloader
628 "/dev/mmcblk0" ; SD card storage
631 (define rock64-installation-os
632 (embedded-installation-os u-boot-rock64-rk3328-bootloader
633 "/dev/mmcblk0" ; SD card/eMMC (SD priority) storage
634 "ttyS2")) ; UART2 connected on the Pi2 bus
636 (define rockpro64-installation-os
637 (embedded-installation-os u-boot-rockpro64-rk3399-bootloader
638 "/dev/mmcblk0" ; SD card/eMMC (SD priority) storage
639 "ttyS2")) ; UART2 connected on the Pi2 bus
641 (define rk3399-puma-installation-os
642 (embedded-installation-os u-boot-puma-rk3399-bootloader
643 "/dev/mmcblk0" ; SD card storage
646 (define wandboard-installation-os
647 (embedded-installation-os u-boot-wandboard-bootloader
648 "/dev/mmcblk0" ; SD card storage
651 ;; Return the default os here so 'guix system' can consume it directly.
654 ;;; install.scm ends here