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 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
69 ;;; This module provides an 'operating-system' definition for use on images
70 ;;; for USB sticks etc., for the installation of the GNU system.
76 "Return a script that spawns the Info reader on the right section of the
78 (program-file "log-to-info"
80 ;; 'gunzip' is needed to decompress the doc.
81 (setenv "PATH" (string-append #$gzip "/bin"))
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"))))
88 (define %backing-directory
89 ;; Sub-directory used as the backing store for copy-on-write.
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."
97 (define (set-store-permissions directory)
98 ;; Set the right perms on DIRECTORY to use it as the store.
100 (chown #$directory 0 30000) ;use the fixed 'guixbuild' GID
101 (chmod #$directory #o1775)))
104 ;; Bind-mount TARGET's /tmp in case we need space to build things.
105 (let ((tmpdir (string-append #$target "/tmp")))
107 (mount tmpdir "/tmp" "none" MS_BIND))
109 (let* ((rw-dir (string-append target #$%backing-directory))
110 (work-dir (string-append rw-dir "/../.overlayfs-workdir")))
113 (mkdir-p "/.rw-store")
114 #$(set-store-permissions #~rw-dir)
115 #$(set-store-permissions "/.rw-store")
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"))))
125 (define cow-store-service-type
126 (shepherd-service-type
130 (requirement '(root-file-system user-processes))
131 (provision '(cow-store))
133 "Make the store copy-on-write, with writes going to \
136 ;; This is meant to be explicitly started by the user.
139 (start #~(case-lambda
141 #$(make-cow-store #~target)
144 ;; Do nothing, and mark the service as stopped.
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))))))))
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!))
161 (define (/etc/configuration-files _)
162 "Return a list of tuples representing configuration templates to add to
165 (local-file (string-append "examples/" f)))
168 (computed-file "configuration-templates"
169 (with-imported-modules '((guix build utils))
172 (for-each (lambda (file target)
174 (string-append #$output "/"
176 '(#$(file "bare-bones.tmpl")
177 #$(file "beaglebone-black.tmpl")
178 #$(file "desktop.tmpl")
179 #$(file "lightweight-desktop.tmpl"))
181 "beaglebone-black.scm"
183 "lightweight-desktop.scm"))
186 `(("configuration" ,directory)))
188 (define configuration-template-service-type
189 (service-type (name 'configuration-template)
191 (list (service-extension etc-service-type
192 /etc/configuration-files)))))
194 (define %configuration-template-service
195 (service configuration-template-service-type #t))
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))
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)
209 (max-database-size (* 5 (expt 2 20)))))) ;5 MiB
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
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.
220 You have been warned. Thanks for being so brave.\x1b[0m
222 (define (normal-tty tty)
223 (mingetty-service (mingetty-configuration (tty tty)
227 (define bare-bones-os
228 (load "examples/bare-bones.tmpl"))
230 (list (service virtual-terminal-service-type)
232 (service kmscon-service-type
233 (kmscon-configuration
234 (virtual-terminal "tty1")
235 (login-program (installer-program))))
237 (login-service (login-configuration
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
246 (login-program (log-to-info))))
248 ;; Documentation add-on.
249 %configuration-template-service
251 ;; A bunch of 'root' ttys.
257 ;; The usual services.
260 ;; The build daemon. Register the hydra.gnu.org key as trusted.
261 ;; This allows the installation process to use substitutes by
263 (service guix-service-type
264 (guix-configuration (authorize-key? #t)))
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))
271 ;; Add the 'cow-store' service, which users have to start manually
272 ;; since it takes the installation directory as an argument.
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
280 (cons tty "lat9u-16"))
281 '("tty1" "tty2" "tty3" "tty4" "tty5" "tty6")))
283 ;; To facilitate copy/paste.
284 (service gpm-service-type)
286 ;; Add an SSH server to facilitate remote installs.
287 (service openssh-service-type
288 (openssh-configuration
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)
296 ;; Don't start it upfront.
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)))
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)
310 ;; Loopback device, needed by OpenSSH notably.
311 (service static-networking-service-type
312 (list (static-networking (interface "lo")
315 (provision '(loopback)))))
317 (service wpa-supplicant-service-type)
319 (service connman-service-type
320 (connman-configuration
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
327 (service gc-root-service-type
331 (canonical-package guile-2.2))))))
336 \x1b[1;37mThis is an installation image of the GNU system. Welcome.\x1b[0m
338 \x1b[1;33mUse Alt-F2 for documentation.\x1b[0m
341 (define installation-os
342 ;; The operating system used on installation images for USB sticks etc.
345 (timezone "Europe/Paris")
346 (locale "en_US.utf8")
347 (bootloader (bootloader-configuration
348 (bootloader grub-bootloader)
349 (target "/dev/sda")))
351 ;; Note: the disk image build code overrides this root file system with
352 ;; the appropriate one.
355 (device (file-system-label "GuixSD_image"))
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
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
376 (users (list (user-account
379 (supplementary-groups '("wheel")) ; allow use of sudo
381 (comment "Guest of GNU")
382 (home-directory "/home/guest"))))
385 (services %installation-services)
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")))
392 ;; Explicitly allow for empty passwords.
393 (base-pam-services #:allow-empty-passwords? #t))
395 (packages (cons* (canonical-package glibc) ;for 'tzselect' & co.
396 parted gptfdisk ddrescue
398 font-dejavu font-gnu-unifont
399 grub ;mostly so xrefs to its manual work
402 dosfstools ;mkfs.fat, for the UEFI boot partition
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.
412 nss-certs ; To access HTTPS, use git, etc.
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.
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)))))
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."
435 (inherit installation-os)
436 (bootloader (bootloader-configuration
437 (bootloader bootloader)
438 (target bootloader-target)))
441 (cons (string-append "console=" tty)
442 (operating-system-user-kernel-arguments installation-os)))
443 (initrd-modules (append extra-modules %base-initrd-modules))))
445 (define beaglebone-black-installation-os
446 (embedded-installation-os u-boot-beaglebone-black-bootloader
450 ;; This module is required to mount the sd card.
454 (define a20-olinuxino-lime-installation-os
455 (embedded-installation-os u-boot-a20-olinuxino-lime-bootloader
456 "/dev/mmcblk0" ; SD card storage
459 (define a20-olinuxino-lime2-emmc-installation-os
460 (embedded-installation-os u-boot-a20-olinuxino-lime2-bootloader
461 "/dev/mmcblk1" ; eMMC storage
464 (define a20-olinuxino-micro-installation-os
465 (embedded-installation-os u-boot-a20-olinuxino-micro-bootloader
466 "/dev/mmcblk0" ; SD card storage
469 (define bananapi-m2-ultra-installation-os
470 (embedded-installation-os u-boot-bananapi-m2-ultra-bootloader
471 "/dev/mmcblk1" ; eMMC storage
474 (define mx6cuboxi-installation-os
475 (embedded-installation-os u-boot-mx6cuboxi-bootloader
476 "/dev/mmcblk0" ; SD card storage
479 (define novena-installation-os
480 (embedded-installation-os u-boot-novena-bootloader
481 "/dev/mmcblk1" ; SD card storage
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)
489 (define pine64-plus-installation-os
490 (embedded-installation-os u-boot-pine64-plus-bootloader
491 "/dev/mmcblk0" ; SD card storage
494 (define pinebook-installation-os
495 (embedded-installation-os u-boot-pinebook-bootloader
496 "/dev/mmcblk0" ; SD card storage
499 (define rk3399-puma-installation-os
500 (embedded-installation-os u-boot-puma-rk3399-bootloader
501 "/dev/mmcblk0" ; SD card storage
504 (define wandboard-installation-os
505 (embedded-installation-os u-boot-wandboard-bootloader
506 "/dev/mmcblk0" ; SD card storage
509 ;; Return the default os here so 'guix system' can consume it directly.
512 ;;; install.scm ends here