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