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