1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014 Ludovic Courtès <ludo@gnu.org>
4 ;;; This file is part of GNU Guix.
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19 (define-module (gnu system install)
21 #:use-module (guix gexp)
22 #:use-module (guix monads)
23 #:use-module ((guix store) #:select (%store-prefix))
24 #:use-module (gnu packages linux)
25 #:use-module (gnu packages package-management)
26 #:use-module (gnu packages disk)
27 #:use-module (gnu packages grub)
28 #:use-module (gnu packages texinfo)
29 #:export (installation-os))
33 ;;; This module provides an 'operating-system' definition for use on images
34 ;;; for USB sticks etc., for the installation of the GNU system.
39 "Return a script that spawns the Info reader on the right section of the
41 (gexp->script "log-to-info"
42 #~(execl (string-append #$texinfo-4 "/bin/info") "info"
43 "-d" "/run/current-system/profile/share/info"
44 "-f" (string-append #$guix "/share/info/guix.info")
45 "-n" "System Installation")))
47 (define %backing-directory
48 ;; Sub-directory used as the backing store for copy-on-write.
51 (define (make-cow-store target)
52 "Return a gexp that makes the store copy-on-write, using TARGET as the
53 backing store. This is useful when TARGET is on a hard disk, whereas the
54 current store is on a RAM disk."
55 (define (unionfs read-only read-write mount-point)
56 ;; Make MOUNT-POINT the union of READ-ONLY and READ-WRITE.
58 ;; Note: in the command below, READ-WRITE appears before READ-ONLY so that
59 ;; it is considered a "higher-level branch", as per unionfs-fuse(8),
60 ;; thereby allowing files existing on READ-ONLY to be copied over to
63 (list (string-append #$unionfs-fuse "/bin/unionfs")
65 "cow,allow_other,use_ino,max_files=65536,nonempty"
66 (string-append #$read-write "=RW:" #$read-only "=RO")
69 (define (set-store-permissions directory)
70 ;; Set the right perms on DIRECTORY to use it as the store.
72 (chown #$directory 0 30000) ;use the fixed 'guixbuild' GID
73 (chmod #$directory #o1775)))
76 (unless (file-exists? "/.ro-store")
78 (mount #$(%store-prefix) "/.ro-store" "none"
79 (logior MS_BIND MS_RDONLY)))
81 (let ((rw-dir (string-append target #$%backing-directory)))
83 (mkdir-p "/.rw-store")
84 #$(set-store-permissions #~rw-dir)
85 #$(set-store-permissions "/.rw-store")
87 ;; Mount the union, then atomically make it the store.
88 (and #$(unionfs "/.ro-store" #~rw-dir "/.rw-store")
90 (sleep 1) ;XXX: wait for unionfs to be ready
91 (mount "/.rw-store" #$(%store-prefix) "" MS_MOVE)
92 (rmdir "/.rw-store"))))))
94 (define (cow-store-service)
95 "Return a service that makes the store copy-on-write, such that writes go to
96 the user's target storage device rather than on the RAM disk."
97 ;; See <http://bugs.gnu.org/18061> for the initial report.
98 (with-monad %store-monad
100 (requirement '(root-file-system user-processes))
101 (provision '(cow-store))
103 "Make the store copy-on-write, with writes going to \
105 (start #~(case-lambda
107 #$(make-cow-store #~target)
110 ;; Do nothing, and mark the service as stopped.
112 (stop #~(lambda (target)
113 ;; Delete the temporary directory, but leave everything
114 ;; mounted as there may still be processes using it
115 ;; since 'user-processes' doesn't depend on us.
116 (delete-file-recursively
117 (string-append target #$%backing-directory))))))))
119 (define (configuration-template-service)
120 "Return a dummy service whose purpose is to install an operating system
121 configuration template file in the installation system."
123 (define local-template
124 "/etc/configuration-template.scm")
126 (search-path %load-path "gnu/system/os-config.tmpl"))
128 (mlet %store-monad ((template (interned-file template)))
130 (requirement '(root-file-system))
131 (provision '(os-config-template))
133 "This dummy service installs an OS configuration template.")
137 #~(unless (file-exists? #$local-template)
138 (copy-file #$template #$local-template)))))))
140 (define (installation-services)
141 "Return the list services for the installation image."
142 (let ((motd (text-file "motd" "
143 Welcome to the installation of the GNU operating system!
145 There is NO WARRANTY, to the extent permitted by law. In particular, you may
146 LOSE ALL YOUR DATA as a side effect of the installation process. Furthermore,
147 it is alpha software, so it may BREAK IN UNEXPECTED WAYS.
149 You have been warned. Thanks for being so brave.
151 (define (normal-tty tty)
152 (mingetty-service tty
157 (list (mingetty-service "tty1"
161 ;; Documentation. The manual is in UTF-8, but
162 ;; 'console-font-service' sets up Unicode support and loads a font
163 ;; with all the useful glyphs like em dash and quotation marks.
164 (mingetty-service "tty2"
167 #:login-program (log-to-info))
169 ;; Documentation add-on.
170 (configuration-template-service)
172 ;; A bunch of 'root' ttys.
178 ;; The usual services.
181 ;; The build daemon. Register the hydra.gnu.org key as trusted.
182 ;; This allows the installation process to use substitutes by
184 (guix-service #:authorize-hydra-key? #t)
186 ;; Start udev so that useful device nodes are available.
189 ;; Add the 'cow-store' service, which users have to start manually
190 ;; since it takes the installation directory as an argument.
193 ;; Install Unicode support and a suitable font.
194 (console-font-service "tty1")
195 (console-font-service "tty2")
196 (console-font-service "tty3")
197 (console-font-service "tty4")
198 (console-font-service "tty5")
199 (console-font-service "tty6")
206 This is an installation image of the GNU system. Welcome.
208 Use Alt-F2 for documentation.
211 (define installation-os
212 ;; The operating system used on installation images for USB sticks etc.
215 (timezone "Europe/Paris")
216 (locale "en_US.UTF-8")
217 (bootloader (grub-configuration
218 (device "/dev/sda")))
220 ;; Note: the disk image build code overrides this root file system with
221 ;; the appropriate one.
224 (device "gnu-disk-image")
228 (users (list (user-account
231 (supplementary-groups '("wheel")) ; allow use of sudo
233 (comment "Guest of GNU")
234 (home-directory "/home/guest"))))
238 (services (installation-services))
240 ;; We don't need setuid programs so pass the empty list so we don't pull
241 ;; additional programs here.
242 (setuid-programs '())
245 ;; Explicitly allow for empty passwords.
246 (base-pam-services #:allow-empty-passwords? #t))
248 (packages (cons* texinfo-4 ;for the standalone Info reader
250 grub ;mostly so xrefs to its manual work
252 ;; XXX: We used to have GNU fdisk here, but as of version
253 ;; 2.0.0a, that pulls Guile 1.8, which takes unreasonable
254 ;; space; furthermore util-linux's fdisk is already
255 ;; available here, so we keep that.
258 ;; Return it here so 'guix system' can consume it directly.
261 ;;; install.scm ends here