1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014, 2015 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 store)
23 #:use-module (guix monads)
24 #:use-module ((guix store) #:select (%store-prefix))
25 #:use-module (guix profiles)
26 #:use-module (gnu packages admin)
27 #:use-module (gnu packages bash)
28 #:use-module (gnu packages linux)
29 #:use-module (gnu packages cryptsetup)
30 #:use-module (gnu packages package-management)
31 #:use-module (gnu packages disk)
32 #:use-module (gnu packages grub)
33 #:use-module (gnu packages texinfo)
34 #:use-module (gnu packages compression)
35 #:use-module (ice-9 match)
36 #:use-module (srfi srfi-26)
37 #:export (self-contained-tarball
42 ;;; This module provides an 'operating-system' definition for use on images
43 ;;; for USB sticks etc., for the installation of the GNU system.
48 (define* (self-contained-tarball #:key (guix guix))
49 "Return a self-contained tarball containing a store initialized with the
50 closure of GUIX. The tarball contains /gnu/store, /var/guix, and a profile
51 under /root/.guix-profile where GUIX is installed."
52 (mlet %store-monad ((profile (profile-derivation
54 (list (package->manifest-entry guix))))))
57 (use-modules (guix build utils)
63 (string-append #$guix "/sbin:" #$tar "/bin:" #$xz "/bin"))
65 (populate-single-profile-directory %root
69 ;; Create the tarball. Use GNU format so there's no file name
70 ;; length limitation. Use the owner and group names given in the
72 ;; XXX: /var and /root should rather be root-owned, but it doesn't
73 ;; make any difference in practice.
74 (with-directory-excursion %root
75 (zero? (system* "tar" "--xz" "--format=gnu"
76 "--owner=guixbuilder01"
78 "-cvf" #$output ".")))))
80 (gexp->derivation "guix-tarball.tar.xz" build
81 #:references-graphs `(("profile" ,profile))
82 #:modules '((guix build utils)
83 (guix build store-copy)
84 (gnu build install)))))
88 "Return a script that spawns the Info reader on the right section of the
90 (gexp->script "log-to-info"
92 ;; 'gunzip' is needed to decompress the doc.
93 (setenv "PATH" (string-append #$gzip "/bin"))
95 (execl (string-append #$texinfo-4 "/bin/info") "info"
96 "-d" "/run/current-system/profile/share/info"
97 "-f" (string-append #$guix "/share/info/guix.info")
98 "-n" "System Installation"))))
100 (define %backing-directory
101 ;; Sub-directory used as the backing store for copy-on-write.
104 (define (make-cow-store target)
105 "Return a gexp that makes the store copy-on-write, using TARGET as the
106 backing store. This is useful when TARGET is on a hard disk, whereas the
107 current store is on a RAM disk."
108 (define (unionfs read-only read-write mount-point)
109 ;; Make MOUNT-POINT the union of READ-ONLY and READ-WRITE.
111 ;; Note: in the command below, READ-WRITE appears before READ-ONLY so that
112 ;; it is considered a "higher-level branch", as per unionfs-fuse(8),
113 ;; thereby allowing files existing on READ-ONLY to be copied over to
116 (list (string-append #$unionfs-fuse "/bin/unionfs")
118 "cow,allow_other,use_ino,max_files=65536,nonempty"
119 (string-append #$read-write "=RW:" #$read-only "=RO")
122 (define (set-store-permissions directory)
123 ;; Set the right perms on DIRECTORY to use it as the store.
125 (chown #$directory 0 30000) ;use the fixed 'guixbuild' GID
126 (chmod #$directory #o1775)))
129 (unless (file-exists? "/.ro-store")
131 (mount #$(%store-prefix) "/.ro-store" "none"
132 (logior MS_BIND MS_RDONLY)))
134 (let ((rw-dir (string-append target #$%backing-directory)))
136 (mkdir-p "/.rw-store")
137 #$(set-store-permissions #~rw-dir)
138 #$(set-store-permissions "/.rw-store")
140 ;; Mount the union, then atomically make it the store.
141 (and #$(unionfs "/.ro-store" #~rw-dir "/.rw-store")
143 (sleep 1) ;XXX: wait for unionfs to be ready
144 (mount "/.rw-store" #$(%store-prefix) "" MS_MOVE)
145 (rmdir "/.rw-store"))))))
147 (define (cow-store-service)
148 "Return a service that makes the store copy-on-write, such that writes go to
149 the user's target storage device rather than on the RAM disk."
150 ;; See <http://bugs.gnu.org/18061> for the initial report.
151 (with-monad %store-monad
153 (requirement '(root-file-system user-processes))
154 (provision '(cow-store))
156 "Make the store copy-on-write, with writes going to \
159 ;; This is meant to be explicitly started by the user.
162 (start #~(case-lambda
164 #$(make-cow-store #~target)
167 ;; Do nothing, and mark the service as stopped.
169 (stop #~(lambda (target)
170 ;; Delete the temporary directory, but leave everything
171 ;; mounted as there may still be processes using it
172 ;; since 'user-processes' doesn't depend on us. The
173 ;; 'user-unmount' service will unmount TARGET
175 (delete-file-recursively
176 (string-append target #$%backing-directory))))))))
178 (define (configuration-template-service)
179 "Return a dummy service whose purpose is to install an operating system
180 configuration template file in the installation system."
183 (cut search-path %load-path <>))
187 (list (local-file (search file))
188 (string-append "/etc/configuration/" target))))
189 '(("gnu/system/examples/bare-bones.tmpl" -> "bare-bones.scm")
190 ("gnu/system/examples/desktop.tmpl" -> "desktop.scm"))))
192 (with-monad %store-monad
194 (requirement '(root-file-system))
195 (provision '(os-config-template))
197 "This dummy service installs an OS configuration template.")
202 (use-modules (ice-9 match)
205 (mkdir-p "/etc/configuration")
206 (for-each (match-lambda
208 (unless (file-exists? target)
209 (copy-file file target))))
212 (define %nscd-minimal-caches
213 ;; Minimal in-memory caching policy for nscd.
214 (list (nscd-cache (database 'hosts)
215 (positive-time-to-live (* 3600 12))
216 (negative-time-to-live 20)
218 (max-database-size (* 5 (expt 2 20)))))) ;5 MiB
220 (define (installation-services)
221 "Return the list services for the installation image."
222 (let ((motd (text-file "motd" "
223 Welcome to the installation of the Guix System Distribution!
225 There is NO WARRANTY, to the extent permitted by law. In particular, you may
226 LOSE ALL YOUR DATA as a side effect of the installation process. Furthermore,
227 it is alpha software, so it may BREAK IN UNEXPECTED WAYS.
229 You have been warned. Thanks for being so brave.
231 (define (normal-tty tty)
232 (mingetty-service tty
237 (list (mingetty-service "tty1"
241 ;; Documentation. The manual is in UTF-8, but
242 ;; 'console-font-service' sets up Unicode support and loads a font
243 ;; with all the useful glyphs like em dash and quotation marks.
244 (mingetty-service "tty2"
247 #:login-program (log-to-info))
249 ;; Documentation add-on.
250 (configuration-template-service)
252 ;; A bunch of 'root' ttys.
258 ;; The usual services.
261 ;; The build daemon. Register the hydra.gnu.org key as trusted.
262 ;; This allows the installation process to use substitutes by
264 (guix-service #:authorize-hydra-key? #t)
266 ;; Start udev so that useful device nodes are available.
269 ;; Add the 'cow-store' service, which users have to start manually
270 ;; since it takes the installation directory as an argument.
273 ;; Install Unicode support and a suitable font.
274 (console-font-service "tty1")
275 (console-font-service "tty2")
276 (console-font-service "tty3")
277 (console-font-service "tty4")
278 (console-font-service "tty5")
279 (console-font-service "tty6")
281 ;; Since this is running on a USB stick with a unionfs as the root
282 ;; file system, use an appropriate cache configuration.
283 (nscd-service (nscd-configuration
284 (caches %nscd-minimal-caches))))))
289 This is an installation image of the GNU system. Welcome.
291 Use Alt-F2 for documentation.
294 (define installation-os
295 ;; The operating system used on installation images for USB sticks etc.
298 (timezone "Europe/Paris")
299 (locale "en_US.utf8")
300 (bootloader (grub-configuration
301 (device "/dev/sda")))
303 ;; Note: the disk image build code overrides this root file system with
304 ;; the appropriate one.
307 (device "gnu-disk-image")
311 (users (list (user-account
314 (supplementary-groups '("wheel")) ; allow use of sudo
316 (comment "Guest of GNU")
317 (home-directory "/home/guest"))))
321 (services (installation-services))
323 ;; We don't need setuid programs so pass the empty list so we don't pull
324 ;; additional programs here.
325 (setuid-programs '())
328 ;; Explicitly allow for empty passwords.
329 (base-pam-services #:allow-empty-passwords? #t))
331 (packages (cons* texinfo-4 ;for the standalone Info reader
333 grub ;mostly so xrefs to its manual work
335 wireless-tools iw wpa-supplicant-light
336 ;; XXX: We used to have GNU fdisk here, but as of version
337 ;; 2.0.0a, that pulls Guile 1.8, which takes unreasonable
338 ;; space; furthermore util-linux's fdisk is already
339 ;; available here, so we keep that.
343 ;; Return it here so 'guix system' can consume it directly.
346 ;;; install.scm ends here