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 (guix gexp)
26 #:use-module (guix store)
27 #:use-module (guix monads)
28 #:use-module ((guix store) #:select (%store-prefix))
29 #:use-module (gnu services shepherd)
30 #:use-module (gnu services ssh)
31 #:use-module (gnu packages admin)
32 #:use-module (gnu packages bash)
33 #:use-module (gnu packages bootloaders)
34 #:use-module (gnu packages guile)
35 #:use-module (gnu packages linux)
36 #:use-module (gnu packages ssh)
37 #:use-module (gnu packages cryptsetup)
38 #:use-module (gnu packages package-management)
39 #:use-module (gnu packages disk)
40 #:use-module (gnu packages texinfo)
41 #:use-module (gnu packages compression)
42 #:use-module (gnu packages nvi)
43 #:use-module (ice-9 match)
44 #:use-module (srfi srfi-26)
45 #:export (installation-os))
49 ;;; This module provides an 'operating-system' definition for use on images
50 ;;; for USB sticks etc., for the installation of the GNU system.
56 "Return a script that spawns the Info reader on the right section of the
58 (program-file "log-to-info"
60 ;; 'gunzip' is needed to decompress the doc.
61 (setenv "PATH" (string-append #$gzip "/bin"))
63 (execl (string-append #$info-reader "/bin/info") "info"
64 "-d" "/run/current-system/profile/share/info"
65 "-f" (string-append #$guix "/share/info/guix.info")
66 "-n" "System Installation"))))
68 (define %backing-directory
69 ;; Sub-directory used as the backing store for copy-on-write.
72 (define (make-cow-store target)
73 "Return a gexp that makes the store copy-on-write, using TARGET as the
74 backing store. This is useful when TARGET is on a hard disk, whereas the
75 current store is on a RAM disk."
77 (define (set-store-permissions directory)
78 ;; Set the right perms on DIRECTORY to use it as the store.
80 (chown #$directory 0 30000) ;use the fixed 'guixbuild' GID
81 (chmod #$directory #o1775)))
84 ;; Bind-mount TARGET's /tmp in case we need space to build things.
85 (let ((tmpdir (string-append #$target "/tmp")))
87 (mount tmpdir "/tmp" "none" MS_BIND))
89 (let* ((rw-dir (string-append target #$%backing-directory))
90 (work-dir (string-append rw-dir "/../.overlayfs-workdir")))
93 (mkdir-p "/.rw-store")
94 #$(set-store-permissions #~rw-dir)
95 #$(set-store-permissions "/.rw-store")
97 ;; Mount the overlay, then atomically make it the store.
98 (mount "none" "/.rw-store" "overlay" 0
99 (string-append "lowerdir=" #$(%store-prefix) ","
100 "upperdir=" rw-dir ","
101 "workdir=" work-dir))
102 (mount "/.rw-store" #$(%store-prefix) "" MS_MOVE)
103 (rmdir "/.rw-store"))))
105 (define cow-store-service-type
106 (shepherd-service-type
110 (requirement '(root-file-system user-processes))
111 (provision '(cow-store))
113 "Make the store copy-on-write, with writes going to \
116 ;; This is meant to be explicitly started by the user.
119 (start #~(case-lambda
121 #$(make-cow-store #~target)
124 ;; Do nothing, and mark the service as stopped.
126 (stop #~(lambda (target)
127 ;; Delete the temporary directory, but leave everything
128 ;; mounted as there may still be processes using it since
129 ;; 'user-processes' doesn't depend on us. The 'user-unmount'
130 ;; service will unmount TARGET eventually.
131 (delete-file-recursively
132 (string-append target #$%backing-directory))))))))
134 (define (cow-store-service)
135 "Return a service that makes the store copy-on-write, such that writes go to
136 the user's target storage device rather than on the RAM disk."
137 ;; See <http://bugs.gnu.org/18061> for the initial report.
138 (service cow-store-service-type 'mooooh!))
141 (define (/etc/configuration-files _)
142 "Return a list of tuples representing configuration templates to add to
145 (local-file (string-append "examples/" f)))
148 (computed-file "configuration-templates"
149 (with-imported-modules '((guix build utils))
152 (for-each (lambda (file target)
154 (string-append #$output "/"
156 '(#$(file "bare-bones.tmpl")
157 #$(file "desktop.tmpl")
158 #$(file "lightweight-desktop.tmpl"))
161 "lightweight-desktop.scm"))
164 `(("configuration" ,directory)))
166 (define configuration-template-service-type
167 (service-type (name 'configuration-template)
169 (list (service-extension etc-service-type
170 /etc/configuration-files)))))
172 (define %configuration-template-service
173 (service configuration-template-service-type #t))
176 (define %nscd-minimal-caches
177 ;; Minimal in-memory caching policy for nscd.
178 (list (nscd-cache (database 'hosts)
179 (positive-time-to-live (* 3600 12))
181 ;; Do not cache lookup failures at all since they are
182 ;; quite likely (for instance when someone tries to ping a
183 ;; host before networking is functional.)
184 (negative-time-to-live 0)
187 (max-database-size (* 5 (expt 2 20)))))) ;5 MiB
189 (define %installation-services
190 ;; List of services of the installation system.
191 (let ((motd (plain-file "motd" "
192 \x1b[1;37mWelcome to the installation of the Guix System Distribution!\x1b[0m
194 \x1b[2mThere is NO WARRANTY, to the extent permitted by law. In particular, you may
195 LOSE ALL YOUR DATA as a side effect of the installation process. Furthermore,
196 it is 'beta' software, so it may contain bugs.
198 You have been warned. Thanks for being so brave.\x1b[0m
200 (define (normal-tty tty)
201 (mingetty-service (mingetty-configuration (tty tty)
205 (define bare-bones-os
206 (load "examples/bare-bones.tmpl"))
208 (list (mingetty-service (mingetty-configuration
210 (auto-login "root")))
212 (login-service (login-configuration
215 ;; Documentation. The manual is in UTF-8, but
216 ;; 'console-font-service' sets up Unicode support and loads a font
217 ;; with all the useful glyphs like em dash and quotation marks.
218 (mingetty-service (mingetty-configuration
221 (login-program (log-to-info))))
223 ;; Documentation add-on.
224 %configuration-template-service
226 ;; A bunch of 'root' ttys.
232 ;; The usual services.
235 ;; The build daemon. Register the hydra.gnu.org key as trusted.
236 ;; This allows the installation process to use substitutes by
238 (guix-service (guix-configuration (authorize-key? #t)))
240 ;; Start udev so that useful device nodes are available.
241 ;; Use device-mapper rules for cryptsetup & co; enable the CRDA for
242 ;; regulations-compliant WiFi access.
243 (udev-service #:rules (list lvm2 crda))
245 ;; Add the 'cow-store' service, which users have to start manually
246 ;; since it takes the installation directory as an argument.
249 ;; Install Unicode support and a suitable font. Use a font that
250 ;; doesn't have more than 256 glyphs so that we can use colors with
251 ;; varying brightness levels (see note in setfont(8)).
252 (service console-font-service-type
254 (cons tty "lat9u-16"))
255 '("tty1" "tty2" "tty3" "tty4" "tty5" "tty6")))
257 ;; To facilitate copy/paste.
260 ;; Add an SSH server to facilitate remote installs.
261 (service openssh-service-type
262 (openssh-configuration
264 (permit-root-login #t)
265 ;; The root account is passwordless, so make sure
266 ;; a password is set before allowing logins.
267 (allow-empty-passwords? #f)
268 (password-authentication? #t)
270 ;; Don't start it upfront.
273 ;; Since this is running on a USB stick with a overlayfs as the root
274 ;; file system, use an appropriate cache configuration.
275 (nscd-service (nscd-configuration
276 (caches %nscd-minimal-caches)))
278 ;; Having /bin/sh is a good idea. In particular it allows Tramp
279 ;; connections to this system to work.
280 (service special-files-service-type
281 `(("/bin/sh" ,(file-append (canonical-package bash)
284 ;; Keep a reference to BARE-BONES-OS to make sure it can be
285 ;; installed without downloading/building anything. Also keep the
286 ;; things needed by 'profile-derivation' to minimize the amount of
288 (service gc-root-service-type
292 (canonical-package guile-2.2))))))
297 \x1b[1;37mThis is an installation image of the GNU system. Welcome.\x1b[0m
299 \x1b[1;33mUse Alt-F2 for documentation.\x1b[0m
302 (define installation-os
303 ;; The operating system used on installation images for USB sticks etc.
306 (timezone "Europe/Paris")
307 (locale "en_US.utf8")
308 (bootloader (bootloader-configuration
309 (bootloader grub-bootloader)
310 (target "/dev/sda")))
312 ;; Note: the disk image build code overrides this root file system with
313 ;; the appropriate one.
316 (device "GuixSD_image")
320 ;; Make /tmp a tmpfs instead of keeping the overlayfs. This
321 ;; originally was used for unionfs because FUSE creates
322 ;; '.fuse_hiddenXYZ' files for each open file, and this confuses
323 ;; Guix's test suite, for instance (see
324 ;; <http://bugs.gnu.org/23056>). We keep this for overlayfs to be
333 ;; XXX: This should be %BASE-FILE-SYSTEMS but we don't need
334 ;; elogind's cgroup file systems.
335 (list %pseudo-terminal-file-system
336 %shared-memory-file-system
339 (users (list (user-account
342 (supplementary-groups '("wheel")) ; allow use of sudo
344 (comment "Guest of GNU")
345 (home-directory "/home/guest"))))
348 (services %installation-services)
350 ;; We don't need setuid programs, except for 'passwd', which can be handy
351 ;; if one is to allow remote SSH login to the machine being installed.
352 (setuid-programs (list (file-append shadow "/bin/passwd")))
355 ;; Explicitly allow for empty passwords.
356 (base-pam-services #:allow-empty-passwords? #t))
358 (packages (cons* (canonical-package glibc) ;for 'tzselect' & co.
359 parted gptfdisk ddrescue
360 grub ;mostly so xrefs to its manual work
363 dosfstools ;mkfs.fat, for the UEFI boot partition
365 openssh ;we already have sshd, having ssh/scp can help
366 wireless-tools iw wpa-supplicant-minimal iproute
367 ;; XXX: We used to have GNU fdisk here, but as of version
368 ;; 2.0.0a, that pulls Guile 1.8, which takes unreasonable
369 ;; space; furthermore util-linux's fdisk is already
370 ;; available here, so we keep that.
375 ;; Return it here so 'guix system' can consume it directly.
378 ;;; install.scm ends here