1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014, 2015, 2016, 2017 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-lime2-emmc-installation-os
48 a20-olinuxino-micro-installation-os
49 banana-pi-m2-ultra-installation-os
50 beaglebone-black-installation-os
51 nintendo-nes-classic-edition-installation-os))
55 ;;; This module provides an 'operating-system' definition for use on images
56 ;;; for USB sticks etc., for the installation of the GNU system.
62 "Return a script that spawns the Info reader on the right section of the
64 (program-file "log-to-info"
66 ;; 'gunzip' is needed to decompress the doc.
67 (setenv "PATH" (string-append #$gzip "/bin"))
69 (execl (string-append #$info-reader "/bin/info") "info"
70 "-d" "/run/current-system/profile/share/info"
71 "-f" (string-append #$guix "/share/info/guix.info")
72 "-n" "System Installation"))))
74 (define %backing-directory
75 ;; Sub-directory used as the backing store for copy-on-write.
78 (define (make-cow-store target)
79 "Return a gexp that makes the store copy-on-write, using TARGET as the
80 backing store. This is useful when TARGET is on a hard disk, whereas the
81 current store is on a RAM disk."
83 (define (set-store-permissions directory)
84 ;; Set the right perms on DIRECTORY to use it as the store.
86 (chown #$directory 0 30000) ;use the fixed 'guixbuild' GID
87 (chmod #$directory #o1775)))
90 ;; Bind-mount TARGET's /tmp in case we need space to build things.
91 (let ((tmpdir (string-append #$target "/tmp")))
93 (mount tmpdir "/tmp" "none" MS_BIND))
95 (let* ((rw-dir (string-append target #$%backing-directory))
96 (work-dir (string-append rw-dir "/../.overlayfs-workdir")))
99 (mkdir-p "/.rw-store")
100 #$(set-store-permissions #~rw-dir)
101 #$(set-store-permissions "/.rw-store")
103 ;; Mount the overlay, then atomically make it the store.
104 (mount "none" "/.rw-store" "overlay" 0
105 (string-append "lowerdir=" #$(%store-prefix) ","
106 "upperdir=" rw-dir ","
107 "workdir=" work-dir))
108 (mount "/.rw-store" #$(%store-prefix) "" MS_MOVE)
109 (rmdir "/.rw-store"))))
111 (define cow-store-service-type
112 (shepherd-service-type
116 (requirement '(root-file-system user-processes))
117 (provision '(cow-store))
119 "Make the store copy-on-write, with writes going to \
122 ;; This is meant to be explicitly started by the user.
125 (start #~(case-lambda
127 #$(make-cow-store #~target)
130 ;; Do nothing, and mark the service as stopped.
132 (stop #~(lambda (target)
133 ;; Delete the temporary directory, but leave everything
134 ;; mounted as there may still be processes using it since
135 ;; 'user-processes' doesn't depend on us. The 'user-unmount'
136 ;; service will unmount TARGET eventually.
137 (delete-file-recursively
138 (string-append target #$%backing-directory))))))))
140 (define (cow-store-service)
141 "Return a service that makes the store copy-on-write, such that writes go to
142 the user's target storage device rather than on the RAM disk."
143 ;; See <http://bugs.gnu.org/18061> for the initial report.
144 (service cow-store-service-type 'mooooh!))
147 (define (/etc/configuration-files _)
148 "Return a list of tuples representing configuration templates to add to
151 (local-file (string-append "examples/" f)))
154 (computed-file "configuration-templates"
155 (with-imported-modules '((guix build utils))
158 (for-each (lambda (file target)
160 (string-append #$output "/"
162 '(#$(file "bare-bones.tmpl")
163 #$(file "beaglebone-black.tmpl")
164 #$(file "desktop.tmpl")
165 #$(file "lightweight-desktop.tmpl"))
167 "beaglebone-black.scm"
169 "lightweight-desktop.scm"))
172 `(("configuration" ,directory)))
174 (define configuration-template-service-type
175 (service-type (name 'configuration-template)
177 (list (service-extension etc-service-type
178 /etc/configuration-files)))))
180 (define %configuration-template-service
181 (service configuration-template-service-type #t))
184 (define %nscd-minimal-caches
185 ;; Minimal in-memory caching policy for nscd.
186 (list (nscd-cache (database 'hosts)
187 (positive-time-to-live (* 3600 12))
189 ;; Do not cache lookup failures at all since they are
190 ;; quite likely (for instance when someone tries to ping a
191 ;; host before networking is functional.)
192 (negative-time-to-live 0)
195 (max-database-size (* 5 (expt 2 20)))))) ;5 MiB
197 (define %installation-services
198 ;; List of services of the installation system.
199 (let ((motd (plain-file "motd" "
200 \x1b[1;37mWelcome to the installation of the Guix System Distribution!\x1b[0m
202 \x1b[2mThere is NO WARRANTY, to the extent permitted by law. In particular, you may
203 LOSE ALL YOUR DATA as a side effect of the installation process. Furthermore,
204 it is 'beta' software, so it may contain bugs.
206 You have been warned. Thanks for being so brave.\x1b[0m
208 (define (normal-tty tty)
209 (mingetty-service (mingetty-configuration (tty tty)
213 (define bare-bones-os
214 (load "examples/bare-bones.tmpl"))
216 (list (mingetty-service (mingetty-configuration
218 (auto-login "root")))
220 (login-service (login-configuration
223 ;; Documentation. The manual is in UTF-8, but
224 ;; 'console-font-service' sets up Unicode support and loads a font
225 ;; with all the useful glyphs like em dash and quotation marks.
226 (mingetty-service (mingetty-configuration
229 (login-program (log-to-info))))
231 ;; Documentation add-on.
232 %configuration-template-service
234 ;; A bunch of 'root' ttys.
240 ;; The usual services.
243 ;; The build daemon. Register the hydra.gnu.org key as trusted.
244 ;; This allows the installation process to use substitutes by
246 (guix-service (guix-configuration (authorize-key? #t)))
248 ;; Start udev so that useful device nodes are available.
249 ;; Use device-mapper rules for cryptsetup & co; enable the CRDA for
250 ;; regulations-compliant WiFi access.
251 (udev-service #:rules (list lvm2 crda))
253 ;; Add the 'cow-store' service, which users have to start manually
254 ;; since it takes the installation directory as an argument.
257 ;; Install Unicode support and a suitable font. Use a font that
258 ;; doesn't have more than 256 glyphs so that we can use colors with
259 ;; varying brightness levels (see note in setfont(8)).
260 (service console-font-service-type
262 (cons tty "lat9u-16"))
263 '("tty1" "tty2" "tty3" "tty4" "tty5" "tty6")))
265 ;; To facilitate copy/paste.
268 ;; Add an SSH server to facilitate remote installs.
269 (service openssh-service-type
270 (openssh-configuration
272 (permit-root-login #t)
273 ;; The root account is passwordless, so make sure
274 ;; a password is set before allowing logins.
275 (allow-empty-passwords? #f)
276 (password-authentication? #t)
278 ;; Don't start it upfront.
281 ;; Since this is running on a USB stick with a overlayfs as the root
282 ;; file system, use an appropriate cache configuration.
283 (nscd-service (nscd-configuration
284 (caches %nscd-minimal-caches)))
286 ;; Having /bin/sh is a good idea. In particular it allows Tramp
287 ;; connections to this system to work.
288 (service special-files-service-type
289 `(("/bin/sh" ,(file-append (canonical-package bash)
292 ;; Keep a reference to BARE-BONES-OS to make sure it can be
293 ;; installed without downloading/building anything. Also keep the
294 ;; things needed by 'profile-derivation' to minimize the amount of
296 (service gc-root-service-type
300 (canonical-package guile-2.2))))))
305 \x1b[1;37mThis is an installation image of the GNU system. Welcome.\x1b[0m
307 \x1b[1;33mUse Alt-F2 for documentation.\x1b[0m
310 (define installation-os
311 ;; The operating system used on installation images for USB sticks etc.
314 (timezone "Europe/Paris")
315 (locale "en_US.utf8")
316 (bootloader (bootloader-configuration
317 (bootloader grub-bootloader)
318 (target "/dev/sda")))
320 ;; Note: the disk image build code overrides this root file system with
321 ;; the appropriate one.
324 (device "GuixSD_image")
328 ;; Make /tmp a tmpfs instead of keeping the overlayfs. This
329 ;; originally was used for unionfs because FUSE creates
330 ;; '.fuse_hiddenXYZ' files for each open file, and this confuses
331 ;; Guix's test suite, for instance (see
332 ;; <http://bugs.gnu.org/23056>). We keep this for overlayfs to be
341 ;; XXX: This should be %BASE-FILE-SYSTEMS but we don't need
342 ;; elogind's cgroup file systems.
343 (list %pseudo-terminal-file-system
344 %shared-memory-file-system
347 (users (list (user-account
350 (supplementary-groups '("wheel")) ; allow use of sudo
352 (comment "Guest of GNU")
353 (home-directory "/home/guest"))))
356 (services %installation-services)
358 ;; We don't need setuid programs, except for 'passwd', which can be handy
359 ;; if one is to allow remote SSH login to the machine being installed.
360 (setuid-programs (list (file-append shadow "/bin/passwd")))
363 ;; Explicitly allow for empty passwords.
364 (base-pam-services #:allow-empty-passwords? #t))
366 (packages (cons* (canonical-package glibc) ;for 'tzselect' & co.
367 parted gptfdisk ddrescue
368 grub ;mostly so xrefs to its manual work
371 dosfstools ;mkfs.fat, for the UEFI boot partition
373 openssh ;we already have sshd, having ssh/scp can help
374 wireless-tools iw wpa-supplicant-minimal iproute
375 ;; XXX: We used to have GNU fdisk here, but as of version
376 ;; 2.0.0a, that pulls Guile 1.8, which takes unreasonable
377 ;; space; furthermore util-linux's fdisk is already
378 ;; available here, so we keep that.
383 (define* (agetty-default-service #:optional (tty "ttyS0"))
384 "Return an agetty-service on the given TTY"
385 (agetty-service (agetty-configuration
386 (extra-options '("-L"))
391 (define* (embedded-installation-os bootloader bootloader-target tty
392 #:key (extra-modules '()))
393 "Return an installation os for embedded systems.
394 The initrd gets the extra modules EXTRA-MODULES.
395 A getty is provided on TTY.
396 The bootloader BOOTLOADER is installed to BOOTLOADER-TARGET."
398 (inherit installation-os)
399 (bootloader (bootloader-configuration
400 (bootloader bootloader)
401 (target bootloader-target)))
403 (initrd (lambda (fs . rest)
404 (apply base-initrd fs
405 #:extra-modules extra-modules
407 (services (cons* (agetty-default-service tty)
408 (operating-system-user-services installation-os)))))
410 (define beaglebone-black-installation-os
411 (embedded-installation-os u-boot-beaglebone-black-bootloader
415 ;; This module is required to mount the sd card.
419 (define a20-olinuxino-lime2-emmc-installation-os
420 (embedded-installation-os u-boot-a20-olinuxino-lime2-bootloader
421 "/dev/mmcblk1" ; eMMC storage
424 (define a20-olinuxino-micro-installation-os
425 (embedded-installation-os u-boot-a20-olinuxino-micro-bootloader
426 "/dev/mmcblk0" ; SD card storage
429 (define banana-pi-m2-ultra-installation-os
430 (embedded-installation-os u-boot-banana-pi-m2-ultra-bootloader
431 "/dev/mmcblk1" ; eMMC storage
434 (define nintendo-nes-classic-edition-installation-os
435 (embedded-installation-os u-boot-nintendo-nes-classic-edition-bootloader
436 "/dev/mmcblk0" ; SD card (solder it yourself)
439 ;; Return the default os here so 'guix system' can consume it directly.
442 ;;; install.scm ends here