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