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 Tobias Geerinckx-Rice <me@tobias.gr>
8 ;;; This file is part of GNU Guix.
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.
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.
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/>.
23 (define-module (gnu system install)
25 #:use-module (gnu system)
26 #:use-module (gnu bootloader u-boot)
27 #:use-module (guix gexp)
28 #:use-module (guix store)
29 #:use-module (guix monads)
30 #:use-module ((guix packages) #:select (package-version))
31 #:use-module ((guix store) #:select (%store-prefix))
32 #:use-module (gnu installer)
33 #:use-module (gnu services dbus)
34 #:use-module (gnu services networking)
35 #:use-module (gnu services shepherd)
36 #:use-module (gnu services ssh)
37 #:use-module (gnu packages admin)
38 #:use-module (gnu packages bash)
39 #:use-module (gnu packages bootloaders)
40 #:use-module (gnu packages certs)
41 #:use-module (gnu packages fonts)
42 #:use-module (gnu packages fontutils)
43 #:use-module (gnu packages guile)
44 #:use-module (gnu packages linux)
45 #:use-module (gnu packages ssh)
46 #:use-module (gnu packages cryptsetup)
47 #:use-module (gnu packages package-management)
48 #:use-module (gnu packages disk)
49 #:use-module (gnu packages texinfo)
50 #:use-module (gnu packages compression)
51 #:use-module (gnu packages nvi)
52 #:use-module (ice-9 match)
53 #:use-module (srfi srfi-26)
54 #:export (installation-os
55 a20-olinuxino-lime-installation-os
56 a20-olinuxino-lime2-emmc-installation-os
57 a20-olinuxino-micro-installation-os
58 bananapi-m2-ultra-installation-os
59 beaglebone-black-installation-os
60 mx6cuboxi-installation-os
61 nintendo-nes-classic-edition-installation-os
62 novena-installation-os
63 pine64-plus-installation-os
64 pinebook-installation-os
65 rk3399-puma-installation-os
66 wandboard-installation-os
71 ;;; This module provides an 'operating-system' definition for use on images
72 ;;; for USB sticks etc., for the installation of the GNU system.
78 ;;; Documentation service.
81 (define %installation-node-names
82 ;; Translated name of the "System Installation" node of the manual. Ideally
83 ;; we'd extract it from the 'guix-manual' gettext domain, but that one is
84 ;; usually not available at run time, hence this hack.
85 '(("de" . "Systeminstallation")
86 ("en" . "System Installation")
87 ("fr" . "Installation du système")))
89 (define (log-to-info tty user)
90 "Return a script that spawns the Info reader on the right section of the
92 (program-file "log-to-info"
93 #~(let* ((tty (open-file #$(string-append "/dev/" tty)
95 (locale (cadr (command-line)))
96 (language (string-take locale
97 (string-index locale #\_)))
98 (infodir "/run/current-system/profile/share/info")
99 (per-lang (string-append infodir "/guix." language
101 (file (if (file-exists? per-lang)
103 (string-append infodir "/guix.info")))
104 (node (or (assoc-ref '#$%installation-node-names
106 "System Installation")))
107 (redirect-port tty (current-output-port))
108 (redirect-port tty (current-error-port))
109 (redirect-port tty (current-input-port))
111 (let ((pw (getpwnam #$user)))
112 (setgid (passwd:gid pw))
113 (setuid (passwd:uid pw)))
115 ;; 'gunzip' is needed to decompress the doc.
116 (setenv "PATH" (string-append #$gzip "/bin"))
118 ;; Change this process' locale so that command-line
119 ;; arguments to 'info' are properly encoded.
122 (setlocale LC_ALL locale)
123 (setenv "LC_ALL" locale))
125 ;; Sometimes LOCALE itself is not available. In that
126 ;; case pick the one UTF-8 locale that's known to work
127 ;; instead of failing.
128 (setlocale LC_ALL "en_US.utf8")
129 (setenv "LC_ALL" "en_US.utf8")))
131 (execl #$(file-append info-reader "/bin/info")
132 "info" "-d" infodir "-f" file "-n" node))))
134 (define (documentation-shepherd-service tty)
135 (list (shepherd-service
136 (provision (list (symbol-append 'term- (string->symbol tty))))
137 (requirement '(user-processes host-name udev virtual-terminal))
138 (start #~(lambda* (#:optional (locale "en_US.utf8"))
140 (list #$(log-to-info tty "documentation") locale)
141 #:environment-variables
142 `("GUIX_LOCPATH=/run/current-system/locale"
144 (stop #~(make-kill-destructor)))))
146 (define %documentation-users
147 ;; User account for the Info viewer.
148 (list (user-account (name "documentation")
151 (home-directory "/var/empty"))))
153 (define documentation-service-type
154 ;; Documentation viewer service.
155 (service-type (name 'documentation)
157 (list (service-extension shepherd-root-service-type
158 documentation-shepherd-service)
159 (service-extension account-service-type
160 (const %documentation-users))))
161 (description "Run the Info reader on a tty.")))
164 (define %backing-directory
165 ;; Sub-directory used as the backing store for copy-on-write.
168 (define (make-cow-store target)
169 "Return a gexp that makes the store copy-on-write, using TARGET as the
170 backing store. This is useful when TARGET is on a hard disk, whereas the
171 current store is on a RAM disk."
173 (define (set-store-permissions directory)
174 ;; Set the right perms on DIRECTORY to use it as the store.
176 (chown #$directory 0 30000) ;use the fixed 'guixbuild' GID
177 (chmod #$directory #o1775)))
180 ;; Bind-mount TARGET's /tmp in case we need space to build things.
181 (let ((tmpdir (string-append #$target "/tmp")))
183 (mount tmpdir "/tmp" "none" MS_BIND))
185 (let* ((rw-dir (string-append target #$%backing-directory))
186 (work-dir (string-append rw-dir "/../.overlayfs-workdir")))
189 (mkdir-p "/.rw-store")
190 #$(set-store-permissions #~rw-dir)
191 #$(set-store-permissions "/.rw-store")
193 ;; Mount the overlay, then atomically make it the store.
194 (mount "none" "/.rw-store" "overlay" 0
195 (string-append "lowerdir=" #$(%store-prefix) ","
196 "upperdir=" rw-dir ","
197 "workdir=" work-dir))
198 (mount "/.rw-store" #$(%store-prefix) "" MS_MOVE)
199 (rmdir "/.rw-store"))))
201 (define cow-store-service-type
202 (shepherd-service-type
206 (requirement '(root-file-system user-processes))
207 (provision '(cow-store))
209 "Make the store copy-on-write, with writes going to \
212 ;; This is meant to be explicitly started by the user.
215 (start #~(case-lambda
217 #$(make-cow-store #~target)
220 ;; Do nothing, and mark the service as stopped.
222 (stop #~(lambda (target)
223 ;; Delete the temporary directory, but leave everything
224 ;; mounted as there may still be processes using it since
225 ;; 'user-processes' doesn't depend on us. The 'user-file-systems'
226 ;; service will unmount TARGET eventually.
227 (delete-file-recursively
228 (string-append target #$%backing-directory))))))))
230 (define (cow-store-service)
231 "Return a service that makes the store copy-on-write, such that writes go to
232 the user's target storage device rather than on the RAM disk."
233 ;; See <http://bugs.gnu.org/18061> for the initial report.
234 (service cow-store-service-type 'mooooh!))
237 (define (/etc/configuration-files _)
238 "Return a list of tuples representing configuration templates to add to
241 (local-file (string-append "examples/" f)))
244 (computed-file "configuration-templates"
245 (with-imported-modules '((guix build utils))
248 (for-each (lambda (file target)
250 (string-append #$output "/"
252 '(#$(file "bare-bones.tmpl")
253 #$(file "beaglebone-black.tmpl")
254 #$(file "desktop.tmpl")
255 #$(file "lightweight-desktop.tmpl"))
257 "beaglebone-black.scm"
259 "lightweight-desktop.scm"))
262 `(("configuration" ,directory)))
264 (define configuration-template-service-type
265 (service-type (name 'configuration-template)
267 (list (service-extension etc-service-type
268 /etc/configuration-files)))))
270 (define %configuration-template-service
271 (service configuration-template-service-type #t))
274 (define %nscd-minimal-caches
275 ;; Minimal in-memory caching policy for nscd.
276 (list (nscd-cache (database 'hosts)
277 (positive-time-to-live (* 3600 12))
279 ;; Do not cache lookup failures at all since they are
280 ;; quite likely (for instance when someone tries to ping a
281 ;; host before networking is functional.)
282 (negative-time-to-live 0)
285 (max-database-size (* 5 (expt 2 20)))))) ;5 MiB
287 (define %installation-services
288 ;; List of services of the installation system.
289 (let ((motd (plain-file "motd" "
290 \x1b[1;37mWelcome to the installation of GNU Guix!\x1b[0m
293 Using this shell, you can carry out the installation process \"manually.\"
294 Access documentation at any time by pressing Alt-F2.\x1b[0m
296 (define (normal-tty tty)
297 (mingetty-service (mingetty-configuration (tty tty)
301 (define bare-bones-os
302 (load "examples/bare-bones.tmpl"))
304 (list (service virtual-terminal-service-type)
306 (service kmscon-service-type
307 (kmscon-configuration
308 (virtual-terminal "tty1")
309 (login-program (installer-program))))
311 (login-service (login-configuration
314 ;; Documentation. The manual is in UTF-8, but
315 ;; 'console-font-service' sets up Unicode support and loads a font
316 ;; with all the useful glyphs like em dash and quotation marks.
317 (service documentation-service-type "tty2")
319 ;; Documentation add-on.
320 %configuration-template-service
322 ;; A bunch of 'root' ttys.
328 ;; The usual services.
331 ;; The build daemon. Register the hydra.gnu.org key as trusted.
332 ;; This allows the installation process to use substitutes by
334 (service guix-service-type
335 (guix-configuration (authorize-key? #t)))
337 ;; Start udev so that useful device nodes are available.
338 ;; Use device-mapper rules for cryptsetup & co; enable the CRDA for
339 ;; regulations-compliant WiFi access.
340 (udev-service #:rules (list lvm2 crda))
342 ;; Add the 'cow-store' service, which users have to start manually
343 ;; since it takes the installation directory as an argument.
346 ;; Install Unicode support and a suitable font.
347 (service console-font-service-type
350 ;; Use a font that contains characters such as
351 ;; curly quotes as found in the manual.
352 '("tty2" . "LatGrkCyr-8x16"))
354 ;; Use a font that doesn't have more than 256
355 ;; glyphs so that we can use colors with varying
356 ;; brightness levels (see note in setfont(8)).
357 `(,tty . "lat9u-16")))
358 '("tty1" "tty2" "tty3" "tty4" "tty5" "tty6")))
360 ;; To facilitate copy/paste.
361 (service gpm-service-type)
363 ;; Add an SSH server to facilitate remote installs.
364 (service openssh-service-type
365 (openssh-configuration
367 (permit-root-login #t)
368 ;; The root account is passwordless, so make sure
369 ;; a password is set before allowing logins.
370 (allow-empty-passwords? #f)
371 (password-authentication? #t)
373 ;; Don't start it upfront.
376 ;; Since this is running on a USB stick with a overlayfs as the root
377 ;; file system, use an appropriate cache configuration.
378 (nscd-service (nscd-configuration
379 (caches %nscd-minimal-caches)))
381 ;; Having /bin/sh is a good idea. In particular it allows Tramp
382 ;; connections to this system to work.
383 (service special-files-service-type
384 `(("/bin/sh" ,(file-append (canonical-package bash)
387 ;; Loopback device, needed by OpenSSH notably.
388 (service static-networking-service-type
389 (list (static-networking (interface "lo")
392 (provision '(loopback)))))
394 (service wpa-supplicant-service-type)
396 (service connman-service-type
397 (connman-configuration
400 ;; Keep a reference to BARE-BONES-OS to make sure it can be
401 ;; installed without downloading/building anything. Also keep the
402 ;; things needed by 'profile-derivation' to minimize the amount of
404 (service gc-root-service-type
408 (canonical-package guile-2.2))))))
413 \x1b[1;37mThis is an installation image of the GNU system. Welcome.\x1b[0m
415 \x1b[1;33mUse Alt-F2 for documentation.\x1b[0m
418 (define installation-os
419 ;; The operating system used on installation images for USB sticks etc.
422 (timezone "Europe/Paris")
423 (locale "en_US.utf8")
424 (bootloader (bootloader-configuration
425 (bootloader grub-bootloader)
426 (target "/dev/sda")))
427 (label (string-append "GNU Guix installation "
428 (package-version guix)))
431 ;; Note: the disk image build code overrides this root file system with
432 ;; the appropriate one.
435 (device (file-system-label "Guix_image"))
438 ;; Make /tmp a tmpfs instead of keeping the overlayfs. This
439 ;; originally was used for unionfs because FUSE creates
440 ;; '.fuse_hiddenXYZ' files for each open file, and this confuses
441 ;; Guix's test suite, for instance (see
442 ;; <http://bugs.gnu.org/23056>). We keep this for overlayfs to be
450 ;; XXX: This should be %BASE-FILE-SYSTEMS but we don't need
451 ;; elogind's cgroup file systems.
452 (list %pseudo-terminal-file-system
453 %shared-memory-file-system
456 (users (list (user-account
459 (supplementary-groups '("wheel")) ; allow use of sudo
461 (comment "Guest of GNU"))))
464 (services %installation-services)
466 ;; We don't need setuid programs, except for 'passwd', which can be handy
467 ;; if one is to allow remote SSH login to the machine being installed.
468 (setuid-programs (list (file-append shadow "/bin/passwd")))
471 ;; Explicitly allow for empty passwords.
472 (base-pam-services #:allow-empty-passwords? #t))
474 (packages (cons* (canonical-package glibc) ;for 'tzselect' & co.
475 parted gptfdisk ddrescue
477 font-dejavu font-gnu-unifont
478 grub ;mostly so xrefs to its manual work
481 dosfstools ;mkfs.fat, for the UEFI boot partition
483 openssh ;we already have sshd, having ssh/scp can help
484 wireless-tools iw wpa-supplicant-minimal iproute
485 ;; XXX: We used to have GNU fdisk here, but as of version
486 ;; 2.0.0a, that pulls Guile 1.8, which takes unreasonable
487 ;; space; furthermore util-linux's fdisk is already
488 ;; available here, so we keep that.
491 nss-certs ; To access HTTPS, use git, etc.
494 (define* (os-with-u-boot os board #:key (bootloader-target "/dev/mmcblk0")
495 (triplet "arm-linux-gnueabihf"))
496 "Given OS, amend it with the u-boot bootloader for BOARD,
497 installed to BOOTLOADER-TARGET (a drive), compiled for TRIPLET.
499 If you want a serial console, make sure to specify one in your
500 operating-system's kernel-arguments (\"console=ttyS0\" or similar)."
501 (operating-system (inherit os)
502 (bootloader (bootloader-configuration
503 (bootloader (bootloader (inherit u-boot-bootloader)
504 (package (make-u-boot-package board triplet))))
505 (target bootloader-target)))))
507 (define* (embedded-installation-os bootloader bootloader-target tty
508 #:key (extra-modules '()))
509 "Return an installation os for embedded systems.
510 The initrd gets the extra modules EXTRA-MODULES.
511 A getty is provided on TTY.
512 The bootloader BOOTLOADER is installed to BOOTLOADER-TARGET."
514 (inherit installation-os)
515 (bootloader (bootloader-configuration
516 (bootloader bootloader)
517 (target bootloader-target)))
520 (cons (string-append "console=" tty)
521 (operating-system-user-kernel-arguments installation-os)))
522 (initrd-modules (append extra-modules %base-initrd-modules))))
524 (define beaglebone-black-installation-os
525 (embedded-installation-os u-boot-beaglebone-black-bootloader
529 ;; This module is required to mount the sd card.
533 (define a20-olinuxino-lime-installation-os
534 (embedded-installation-os u-boot-a20-olinuxino-lime-bootloader
535 "/dev/mmcblk0" ; SD card storage
538 (define a20-olinuxino-lime2-emmc-installation-os
539 (embedded-installation-os u-boot-a20-olinuxino-lime2-bootloader
540 "/dev/mmcblk1" ; eMMC storage
543 (define a20-olinuxino-micro-installation-os
544 (embedded-installation-os u-boot-a20-olinuxino-micro-bootloader
545 "/dev/mmcblk0" ; SD card storage
548 (define bananapi-m2-ultra-installation-os
549 (embedded-installation-os u-boot-bananapi-m2-ultra-bootloader
550 "/dev/mmcblk1" ; eMMC storage
553 (define mx6cuboxi-installation-os
554 (embedded-installation-os u-boot-mx6cuboxi-bootloader
555 "/dev/mmcblk0" ; SD card storage
558 (define novena-installation-os
559 (embedded-installation-os u-boot-novena-bootloader
560 "/dev/mmcblk1" ; SD card storage
563 (define nintendo-nes-classic-edition-installation-os
564 (embedded-installation-os u-boot-nintendo-nes-classic-edition-bootloader
565 "/dev/mmcblk0" ; SD card (solder it yourself)
568 (define pine64-plus-installation-os
569 (embedded-installation-os u-boot-pine64-plus-bootloader
570 "/dev/mmcblk0" ; SD card storage
573 (define pinebook-installation-os
574 (embedded-installation-os u-boot-pinebook-bootloader
575 "/dev/mmcblk0" ; SD card storage
578 (define rk3399-puma-installation-os
579 (embedded-installation-os u-boot-puma-rk3399-bootloader
580 "/dev/mmcblk0" ; SD card storage
583 (define wandboard-installation-os
584 (embedded-installation-os u-boot-wandboard-bootloader
585 "/dev/mmcblk0" ; SD card storage
588 ;; Return the default os here so 'guix system' can consume it directly.
591 ;;; install.scm ends here