gnu: cuirass: Update to 4ab2f2c.
[jackhill/guix/guix.git] / gnu / system / install.scm
CommitLineData
fc91c17a 1;;; GNU Guix --- Functional package management for GNU
239c2266 2;;; Copyright © 2014, 2015, 2016, 2017 Ludovic Courtès <ludo@gnu.org>
b2a5fa59 3;;; Copyright © 2015 Mark H Weaver <mhw@netris.org>
f0fbf2c1 4;;; Copyright © 2016 Andreas Enge <andreas@enge.fr>
c80cd4df 5;;; Copyright © 2017 Marius Bakke <mbakke@fastmail.com>
fdfdecdb 6;;; Copyright © 2017 Tobias Geerinckx-Rice <me@tobias.gr>
fc91c17a
LC
7;;;
8;;; This file is part of GNU Guix.
9;;;
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.
14;;;
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.
19;;;
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/>.
22
23(define-module (gnu system install)
24 #:use-module (gnu)
ceb39527 25 #:use-module (gnu bootloader u-boot)
fc91c17a 26 #:use-module (guix gexp)
e87f0591 27 #:use-module (guix store)
fc91c17a 28 #:use-module (guix monads)
83a17b62 29 #:use-module ((guix store) #:select (%store-prefix))
0190c1c0 30 #:use-module (gnu services shepherd)
c80cd4df 31 #:use-module (gnu services ssh)
db84467a 32 #:use-module (gnu packages admin)
f4bdfe73 33 #:use-module (gnu packages bash)
862e38d5 34 #:use-module (gnu packages bootloaders)
af4a761e 35 #:use-module (gnu packages guile)
fc91c17a 36 #:use-module (gnu packages linux)
1e8d398a 37 #:use-module (gnu packages ssh)
b419c7f5 38 #:use-module (gnu packages cryptsetup)
fc91c17a 39 #:use-module (gnu packages package-management)
cc4a2aeb 40 #:use-module (gnu packages disk)
fc91c17a 41 #:use-module (gnu packages texinfo)
dd6b28d1 42 #:use-module (gnu packages compression)
a8cb87ab 43 #:use-module (gnu packages nvi)
e1fbc32a
LC
44 #:use-module (ice-9 match)
45 #:use-module (srfi srfi-26)
ceb39527 46 #:export (installation-os
c55c6985 47 a20-olinuxino-lime-installation-os
4b9e9abb 48 a20-olinuxino-lime2-emmc-installation-os
a7bb327e 49 a20-olinuxino-micro-installation-os
30aeb846 50 banana-pi-m2-ultra-installation-os
84ee3378
DM
51 beaglebone-black-installation-os
52 nintendo-nes-classic-edition-installation-os))
fc91c17a
LC
53
54;;; Commentary:
55;;;
56;;; This module provides an 'operating-system' definition for use on images
57;;; for USB sticks etc., for the installation of the GNU system.
58;;;
59;;; Code:
60
9d3fb6c7 61\f
fc91c17a
LC
62(define (log-to-info)
63 "Return a script that spawns the Info reader on the right section of the
64manual."
ce8a6dfc 65 (program-file "log-to-info"
dd6b28d1
LC
66 #~(begin
67 ;; 'gunzip' is needed to decompress the doc.
68 (setenv "PATH" (string-append #$gzip "/bin"))
69
68abb9b0 70 (execl (string-append #$info-reader "/bin/info") "info"
dd6b28d1
LC
71 "-d" "/run/current-system/profile/share/info"
72 "-f" (string-append #$guix "/share/info/guix.info")
73 "-n" "System Installation"))))
fc91c17a 74
83a17b62
LC
75(define %backing-directory
76 ;; Sub-directory used as the backing store for copy-on-write.
77 "/tmp/guix-inst")
78
79(define (make-cow-store target)
80 "Return a gexp that makes the store copy-on-write, using TARGET as the
81backing store. This is useful when TARGET is on a hard disk, whereas the
82current store is on a RAM disk."
83a17b62
LC
83
84 (define (set-store-permissions directory)
85 ;; Set the right perms on DIRECTORY to use it as the store.
86 #~(begin
87 (chown #$directory 0 30000) ;use the fixed 'guixbuild' GID
88 (chmod #$directory #o1775)))
89
90 #~(begin
0adabad7
LC
91 ;; Bind-mount TARGET's /tmp in case we need space to build things.
92 (let ((tmpdir (string-append #$target "/tmp")))
93 (mkdir-p tmpdir)
94 (mount tmpdir "/tmp" "none" MS_BIND))
95
d9565f7d
HG
96 (let* ((rw-dir (string-append target #$%backing-directory))
97 (work-dir (string-append rw-dir "/../.overlayfs-workdir")))
83a17b62 98 (mkdir-p rw-dir)
d9565f7d 99 (mkdir-p work-dir)
83a17b62
LC
100 (mkdir-p "/.rw-store")
101 #$(set-store-permissions #~rw-dir)
102 #$(set-store-permissions "/.rw-store")
103
d9565f7d
HG
104 ;; Mount the overlay, then atomically make it the store.
105 (mount "none" "/.rw-store" "overlay" 0
106 (string-append "lowerdir=" #$(%store-prefix) ","
107 "upperdir=" rw-dir ","
108 "workdir=" work-dir))
109 (mount "/.rw-store" #$(%store-prefix) "" MS_MOVE)
110 (rmdir "/.rw-store"))))
83a17b62 111
0adfe95a 112(define cow-store-service-type
d4053c71 113 (shepherd-service-type
00184239 114 'cow-store
0adfe95a 115 (lambda _
d4053c71 116 (shepherd-service
0adfe95a
LC
117 (requirement '(root-file-system user-processes))
118 (provision '(cow-store))
119 (documentation
120 "Make the store copy-on-write, with writes going to \
121the given target.")
122
123 ;; This is meant to be explicitly started by the user.
124 (auto-start? #f)
125
126 (start #~(case-lambda
127 ((target)
128 #$(make-cow-store #~target)
129 target)
130 (else
131 ;; Do nothing, and mark the service as stopped.
132 #f)))
133 (stop #~(lambda (target)
134 ;; Delete the temporary directory, but leave everything
135 ;; mounted as there may still be processes using it since
136 ;; 'user-processes' doesn't depend on us. The 'user-unmount'
137 ;; service will unmount TARGET eventually.
138 (delete-file-recursively
139 (string-append target #$%backing-directory))))))))
140
83a17b62
LC
141(define (cow-store-service)
142 "Return a service that makes the store copy-on-write, such that writes go to
143the user's target storage device rather than on the RAM disk."
144 ;; See <http://bugs.gnu.org/18061> for the initial report.
0adfe95a
LC
145 (service cow-store-service-type 'mooooh!))
146
147
148(define (/etc/configuration-files _)
149 "Return a list of tuples representing configuration templates to add to
150/etc."
151 (define (file f)
bae90dc7 152 (local-file (string-append "examples/" f)))
0adfe95a
LC
153
154 (define directory
155 (computed-file "configuration-templates"
4ee96a79
LC
156 (with-imported-modules '((guix build utils))
157 #~(begin
158 (mkdir #$output)
159 (for-each (lambda (file target)
160 (copy-file file
161 (string-append #$output "/"
162 target)))
163 '(#$(file "bare-bones.tmpl")
9f1e39d1 164 #$(file "beaglebone-black.tmpl")
4ee96a79
LC
165 #$(file "desktop.tmpl")
166 #$(file "lightweight-desktop.tmpl"))
167 '("bare-bones.scm"
9f1e39d1 168 "beaglebone-black.scm"
4ee96a79
LC
169 "desktop.scm"
170 "lightweight-desktop.scm"))
171 #t))))
0adfe95a
LC
172
173 `(("configuration" ,directory)))
174
175(define configuration-template-service-type
176 (service-type (name 'configuration-template)
177 (extensions
178 (list (service-extension etc-service-type
179 /etc/configuration-files)))))
180
181(define %configuration-template-service
182 (service configuration-template-service-type #t))
be1c2c54 183
1dac8566 184
61ff0a3a
LC
185(define %nscd-minimal-caches
186 ;; Minimal in-memory caching policy for nscd.
187 (list (nscd-cache (database 'hosts)
188 (positive-time-to-live (* 3600 12))
c96ba2cf
LC
189
190 ;; Do not cache lookup failures at all since they are
191 ;; quite likely (for instance when someone tries to ping a
192 ;; host before networking is functional.)
193 (negative-time-to-live 0)
194
61ff0a3a
LC
195 (persistent? #f)
196 (max-database-size (* 5 (expt 2 20)))))) ;5 MiB
197
58b21e1e
LC
198(define %installation-services
199 ;; List of services of the installation system.
ce8a6dfc 200 (let ((motd (plain-file "motd" "
8638362f 201\x1b[1;37mWelcome to the installation of the Guix System Distribution!\x1b[0m
fc91c17a 202
8638362f 203\x1b[2mThere is NO WARRANTY, to the extent permitted by law. In particular, you may
fc91c17a 204LOSE ALL YOUR DATA as a side effect of the installation process. Furthermore,
c82c060d 205it is 'beta' software, so it may contain bugs.
fc91c17a 206
8638362f 207You have been warned. Thanks for being so brave.\x1b[0m
fc91c17a
LC
208")))
209 (define (normal-tty tty)
66e4f01c 210 (mingetty-service (mingetty-configuration (tty tty)
66e4f01c
LC
211 (auto-login "root")
212 (login-pause? #t))))
fc91c17a 213
4e854b18
LC
214 (define bare-bones-os
215 (load "examples/bare-bones.tmpl"))
216
66e4f01c
LC
217 (list (mingetty-service (mingetty-configuration
218 (tty "tty1")
66e4f01c 219 (auto-login "root")))
fc91c17a 220
2932ab9c
DC
221 (login-service (login-configuration
222 (motd motd)))
223
62ca0fdf
LC
224 ;; Documentation. The manual is in UTF-8, but
225 ;; 'console-font-service' sets up Unicode support and loads a font
226 ;; with all the useful glyphs like em dash and quotation marks.
66e4f01c
LC
227 (mingetty-service (mingetty-configuration
228 (tty "tty2")
66e4f01c
LC
229 (auto-login "guest")
230 (login-program (log-to-info))))
fc91c17a 231
1dac8566 232 ;; Documentation add-on.
0adfe95a 233 %configuration-template-service
1dac8566 234
fc91c17a
LC
235 ;; A bunch of 'root' ttys.
236 (normal-tty "tty3")
237 (normal-tty "tty4")
238 (normal-tty "tty5")
239 (normal-tty "tty6")
240
241 ;; The usual services.
242 (syslog-service)
2c5c696c
LC
243
244 ;; The build daemon. Register the hydra.gnu.org key as trusted.
245 ;; This allows the installation process to use substitutes by
246 ;; default.
0adfe95a 247 (guix-service (guix-configuration (authorize-key? #t)))
2c5c696c 248
e11390df 249 ;; Start udev so that useful device nodes are available.
68ac258b
LC
250 ;; Use device-mapper rules for cryptsetup & co; enable the CRDA for
251 ;; regulations-compliant WiFi access.
252 (udev-service #:rules (list lvm2 crda))
e11390df 253
83a17b62
LC
254 ;; Add the 'cow-store' service, which users have to start manually
255 ;; since it takes the installation directory as an argument.
256 (cow-store-service)
257
8638362f
LC
258 ;; Install Unicode support and a suitable font. Use a font that
259 ;; doesn't have more than 256 glyphs so that we can use colors with
260 ;; varying brightness levels (see note in setfont(8)).
4a84a487
LC
261 (service console-font-service-type
262 (map (lambda (tty)
8638362f 263 (cons tty "lat9u-16"))
4a84a487 264 '("tty1" "tty2" "tty3" "tty4" "tty5" "tty6")))
62ca0fdf 265
ae7ffa9e
LC
266 ;; To facilitate copy/paste.
267 (gpm-service)
268
c80cd4df
MB
269 ;; Add an SSH server to facilitate remote installs.
270 (service openssh-service-type
271 (openssh-configuration
272 (port-number 22)
273 (permit-root-login #t)
274 ;; The root account is passwordless, so make sure
275 ;; a password is set before allowing logins.
276 (allow-empty-passwords? #f)
aab322d9
LC
277 (password-authentication? #t)
278
279 ;; Don't start it upfront.
280 (%auto-start? #f)))
c80cd4df 281
d9565f7d 282 ;; Since this is running on a USB stick with a overlayfs as the root
61ff0a3a
LC
283 ;; file system, use an appropriate cache configuration.
284 (nscd-service (nscd-configuration
50cb948f
LC
285 (caches %nscd-minimal-caches)))
286
287 ;; Having /bin/sh is a good idea. In particular it allows Tramp
288 ;; connections to this system to work.
289 (service special-files-service-type
290 `(("/bin/sh" ,(file-append (canonical-package bash)
4e854b18
LC
291 "/bin/sh"))))
292
293 ;; Keep a reference to BARE-BONES-OS to make sure it can be
af4a761e
LC
294 ;; installed without downloading/building anything. Also keep the
295 ;; things needed by 'profile-derivation' to minimize the amount of
296 ;; download.
297 (service gc-root-service-type
298 (list bare-bones-os
299 glibc-utf8-locales
300 texinfo
301 (canonical-package guile-2.2))))))
fc91c17a
LC
302
303(define %issue
304 ;; Greeting.
305 "
8638362f 306\x1b[1;37mThis is an installation image of the GNU system. Welcome.\x1b[0m
fc91c17a 307
8638362f 308\x1b[1;33mUse Alt-F2 for documentation.\x1b[0m
fc91c17a
LC
309")
310
311(define installation-os
312 ;; The operating system used on installation images for USB sticks etc.
313 (operating-system
314 (host-name "gnu")
315 (timezone "Europe/Paris")
9cd0dfaa 316 (locale "en_US.utf8")
fdfdecdb
TGR
317 (bootloader (bootloader-configuration
318 (bootloader grub-bootloader)
319 (target "/dev/sda")))
fc91c17a
LC
320 (file-systems
321 ;; Note: the disk image build code overrides this root file system with
322 ;; the appropriate one.
ee03b75d
LC
323 (cons* (file-system
324 (mount-point "/")
0862b954 325 (device "GuixSD_image")
ee03b75d
LC
326 (title 'label)
327 (type "ext4"))
328
d9565f7d
HG
329 ;; Make /tmp a tmpfs instead of keeping the overlayfs. This
330 ;; originally was used for unionfs because FUSE creates
331 ;; '.fuse_hiddenXYZ' files for each open file, and this confuses
332 ;; Guix's test suite, for instance (see
333 ;; <http://bugs.gnu.org/23056>). We keep this for overlayfs to be
795ec760 334 ;; on the safe side.
ee03b75d
LC
335 (file-system
336 (mount-point "/tmp")
337 (device "none")
338 (title 'device)
339 (type "tmpfs")
340 (check? #f))
341
0feefb53
LC
342 ;; XXX: This should be %BASE-FILE-SYSTEMS but we don't need
343 ;; elogind's cgroup file systems.
344 (list %pseudo-terminal-file-system
345 %shared-memory-file-system
346 %immutable-store)))
fc91c17a
LC
347
348 (users (list (user-account
349 (name "guest")
72507e23 350 (group "users")
ee03b75d 351 (supplementary-groups '("wheel")) ; allow use of sudo
fc91c17a
LC
352 (password "")
353 (comment "Guest of GNU")
354 (home-directory "/home/guest"))))
fc91c17a
LC
355
356 (issue %issue)
58b21e1e 357 (services %installation-services)
fc91c17a 358
903ae630
LC
359 ;; We don't need setuid programs, except for 'passwd', which can be handy
360 ;; if one is to allow remote SSH login to the machine being installed.
361 (setuid-programs (list (file-append shadow "/bin/passwd")))
fc91c17a
LC
362
363 (pam-services
364 ;; Explicitly allow for empty passwords.
365 (base-pam-services #:allow-empty-passwords? #t))
366
a6312f1d 367 (packages (cons* (canonical-package glibc) ;for 'tzselect' & co.
72524ae8 368 parted gptfdisk ddrescue
7eda0c56 369 grub ;mostly so xrefs to its manual work
b419c7f5 370 cryptsetup
f0fbf2c1 371 mdadm
f731529e 372 dosfstools ;mkfs.fat, for the UEFI boot partition
3a9cfba8 373 btrfs-progs
1e8d398a 374 openssh ;we already have sshd, having ssh/scp can help
1ce6f43a 375 wireless-tools iw wpa-supplicant-minimal iproute
8f297d42
LC
376 ;; XXX: We used to have GNU fdisk here, but as of version
377 ;; 2.0.0a, that pulls Guile 1.8, which takes unreasonable
378 ;; space; furthermore util-linux's fdisk is already
379 ;; available here, so we keep that.
f4bdfe73 380 bash-completion
a8cb87ab 381 nvi ;:wq!
6f436c54 382 %base-packages))))
fc91c17a 383
8bac66de
DM
384(define* (agetty-default-service #:optional (tty "ttyS0"))
385 "Return an agetty-service on the given TTY"
386 (agetty-service (agetty-configuration
387 (extra-options '("-L"))
388 (baud-rate "115200")
389 (term "vt100")
390 (tty tty))))
391
fccdc8c8
DM
392(define* (embedded-installation-os bootloader bootloader-target tty
393 #:key (extra-modules '()))
394 "Return an installation os for embedded systems.
395The initrd gets the extra modules EXTRA-MODULES.
396A getty is provided on TTY.
397The bootloader BOOTLOADER is installed to BOOTLOADER-TARGET."
ceb39527
MO
398 (operating-system
399 (inherit installation-os)
400 (bootloader (bootloader-configuration
fccdc8c8
DM
401 (bootloader bootloader)
402 (target bootloader-target)))
ceb39527
MO
403 (kernel linux-libre)
404 (initrd (lambda (fs . rest)
405 (apply base-initrd fs
fccdc8c8 406 #:extra-modules extra-modules
ceb39527 407 rest)))
fccdc8c8 408 (services (cons* (agetty-default-service tty)
8bac66de 409 (operating-system-user-services installation-os)))))
ceb39527 410
fccdc8c8
DM
411(define beaglebone-black-installation-os
412 (embedded-installation-os u-boot-beaglebone-black-bootloader
413 "/dev/sda"
414 "ttyO0"
415 #:extra-modules
416 ;; This module is required to mount the sd card.
417 '("omap_hsmmc")))
418
419
0db22b32 420(define a20-olinuxino-lime-installation-os
c55c6985
DM
421 (embedded-installation-os u-boot-a20-olinuxino-lime-bootloader
422 "/dev/mmcblk0" ; SD card storage
423 "ttyS0"))
424
4b9e9abb 425(define a20-olinuxino-lime2-emmc-installation-os
fccdc8c8
DM
426 (embedded-installation-os u-boot-a20-olinuxino-lime2-bootloader
427 "/dev/mmcblk1" ; eMMC storage
428 "ttyS0"))
a7bb327e
DM
429
430(define a20-olinuxino-micro-installation-os
fccdc8c8
DM
431 (embedded-installation-os u-boot-a20-olinuxino-micro-bootloader
432 "/dev/mmcblk0" ; SD card storage
433 "ttyS0"))
4b9e9abb 434
30aeb846 435(define banana-pi-m2-ultra-installation-os
fccdc8c8
DM
436 (embedded-installation-os u-boot-banana-pi-m2-ultra-bootloader
437 "/dev/mmcblk1" ; eMMC storage
438 "ttyS0"))
30aeb846 439
84ee3378
DM
440(define nintendo-nes-classic-edition-installation-os
441 (embedded-installation-os u-boot-nintendo-nes-classic-edition-bootloader
442 "/dev/mmcblk0" ; SD card (solder it yourself)
443 "ttyS0"))
444
ceb39527 445;; Return the default os here so 'guix system' can consume it directly.
fc91c17a
LC
446installation-os
447
448;;; install.scm ends here