1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014, 2015, 2016, 2017, 2018 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 bootloader u-boot)
26 #:use-module (guix gexp)
27 #:use-module (guix store)
28 #:use-module (guix monads)
29 #:use-module ((guix store) #:select (%store-prefix))
30 #:use-module (gnu services shepherd)
31 #:use-module (gnu services ssh)
32 #:use-module (gnu packages admin)
33 #:use-module (gnu packages bash)
34 #:use-module (gnu packages bootloaders)
35 #:use-module (gnu packages guile)
36 #:use-module (gnu packages linux)
37 #:use-module (gnu packages ssh)
38 #:use-module (gnu packages cryptsetup)
39 #:use-module (gnu packages package-management)
40 #:use-module (gnu packages disk)
41 #:use-module (gnu packages texinfo)
42 #:use-module (gnu packages compression)
43 #:use-module (gnu packages nvi)
44 #:use-module (ice-9 match)
45 #:use-module (srfi srfi-26)
46 #:export (installation-os
47 a20-olinuxino-lime-installation-os
48 a20-olinuxino-lime2-emmc-installation-os
49 a20-olinuxino-micro-installation-os
50 bananapi-m2-ultra-installation-os
51 beaglebone-black-installation-os
52 mx6cuboxi-installation-os
53 nintendo-nes-classic-edition-installation-os
54 novena-installation-os
55 pine64-plus-installation-os
56 pinebook-installation-os
57 rk3399-puma-installation-os
58 wandboard-installation-os
63 ;;; This module provides an 'operating-system' definition for use on images
64 ;;; for USB sticks etc., for the installation of the GNU system.
70 "Return a script that spawns the Info reader on the right section of the
72 (program-file "log-to-info"
74 ;; 'gunzip' is needed to decompress the doc.
75 (setenv "PATH" (string-append #$gzip "/bin"))
77 (execl (string-append #$info-reader "/bin/info") "info"
78 "-d" "/run/current-system/profile/share/info"
79 "-f" (string-append #$guix "/share/info/guix.info")
80 "-n" "System Installation"))))
82 (define %backing-directory
83 ;; Sub-directory used as the backing store for copy-on-write.
86 (define (make-cow-store target)
87 "Return a gexp that makes the store copy-on-write, using TARGET as the
88 backing store. This is useful when TARGET is on a hard disk, whereas the
89 current store is on a RAM disk."
91 (define (set-store-permissions directory)
92 ;; Set the right perms on DIRECTORY to use it as the store.
94 (chown #$directory 0 30000) ;use the fixed 'guixbuild' GID
95 (chmod #$directory #o1775)))
98 ;; Bind-mount TARGET's /tmp in case we need space to build things.
99 (let ((tmpdir (string-append #$target "/tmp")))
101 (mount tmpdir "/tmp" "none" MS_BIND))
103 (let* ((rw-dir (string-append target #$%backing-directory))
104 (work-dir (string-append rw-dir "/../.overlayfs-workdir")))
107 (mkdir-p "/.rw-store")
108 #$(set-store-permissions #~rw-dir)
109 #$(set-store-permissions "/.rw-store")
111 ;; Mount the overlay, then atomically make it the store.
112 (mount "none" "/.rw-store" "overlay" 0
113 (string-append "lowerdir=" #$(%store-prefix) ","
114 "upperdir=" rw-dir ","
115 "workdir=" work-dir))
116 (mount "/.rw-store" #$(%store-prefix) "" MS_MOVE)
117 (rmdir "/.rw-store"))))
119 (define cow-store-service-type
120 (shepherd-service-type
124 (requirement '(root-file-system user-processes))
125 (provision '(cow-store))
127 "Make the store copy-on-write, with writes going to \
130 ;; This is meant to be explicitly started by the user.
133 (start #~(case-lambda
135 #$(make-cow-store #~target)
138 ;; Do nothing, and mark the service as stopped.
140 (stop #~(lambda (target)
141 ;; Delete the temporary directory, but leave everything
142 ;; mounted as there may still be processes using it since
143 ;; 'user-processes' doesn't depend on us. The 'user-file-systems'
144 ;; service will unmount TARGET eventually.
145 (delete-file-recursively
146 (string-append target #$%backing-directory))))))))
148 (define (cow-store-service)
149 "Return a service that makes the store copy-on-write, such that writes go to
150 the user's target storage device rather than on the RAM disk."
151 ;; See <http://bugs.gnu.org/18061> for the initial report.
152 (service cow-store-service-type 'mooooh!))
155 (define (/etc/configuration-files _)
156 "Return a list of tuples representing configuration templates to add to
159 (local-file (string-append "examples/" f)))
162 (computed-file "configuration-templates"
163 (with-imported-modules '((guix build utils))
166 (for-each (lambda (file target)
168 (string-append #$output "/"
170 '(#$(file "bare-bones.tmpl")
171 #$(file "beaglebone-black.tmpl")
172 #$(file "desktop.tmpl")
173 #$(file "lightweight-desktop.tmpl"))
175 "beaglebone-black.scm"
177 "lightweight-desktop.scm"))
180 `(("configuration" ,directory)))
182 (define configuration-template-service-type
183 (service-type (name 'configuration-template)
185 (list (service-extension etc-service-type
186 /etc/configuration-files)))))
188 (define %configuration-template-service
189 (service configuration-template-service-type #t))
192 (define %nscd-minimal-caches
193 ;; Minimal in-memory caching policy for nscd.
194 (list (nscd-cache (database 'hosts)
195 (positive-time-to-live (* 3600 12))
197 ;; Do not cache lookup failures at all since they are
198 ;; quite likely (for instance when someone tries to ping a
199 ;; host before networking is functional.)
200 (negative-time-to-live 0)
203 (max-database-size (* 5 (expt 2 20)))))) ;5 MiB
205 (define %installation-services
206 ;; List of services of the installation system.
207 (let ((motd (plain-file "motd" "
208 \x1b[1;37mWelcome to the installation of the Guix System Distribution!\x1b[0m
210 \x1b[2mThere is NO WARRANTY, to the extent permitted by law. In particular, you may
211 LOSE ALL YOUR DATA as a side effect of the installation process. Furthermore,
212 it is 'beta' software, so it may contain bugs.
214 You have been warned. Thanks for being so brave.\x1b[0m
216 (define (normal-tty tty)
217 (mingetty-service (mingetty-configuration (tty tty)
221 (define bare-bones-os
222 (load "examples/bare-bones.tmpl"))
224 (list (service virtual-terminal-service-type)
226 (mingetty-service (mingetty-configuration
228 (auto-login "root")))
230 (login-service (login-configuration
233 ;; Documentation. The manual is in UTF-8, but
234 ;; 'console-font-service' sets up Unicode support and loads a font
235 ;; with all the useful glyphs like em dash and quotation marks.
236 (mingetty-service (mingetty-configuration
239 (login-program (log-to-info))))
241 ;; Documentation add-on.
242 %configuration-template-service
244 ;; A bunch of 'root' ttys.
250 ;; The usual services.
253 ;; The build daemon. Register the official server keys as trusted.
254 ;; This allows the installation process to use substitutes by
256 (guix-service (guix-configuration (authorize-key? #t)))
258 ;; Start udev so that useful device nodes are available.
259 ;; Use device-mapper rules for cryptsetup & co; enable the CRDA for
260 ;; regulations-compliant WiFi access.
261 (udev-service #:rules (list lvm2 crda))
263 ;; Add the 'cow-store' service, which users have to start manually
264 ;; since it takes the installation directory as an argument.
267 ;; Install Unicode support and a suitable font. Use a font that
268 ;; doesn't have more than 256 glyphs so that we can use colors with
269 ;; varying brightness levels (see note in setfont(8)).
270 (service console-font-service-type
272 (cons tty "lat9u-16"))
273 '("tty1" "tty2" "tty3" "tty4" "tty5" "tty6")))
275 ;; To facilitate copy/paste.
278 ;; Add an SSH server to facilitate remote installs.
279 (service openssh-service-type
280 (openssh-configuration
282 (permit-root-login #t)
283 ;; The root account is passwordless, so make sure
284 ;; a password is set before allowing logins.
285 (allow-empty-passwords? #f)
286 (password-authentication? #t)
288 ;; Don't start it upfront.
291 ;; Since this is running on a USB stick with a overlayfs as the root
292 ;; file system, use an appropriate cache configuration.
293 (nscd-service (nscd-configuration
294 (caches %nscd-minimal-caches)))
296 ;; Having /bin/sh is a good idea. In particular it allows Tramp
297 ;; connections to this system to work.
298 (service special-files-service-type
299 `(("/bin/sh" ,(file-append (canonical-package bash)
302 ;; Loopback device, needed by OpenSSH notably.
303 (service static-networking-service-type
304 (list (static-networking (interface "lo")
307 (provision '(loopback)))))
309 ;; Keep a reference to BARE-BONES-OS to make sure it can be
310 ;; installed without downloading/building anything. Also keep the
311 ;; things needed by 'profile-derivation' to minimize the amount of
313 (service gc-root-service-type
317 (canonical-package guile-2.2))))))
322 \x1b[1;37mThis is an installation image of the GNU system. Welcome.\x1b[0m
324 \x1b[1;33mUse Alt-F2 for documentation.\x1b[0m
327 (define installation-os
328 ;; The operating system used on installation images for USB sticks etc.
331 (timezone "Europe/Paris")
332 (locale "en_US.utf8")
333 (bootloader (bootloader-configuration
334 (bootloader grub-bootloader)
335 (target "/dev/sda")))
337 ;; Note: the disk image build code overrides this root file system with
338 ;; the appropriate one.
341 (device (file-system-label "GuixSD_image"))
344 ;; Make /tmp a tmpfs instead of keeping the overlayfs. This
345 ;; originally was used for unionfs because FUSE creates
346 ;; '.fuse_hiddenXYZ' files for each open file, and this confuses
347 ;; Guix's test suite, for instance (see
348 ;; <http://bugs.gnu.org/23056>). We keep this for overlayfs to be
356 ;; XXX: This should be %BASE-FILE-SYSTEMS but we don't need
357 ;; elogind's cgroup file systems.
358 (list %pseudo-terminal-file-system
359 %shared-memory-file-system
362 (users (list (user-account
365 (supplementary-groups '("wheel")) ; allow use of sudo
367 (comment "Guest of GNU")
368 (home-directory "/home/guest"))))
371 (services %installation-services)
373 ;; We don't need setuid programs, except for 'passwd', which can be handy
374 ;; if one is to allow remote SSH login to the machine being installed.
375 (setuid-programs (list (file-append shadow "/bin/passwd")))
378 ;; Explicitly allow for empty passwords.
379 (base-pam-services #:allow-empty-passwords? #t))
381 (packages (cons* (canonical-package glibc) ;for 'tzselect' & co.
382 parted gptfdisk ddrescue
383 grub ;mostly so xrefs to its manual work
386 dosfstools ;mkfs.fat, for the UEFI boot partition
388 openssh ;we already have sshd, having ssh/scp can help
389 wireless-tools iw wpa-supplicant-minimal iproute
390 ;; XXX: We used to have GNU fdisk here, but as of version
391 ;; 2.0.0a, that pulls Guile 1.8, which takes unreasonable
392 ;; space; furthermore util-linux's fdisk is already
393 ;; available here, so we keep that.
398 (define* (os-with-u-boot os board #:key (bootloader-target "/dev/mmcblk0")
399 (triplet "arm-linux-gnueabihf"))
400 "Given OS, amend it with the u-boot bootloader for BOARD,
401 installed to BOOTLOADER-TARGET (a drive), compiled for TRIPLET.
403 If you want a serial console, make sure to specify one in your
404 operating-system's kernel-arguments (\"console=ttyS0\" or similar)."
405 (operating-system (inherit os)
406 (bootloader (bootloader-configuration
407 (bootloader (bootloader (inherit u-boot-bootloader)
408 (package (make-u-boot-package board triplet))))
409 (target bootloader-target)))))
411 (define* (embedded-installation-os bootloader bootloader-target tty
412 #:key (extra-modules '()))
413 "Return an installation os for embedded systems.
414 The initrd gets the extra modules EXTRA-MODULES.
415 A getty is provided on TTY.
416 The bootloader BOOTLOADER is installed to BOOTLOADER-TARGET."
418 (inherit installation-os)
419 (bootloader (bootloader-configuration
420 (bootloader bootloader)
421 (target bootloader-target)))
424 (cons (string-append "console=" tty)
425 (operating-system-user-kernel-arguments installation-os)))
426 (initrd-modules (append extra-modules %base-initrd-modules))))
428 (define beaglebone-black-installation-os
429 (embedded-installation-os u-boot-beaglebone-black-bootloader
433 ;; This module is required to mount the sd card.
437 (define a20-olinuxino-lime-installation-os
438 (embedded-installation-os u-boot-a20-olinuxino-lime-bootloader
439 "/dev/mmcblk0" ; SD card storage
442 (define a20-olinuxino-lime2-emmc-installation-os
443 (embedded-installation-os u-boot-a20-olinuxino-lime2-bootloader
444 "/dev/mmcblk1" ; eMMC storage
447 (define a20-olinuxino-micro-installation-os
448 (embedded-installation-os u-boot-a20-olinuxino-micro-bootloader
449 "/dev/mmcblk0" ; SD card storage
452 (define bananapi-m2-ultra-installation-os
453 (embedded-installation-os u-boot-bananapi-m2-ultra-bootloader
454 "/dev/mmcblk1" ; eMMC storage
457 (define mx6cuboxi-installation-os
458 (embedded-installation-os u-boot-mx6cuboxi-bootloader
459 "/dev/mmcblk0" ; SD card storage
462 (define novena-installation-os
463 (embedded-installation-os u-boot-novena-bootloader
464 "/dev/mmcblk1" ; SD card storage
467 (define nintendo-nes-classic-edition-installation-os
468 (embedded-installation-os u-boot-nintendo-nes-classic-edition-bootloader
469 "/dev/mmcblk0" ; SD card (solder it yourself)
472 (define pine64-plus-installation-os
473 (embedded-installation-os u-boot-pine64-plus-bootloader
474 "/dev/mmcblk0" ; SD card storage
477 (define pinebook-installation-os
478 (embedded-installation-os u-boot-pinebook-bootloader
479 "/dev/mmcblk0" ; SD card storage
482 (define rk3399-puma-installation-os
483 (embedded-installation-os u-boot-puma-rk3399-bootloader
484 "/dev/mmcblk0" ; SD card storage
487 (define wandboard-installation-os
488 (embedded-installation-os u-boot-wandboard-bootloader
489 "/dev/mmcblk0" ; SD card storage
492 ;; Return the default os here so 'guix system' can consume it directly.
495 ;;; install.scm ends here