install: Tweak motd.
[jackhill/guix/guix.git] / gnu / system / install.scm
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>
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 install)
24 #:use-module (gnu)
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 store) #:select (%store-prefix))
31 #:use-module (gnu installer)
32 #:use-module (gnu services dbus)
33 #:use-module (gnu services networking)
34 #:use-module (gnu services shepherd)
35 #:use-module (gnu services ssh)
36 #:use-module (gnu packages admin)
37 #:use-module (gnu packages bash)
38 #:use-module (gnu packages bootloaders)
39 #:use-module (gnu packages certs)
40 #:use-module (gnu packages fonts)
41 #:use-module (gnu packages fontutils)
42 #:use-module (gnu packages guile)
43 #:use-module (gnu packages linux)
44 #:use-module (gnu packages ssh)
45 #:use-module (gnu packages cryptsetup)
46 #:use-module (gnu packages package-management)
47 #:use-module (gnu packages disk)
48 #:use-module (gnu packages texinfo)
49 #:use-module (gnu packages compression)
50 #:use-module (gnu packages nvi)
51 #:use-module (ice-9 match)
52 #:use-module (srfi srfi-26)
53 #:export (installation-os
54 a20-olinuxino-lime-installation-os
55 a20-olinuxino-lime2-emmc-installation-os
56 a20-olinuxino-micro-installation-os
57 bananapi-m2-ultra-installation-os
58 beaglebone-black-installation-os
59 mx6cuboxi-installation-os
60 nintendo-nes-classic-edition-installation-os
61 novena-installation-os
62 pine64-plus-installation-os
63 pinebook-installation-os
64 rk3399-puma-installation-os
65 wandboard-installation-os
66 os-with-u-boot))
67
68 ;;; Commentary:
69 ;;;
70 ;;; This module provides an 'operating-system' definition for use on images
71 ;;; for USB sticks etc., for the installation of the GNU system.
72 ;;;
73 ;;; Code:
74
75 \f
76 (define (log-to-info)
77 "Return a script that spawns the Info reader on the right section of the
78 manual."
79 (program-file "log-to-info"
80 #~(begin
81 ;; 'gunzip' is needed to decompress the doc.
82 (setenv "PATH" (string-append #$gzip "/bin"))
83
84 (execl (string-append #$info-reader "/bin/info") "info"
85 "-d" "/run/current-system/profile/share/info"
86 "-f" (string-append #$guix "/share/info/guix.info")
87 "-n" "System Installation"))))
88
89 (define %backing-directory
90 ;; Sub-directory used as the backing store for copy-on-write.
91 "/tmp/guix-inst")
92
93 (define (make-cow-store target)
94 "Return a gexp that makes the store copy-on-write, using TARGET as the
95 backing store. This is useful when TARGET is on a hard disk, whereas the
96 current store is on a RAM disk."
97
98 (define (set-store-permissions directory)
99 ;; Set the right perms on DIRECTORY to use it as the store.
100 #~(begin
101 (chown #$directory 0 30000) ;use the fixed 'guixbuild' GID
102 (chmod #$directory #o1775)))
103
104 #~(begin
105 ;; Bind-mount TARGET's /tmp in case we need space to build things.
106 (let ((tmpdir (string-append #$target "/tmp")))
107 (mkdir-p tmpdir)
108 (mount tmpdir "/tmp" "none" MS_BIND))
109
110 (let* ((rw-dir (string-append target #$%backing-directory))
111 (work-dir (string-append rw-dir "/../.overlayfs-workdir")))
112 (mkdir-p rw-dir)
113 (mkdir-p work-dir)
114 (mkdir-p "/.rw-store")
115 #$(set-store-permissions #~rw-dir)
116 #$(set-store-permissions "/.rw-store")
117
118 ;; Mount the overlay, then atomically make it the store.
119 (mount "none" "/.rw-store" "overlay" 0
120 (string-append "lowerdir=" #$(%store-prefix) ","
121 "upperdir=" rw-dir ","
122 "workdir=" work-dir))
123 (mount "/.rw-store" #$(%store-prefix) "" MS_MOVE)
124 (rmdir "/.rw-store"))))
125
126 (define cow-store-service-type
127 (shepherd-service-type
128 'cow-store
129 (lambda _
130 (shepherd-service
131 (requirement '(root-file-system user-processes))
132 (provision '(cow-store))
133 (documentation
134 "Make the store copy-on-write, with writes going to \
135 the given target.")
136
137 ;; This is meant to be explicitly started by the user.
138 (auto-start? #f)
139
140 (start #~(case-lambda
141 ((target)
142 #$(make-cow-store #~target)
143 target)
144 (else
145 ;; Do nothing, and mark the service as stopped.
146 #f)))
147 (stop #~(lambda (target)
148 ;; Delete the temporary directory, but leave everything
149 ;; mounted as there may still be processes using it since
150 ;; 'user-processes' doesn't depend on us. The 'user-file-systems'
151 ;; service will unmount TARGET eventually.
152 (delete-file-recursively
153 (string-append target #$%backing-directory))))))))
154
155 (define (cow-store-service)
156 "Return a service that makes the store copy-on-write, such that writes go to
157 the user's target storage device rather than on the RAM disk."
158 ;; See <http://bugs.gnu.org/18061> for the initial report.
159 (service cow-store-service-type 'mooooh!))
160
161
162 (define (/etc/configuration-files _)
163 "Return a list of tuples representing configuration templates to add to
164 /etc."
165 (define (file f)
166 (local-file (string-append "examples/" f)))
167
168 (define directory
169 (computed-file "configuration-templates"
170 (with-imported-modules '((guix build utils))
171 #~(begin
172 (mkdir #$output)
173 (for-each (lambda (file target)
174 (copy-file file
175 (string-append #$output "/"
176 target)))
177 '(#$(file "bare-bones.tmpl")
178 #$(file "beaglebone-black.tmpl")
179 #$(file "desktop.tmpl")
180 #$(file "lightweight-desktop.tmpl"))
181 '("bare-bones.scm"
182 "beaglebone-black.scm"
183 "desktop.scm"
184 "lightweight-desktop.scm"))
185 #t))))
186
187 `(("configuration" ,directory)))
188
189 (define configuration-template-service-type
190 (service-type (name 'configuration-template)
191 (extensions
192 (list (service-extension etc-service-type
193 /etc/configuration-files)))))
194
195 (define %configuration-template-service
196 (service configuration-template-service-type #t))
197
198
199 (define %nscd-minimal-caches
200 ;; Minimal in-memory caching policy for nscd.
201 (list (nscd-cache (database 'hosts)
202 (positive-time-to-live (* 3600 12))
203
204 ;; Do not cache lookup failures at all since they are
205 ;; quite likely (for instance when someone tries to ping a
206 ;; host before networking is functional.)
207 (negative-time-to-live 0)
208
209 (persistent? #f)
210 (max-database-size (* 5 (expt 2 20)))))) ;5 MiB
211
212 (define %installation-services
213 ;; List of services of the installation system.
214 (let ((motd (plain-file "motd" "
215 \x1b[1;37mWelcome to the installation of GNU Guix!\x1b[0m
216
217 \x1b[2m\
218 Using this shell, you can carry out the installation process \"manually.\"
219 Access documentation at any time by pressing Alt-F2.\x1b[0m
220 ")))
221 (define (normal-tty tty)
222 (mingetty-service (mingetty-configuration (tty tty)
223 (auto-login "root")
224 (login-pause? #t))))
225
226 (define bare-bones-os
227 (load "examples/bare-bones.tmpl"))
228
229 (list (service virtual-terminal-service-type)
230
231 (service kmscon-service-type
232 (kmscon-configuration
233 (virtual-terminal "tty1")
234 (login-program (installer-program))))
235
236 (login-service (login-configuration
237 (motd motd)))
238
239 ;; Documentation. The manual is in UTF-8, but
240 ;; 'console-font-service' sets up Unicode support and loads a font
241 ;; with all the useful glyphs like em dash and quotation marks.
242 (mingetty-service (mingetty-configuration
243 (tty "tty2")
244 (auto-login "guest")
245 (login-program (log-to-info))))
246
247 ;; Documentation add-on.
248 %configuration-template-service
249
250 ;; A bunch of 'root' ttys.
251 (normal-tty "tty3")
252 (normal-tty "tty4")
253 (normal-tty "tty5")
254 (normal-tty "tty6")
255
256 ;; The usual services.
257 (syslog-service)
258
259 ;; The build daemon. Register the hydra.gnu.org key as trusted.
260 ;; This allows the installation process to use substitutes by
261 ;; default.
262 (service guix-service-type
263 (guix-configuration (authorize-key? #t)))
264
265 ;; Start udev so that useful device nodes are available.
266 ;; Use device-mapper rules for cryptsetup & co; enable the CRDA for
267 ;; regulations-compliant WiFi access.
268 (udev-service #:rules (list lvm2 crda))
269
270 ;; Add the 'cow-store' service, which users have to start manually
271 ;; since it takes the installation directory as an argument.
272 (cow-store-service)
273
274 ;; Install Unicode support and a suitable font. Use a font that
275 ;; doesn't have more than 256 glyphs so that we can use colors with
276 ;; varying brightness levels (see note in setfont(8)).
277 (service console-font-service-type
278 (map (lambda (tty)
279 (cons tty "lat9u-16"))
280 '("tty1" "tty2" "tty3" "tty4" "tty5" "tty6")))
281
282 ;; To facilitate copy/paste.
283 (service gpm-service-type)
284
285 ;; Add an SSH server to facilitate remote installs.
286 (service openssh-service-type
287 (openssh-configuration
288 (port-number 22)
289 (permit-root-login #t)
290 ;; The root account is passwordless, so make sure
291 ;; a password is set before allowing logins.
292 (allow-empty-passwords? #f)
293 (password-authentication? #t)
294
295 ;; Don't start it upfront.
296 (%auto-start? #f)))
297
298 ;; Since this is running on a USB stick with a overlayfs as the root
299 ;; file system, use an appropriate cache configuration.
300 (nscd-service (nscd-configuration
301 (caches %nscd-minimal-caches)))
302
303 ;; Having /bin/sh is a good idea. In particular it allows Tramp
304 ;; connections to this system to work.
305 (service special-files-service-type
306 `(("/bin/sh" ,(file-append (canonical-package bash)
307 "/bin/sh"))))
308
309 ;; Loopback device, needed by OpenSSH notably.
310 (service static-networking-service-type
311 (list (static-networking (interface "lo")
312 (ip "127.0.0.1")
313 (requirement '())
314 (provision '(loopback)))))
315
316 (service wpa-supplicant-service-type)
317 (dbus-service)
318 (service connman-service-type
319 (connman-configuration
320 (disable-vpn? #t)))
321
322 ;; Keep a reference to BARE-BONES-OS to make sure it can be
323 ;; installed without downloading/building anything. Also keep the
324 ;; things needed by 'profile-derivation' to minimize the amount of
325 ;; download.
326 (service gc-root-service-type
327 (list bare-bones-os
328 glibc-utf8-locales
329 texinfo
330 (canonical-package guile-2.2))))))
331
332 (define %issue
333 ;; Greeting.
334 "
335 \x1b[1;37mThis is an installation image of the GNU system. Welcome.\x1b[0m
336
337 \x1b[1;33mUse Alt-F2 for documentation.\x1b[0m
338 ")
339
340 (define installation-os
341 ;; The operating system used on installation images for USB sticks etc.
342 (operating-system
343 (host-name "gnu")
344 (timezone "Europe/Paris")
345 (locale "en_US.utf8")
346 (bootloader (bootloader-configuration
347 (bootloader grub-bootloader)
348 (target "/dev/sda")))
349 (file-systems
350 ;; Note: the disk image build code overrides this root file system with
351 ;; the appropriate one.
352 (cons* (file-system
353 (mount-point "/")
354 (device (file-system-label "Guix_image"))
355 (type "ext4"))
356
357 ;; Make /tmp a tmpfs instead of keeping the overlayfs. This
358 ;; originally was used for unionfs because FUSE creates
359 ;; '.fuse_hiddenXYZ' files for each open file, and this confuses
360 ;; Guix's test suite, for instance (see
361 ;; <http://bugs.gnu.org/23056>). We keep this for overlayfs to be
362 ;; on the safe side.
363 (file-system
364 (mount-point "/tmp")
365 (device "none")
366 (type "tmpfs")
367 (check? #f))
368
369 ;; XXX: This should be %BASE-FILE-SYSTEMS but we don't need
370 ;; elogind's cgroup file systems.
371 (list %pseudo-terminal-file-system
372 %shared-memory-file-system
373 %immutable-store)))
374
375 (users (list (user-account
376 (name "guest")
377 (group "users")
378 (supplementary-groups '("wheel")) ; allow use of sudo
379 (password "")
380 (comment "Guest of GNU"))))
381
382 (issue %issue)
383 (services %installation-services)
384
385 ;; We don't need setuid programs, except for 'passwd', which can be handy
386 ;; if one is to allow remote SSH login to the machine being installed.
387 (setuid-programs (list (file-append shadow "/bin/passwd")))
388
389 (pam-services
390 ;; Explicitly allow for empty passwords.
391 (base-pam-services #:allow-empty-passwords? #t))
392
393 (packages (cons* (canonical-package glibc) ;for 'tzselect' & co.
394 parted gptfdisk ddrescue
395 fontconfig
396 font-dejavu font-gnu-unifont
397 grub ;mostly so xrefs to its manual work
398 cryptsetup
399 mdadm
400 dosfstools ;mkfs.fat, for the UEFI boot partition
401 btrfs-progs
402 openssh ;we already have sshd, having ssh/scp can help
403 wireless-tools iw wpa-supplicant-minimal iproute
404 ;; XXX: We used to have GNU fdisk here, but as of version
405 ;; 2.0.0a, that pulls Guile 1.8, which takes unreasonable
406 ;; space; furthermore util-linux's fdisk is already
407 ;; available here, so we keep that.
408 bash-completion
409 nvi ;:wq!
410 nss-certs ; To access HTTPS, use git, etc.
411 %base-packages))))
412
413 (define* (os-with-u-boot os board #:key (bootloader-target "/dev/mmcblk0")
414 (triplet "arm-linux-gnueabihf"))
415 "Given OS, amend it with the u-boot bootloader for BOARD,
416 installed to BOOTLOADER-TARGET (a drive), compiled for TRIPLET.
417
418 If you want a serial console, make sure to specify one in your
419 operating-system's kernel-arguments (\"console=ttyS0\" or similar)."
420 (operating-system (inherit os)
421 (bootloader (bootloader-configuration
422 (bootloader (bootloader (inherit u-boot-bootloader)
423 (package (make-u-boot-package board triplet))))
424 (target bootloader-target)))))
425
426 (define* (embedded-installation-os bootloader bootloader-target tty
427 #:key (extra-modules '()))
428 "Return an installation os for embedded systems.
429 The initrd gets the extra modules EXTRA-MODULES.
430 A getty is provided on TTY.
431 The bootloader BOOTLOADER is installed to BOOTLOADER-TARGET."
432 (operating-system
433 (inherit installation-os)
434 (bootloader (bootloader-configuration
435 (bootloader bootloader)
436 (target bootloader-target)))
437 (kernel linux-libre)
438 (kernel-arguments
439 (cons (string-append "console=" tty)
440 (operating-system-user-kernel-arguments installation-os)))
441 (initrd-modules (append extra-modules %base-initrd-modules))))
442
443 (define beaglebone-black-installation-os
444 (embedded-installation-os u-boot-beaglebone-black-bootloader
445 "/dev/sda"
446 "ttyO0"
447 #:extra-modules
448 ;; This module is required to mount the sd card.
449 '("omap_hsmmc")))
450
451
452 (define a20-olinuxino-lime-installation-os
453 (embedded-installation-os u-boot-a20-olinuxino-lime-bootloader
454 "/dev/mmcblk0" ; SD card storage
455 "ttyS0"))
456
457 (define a20-olinuxino-lime2-emmc-installation-os
458 (embedded-installation-os u-boot-a20-olinuxino-lime2-bootloader
459 "/dev/mmcblk1" ; eMMC storage
460 "ttyS0"))
461
462 (define a20-olinuxino-micro-installation-os
463 (embedded-installation-os u-boot-a20-olinuxino-micro-bootloader
464 "/dev/mmcblk0" ; SD card storage
465 "ttyS0"))
466
467 (define bananapi-m2-ultra-installation-os
468 (embedded-installation-os u-boot-bananapi-m2-ultra-bootloader
469 "/dev/mmcblk1" ; eMMC storage
470 "ttyS0"))
471
472 (define mx6cuboxi-installation-os
473 (embedded-installation-os u-boot-mx6cuboxi-bootloader
474 "/dev/mmcblk0" ; SD card storage
475 "ttymxc0"))
476
477 (define novena-installation-os
478 (embedded-installation-os u-boot-novena-bootloader
479 "/dev/mmcblk1" ; SD card storage
480 "ttymxc1"))
481
482 (define nintendo-nes-classic-edition-installation-os
483 (embedded-installation-os u-boot-nintendo-nes-classic-edition-bootloader
484 "/dev/mmcblk0" ; SD card (solder it yourself)
485 "ttyS0"))
486
487 (define pine64-plus-installation-os
488 (embedded-installation-os u-boot-pine64-plus-bootloader
489 "/dev/mmcblk0" ; SD card storage
490 "ttyS0"))
491
492 (define pinebook-installation-os
493 (embedded-installation-os u-boot-pinebook-bootloader
494 "/dev/mmcblk0" ; SD card storage
495 "ttyS0"))
496
497 (define rk3399-puma-installation-os
498 (embedded-installation-os u-boot-puma-rk3399-bootloader
499 "/dev/mmcblk0" ; SD card storage
500 "ttyS0"))
501
502 (define wandboard-installation-os
503 (embedded-installation-os u-boot-wandboard-bootloader
504 "/dev/mmcblk0" ; SD card storage
505 "ttymxc0"))
506
507 ;; Return the default os here so 'guix system' can consume it directly.
508 installation-os
509
510 ;;; install.scm ends here