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 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
70 ;;; This module provides an 'operating-system' definition for use on images
71 ;;; for USB sticks etc., for the installation of the GNU system.
77 "Return a script that spawns the Info reader on the right section of the
79 (program-file "log-to-info"
81 ;; 'gunzip' is needed to decompress the doc.
82 (setenv "PATH" (string-append #$gzip "/bin"))
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"))))
89 (define %backing-directory
90 ;; Sub-directory used as the backing store for copy-on-write.
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."
98 (define (set-store-permissions directory)
99 ;; Set the right perms on DIRECTORY to use it as the store.
101 (chown #$directory 0 30000) ;use the fixed 'guixbuild' GID
102 (chmod #$directory #o1775)))
105 ;; Bind-mount TARGET's /tmp in case we need space to build things.
106 (let ((tmpdir (string-append #$target "/tmp")))
108 (mount tmpdir "/tmp" "none" MS_BIND))
110 (let* ((rw-dir (string-append target #$%backing-directory))
111 (work-dir (string-append rw-dir "/../.overlayfs-workdir")))
114 (mkdir-p "/.rw-store")
115 #$(set-store-permissions #~rw-dir)
116 #$(set-store-permissions "/.rw-store")
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"))))
126 (define cow-store-service-type
127 (shepherd-service-type
131 (requirement '(root-file-system user-processes))
132 (provision '(cow-store))
134 "Make the store copy-on-write, with writes going to \
137 ;; This is meant to be explicitly started by the user.
140 (start #~(case-lambda
142 #$(make-cow-store #~target)
145 ;; Do nothing, and mark the service as stopped.
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))))))))
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!))
162 (define (/etc/configuration-files _)
163 "Return a list of tuples representing configuration templates to add to
166 (local-file (string-append "examples/" f)))
169 (computed-file "configuration-templates"
170 (with-imported-modules '((guix build utils))
173 (for-each (lambda (file target)
175 (string-append #$output "/"
177 '(#$(file "bare-bones.tmpl")
178 #$(file "beaglebone-black.tmpl")
179 #$(file "desktop.tmpl")
180 #$(file "lightweight-desktop.tmpl"))
182 "beaglebone-black.scm"
184 "lightweight-desktop.scm"))
187 `(("configuration" ,directory)))
189 (define configuration-template-service-type
190 (service-type (name 'configuration-template)
192 (list (service-extension etc-service-type
193 /etc/configuration-files)))))
195 (define %configuration-template-service
196 (service configuration-template-service-type #t))
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))
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)
210 (max-database-size (* 5 (expt 2 20)))))) ;5 MiB
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
218 Using this shell, you can carry out the installation process \"manually.\"
219 Access documentation at any time by pressing Alt-F2.\x1b[0m
221 (define (normal-tty tty)
222 (mingetty-service (mingetty-configuration (tty tty)
226 (define bare-bones-os
227 (load "examples/bare-bones.tmpl"))
229 (list (service virtual-terminal-service-type)
231 (service kmscon-service-type
232 (kmscon-configuration
233 (virtual-terminal "tty1")
234 (login-program (installer-program))))
236 (login-service (login-configuration
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
245 (login-program (log-to-info))))
247 ;; Documentation add-on.
248 %configuration-template-service
250 ;; A bunch of 'root' ttys.
256 ;; The usual services.
259 ;; The build daemon. Register the hydra.gnu.org key as trusted.
260 ;; This allows the installation process to use substitutes by
262 (service guix-service-type
263 (guix-configuration (authorize-key? #t)))
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))
270 ;; Add the 'cow-store' service, which users have to start manually
271 ;; since it takes the installation directory as an argument.
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
279 (cons tty "lat9u-16"))
280 '("tty1" "tty2" "tty3" "tty4" "tty5" "tty6")))
282 ;; To facilitate copy/paste.
283 (service gpm-service-type)
285 ;; Add an SSH server to facilitate remote installs.
286 (service openssh-service-type
287 (openssh-configuration
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)
295 ;; Don't start it upfront.
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)))
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)
309 ;; Loopback device, needed by OpenSSH notably.
310 (service static-networking-service-type
311 (list (static-networking (interface "lo")
314 (provision '(loopback)))))
316 (service wpa-supplicant-service-type)
318 (service connman-service-type
319 (connman-configuration
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
326 (service gc-root-service-type
330 (canonical-package guile-2.2))))))
335 \x1b[1;37mThis is an installation image of the GNU system. Welcome.\x1b[0m
337 \x1b[1;33mUse Alt-F2 for documentation.\x1b[0m
340 (define installation-os
341 ;; The operating system used on installation images for USB sticks etc.
344 (timezone "Europe/Paris")
345 (locale "en_US.utf8")
346 (bootloader (bootloader-configuration
347 (bootloader grub-bootloader)
348 (target "/dev/sda")))
350 ;; Note: the disk image build code overrides this root file system with
351 ;; the appropriate one.
354 (device (file-system-label "Guix_image"))
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
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
375 (users (list (user-account
378 (supplementary-groups '("wheel")) ; allow use of sudo
380 (comment "Guest of GNU"))))
383 (services %installation-services)
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")))
390 ;; Explicitly allow for empty passwords.
391 (base-pam-services #:allow-empty-passwords? #t))
393 (packages (cons* (canonical-package glibc) ;for 'tzselect' & co.
394 parted gptfdisk ddrescue
396 font-dejavu font-gnu-unifont
397 grub ;mostly so xrefs to its manual work
400 dosfstools ;mkfs.fat, for the UEFI boot partition
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.
410 nss-certs ; To access HTTPS, use git, etc.
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.
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)))))
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."
433 (inherit installation-os)
434 (bootloader (bootloader-configuration
435 (bootloader bootloader)
436 (target bootloader-target)))
439 (cons (string-append "console=" tty)
440 (operating-system-user-kernel-arguments installation-os)))
441 (initrd-modules (append extra-modules %base-initrd-modules))))
443 (define beaglebone-black-installation-os
444 (embedded-installation-os u-boot-beaglebone-black-bootloader
448 ;; This module is required to mount the sd card.
452 (define a20-olinuxino-lime-installation-os
453 (embedded-installation-os u-boot-a20-olinuxino-lime-bootloader
454 "/dev/mmcblk0" ; SD card storage
457 (define a20-olinuxino-lime2-emmc-installation-os
458 (embedded-installation-os u-boot-a20-olinuxino-lime2-bootloader
459 "/dev/mmcblk1" ; eMMC storage
462 (define a20-olinuxino-micro-installation-os
463 (embedded-installation-os u-boot-a20-olinuxino-micro-bootloader
464 "/dev/mmcblk0" ; SD card storage
467 (define bananapi-m2-ultra-installation-os
468 (embedded-installation-os u-boot-bananapi-m2-ultra-bootloader
469 "/dev/mmcblk1" ; eMMC storage
472 (define mx6cuboxi-installation-os
473 (embedded-installation-os u-boot-mx6cuboxi-bootloader
474 "/dev/mmcblk0" ; SD card storage
477 (define novena-installation-os
478 (embedded-installation-os u-boot-novena-bootloader
479 "/dev/mmcblk1" ; SD card storage
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)
487 (define pine64-plus-installation-os
488 (embedded-installation-os u-boot-pine64-plus-bootloader
489 "/dev/mmcblk0" ; SD card storage
492 (define pinebook-installation-os
493 (embedded-installation-os u-boot-pinebook-bootloader
494 "/dev/mmcblk0" ; SD card storage
497 (define rk3399-puma-installation-os
498 (embedded-installation-os u-boot-puma-rk3399-bootloader
499 "/dev/mmcblk0" ; SD card storage
502 (define wandboard-installation-os
503 (embedded-installation-os u-boot-wandboard-bootloader
504 "/dev/mmcblk0" ; SD card storage
507 ;; Return the default os here so 'guix system' can consume it directly.
510 ;;; install.scm ends here