1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014, 2015 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2015 Mark H Weaver <mhw@netris.org>
5 ;;; This file is part of GNU Guix.
7 ;;; GNU Guix is free software; you can redistribute it and/or modify it
8 ;;; under the terms of the GNU General Public License as published by
9 ;;; the Free Software Foundation; either version 3 of the License, or (at
10 ;;; your option) any later version.
12 ;;; GNU Guix is distributed in the hope that it will be useful, but
13 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;;; GNU General Public License for more details.
17 ;;; You should have received a copy of the GNU General Public License
18 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20 (define-module (gnu system install)
22 #:use-module (guix gexp)
23 #:use-module (guix store)
24 #:use-module (guix monads)
25 #:use-module ((guix store) #:select (%store-prefix))
26 #:use-module (guix profiles)
27 #:use-module (gnu packages admin)
28 #:use-module (gnu packages bash)
29 #:use-module (gnu packages linux)
30 #:use-module (gnu packages cryptsetup)
31 #:use-module (gnu packages package-management)
32 #:use-module (gnu packages disk)
33 #:use-module (gnu packages grub)
34 #:use-module (gnu packages texinfo)
35 #:use-module (gnu packages compression)
36 #:use-module (ice-9 match)
37 #:use-module (srfi srfi-26)
38 #:export (self-contained-tarball
43 ;;; This module provides an 'operating-system' definition for use on images
44 ;;; for USB sticks etc., for the installation of the GNU system.
49 (define* (self-contained-tarball #:key (guix guix))
50 "Return a self-contained tarball containing a store initialized with the
51 closure of GUIX. The tarball contains /gnu/store, /var/guix, and a profile
52 under /root/.guix-profile where GUIX is installed."
53 (mlet %store-monad ((profile (profile-derivation
55 (list (package->manifest-entry guix))))))
58 (use-modules (guix build utils)
64 (string-append #$guix "/sbin:" #$tar "/bin:" #$xz "/bin"))
66 ;; Note: there is not much to gain here with deduplication and there
67 ;; is the overhead of the '.links' directory, so turn it off.
68 (populate-single-profile-directory %root
73 ;; Create the tarball. Use GNU format so there's no file name
75 (with-directory-excursion %root
76 (zero? (system* "tar" "--xz" "--format=gnu"
77 "--owner=root:0" "--group=root:0"
80 ;; Avoid adding / and /var to the tarball,
81 ;; so that the ownership and permissions of those
82 ;; directories will not be overwritten when
83 ;; extracting the archive. Do not include /root
84 ;; because the root account might have a different
87 (string-append "." (%store-directory)))))))
89 (gexp->derivation "guix-tarball.tar.xz" build
90 #:references-graphs `(("profile" ,profile))
91 #:modules '((guix build utils)
92 (guix build store-copy)
93 (gnu build install)))))
97 "Return a script that spawns the Info reader on the right section of the
99 (gexp->script "log-to-info"
101 ;; 'gunzip' is needed to decompress the doc.
102 (setenv "PATH" (string-append #$gzip "/bin"))
104 (execl (string-append #$texinfo-4 "/bin/info") "info"
105 "-d" "/run/current-system/profile/share/info"
106 "-f" (string-append #$guix "/share/info/guix.info")
107 "-n" "System Installation"))))
109 (define %backing-directory
110 ;; Sub-directory used as the backing store for copy-on-write.
113 (define (make-cow-store target)
114 "Return a gexp that makes the store copy-on-write, using TARGET as the
115 backing store. This is useful when TARGET is on a hard disk, whereas the
116 current store is on a RAM disk."
117 (define (unionfs read-only read-write mount-point)
118 ;; Make MOUNT-POINT the union of READ-ONLY and READ-WRITE.
120 ;; Note: in the command below, READ-WRITE appears before READ-ONLY so that
121 ;; it is considered a "higher-level branch", as per unionfs-fuse(8),
122 ;; thereby allowing files existing on READ-ONLY to be copied over to
125 (list (string-append #$unionfs-fuse "/bin/unionfs")
127 "cow,allow_other,use_ino,max_files=65536,nonempty"
128 (string-append #$read-write "=RW:" #$read-only "=RO")
131 (define (set-store-permissions directory)
132 ;; Set the right perms on DIRECTORY to use it as the store.
134 (chown #$directory 0 30000) ;use the fixed 'guixbuild' GID
135 (chmod #$directory #o1775)))
138 (unless (file-exists? "/.ro-store")
140 (mount #$(%store-prefix) "/.ro-store" "none"
141 (logior MS_BIND MS_RDONLY)))
143 (let ((rw-dir (string-append target #$%backing-directory)))
145 (mkdir-p "/.rw-store")
146 #$(set-store-permissions #~rw-dir)
147 #$(set-store-permissions "/.rw-store")
149 ;; Mount the union, then atomically make it the store.
150 (and #$(unionfs "/.ro-store" #~rw-dir "/.rw-store")
152 (sleep 1) ;XXX: wait for unionfs to be ready
153 (mount "/.rw-store" #$(%store-prefix) "" MS_MOVE)
154 (rmdir "/.rw-store"))))))
156 (define (cow-store-service)
157 "Return a service that makes the store copy-on-write, such that writes go to
158 the user's target storage device rather than on the RAM disk."
159 ;; See <http://bugs.gnu.org/18061> for the initial report.
160 (with-monad %store-monad
162 (requirement '(root-file-system user-processes))
163 (provision '(cow-store))
165 "Make the store copy-on-write, with writes going to \
168 ;; This is meant to be explicitly started by the user.
171 (start #~(case-lambda
173 #$(make-cow-store #~target)
176 ;; Do nothing, and mark the service as stopped.
178 (stop #~(lambda (target)
179 ;; Delete the temporary directory, but leave everything
180 ;; mounted as there may still be processes using it
181 ;; since 'user-processes' doesn't depend on us. The
182 ;; 'user-unmount' service will unmount TARGET
184 (delete-file-recursively
185 (string-append target #$%backing-directory))))))))
187 (define (configuration-template-service)
188 "Return a dummy service whose purpose is to install an operating system
189 configuration template file in the installation system."
192 (cut search-path %load-path <>))
196 (list (local-file (search file))
197 (string-append "/etc/configuration/" target))))
198 '(("gnu/system/examples/bare-bones.tmpl" -> "bare-bones.scm")
199 ("gnu/system/examples/desktop.tmpl" -> "desktop.scm"))))
201 (with-monad %store-monad
203 (requirement '(root-file-system))
204 (provision '(os-config-template))
206 "This dummy service installs an OS configuration template.")
211 (use-modules (ice-9 match)
214 (mkdir-p "/etc/configuration")
215 (for-each (match-lambda
217 (unless (file-exists? target)
218 (copy-file file target))))
221 (define %nscd-minimal-caches
222 ;; Minimal in-memory caching policy for nscd.
223 (list (nscd-cache (database 'hosts)
224 (positive-time-to-live (* 3600 12))
225 (negative-time-to-live 20)
227 (max-database-size (* 5 (expt 2 20)))))) ;5 MiB
229 (define (installation-services)
230 "Return the list services for the installation image."
231 (let ((motd (text-file "motd" "
232 Welcome to the installation of the Guix System Distribution!
234 There is NO WARRANTY, to the extent permitted by law. In particular, you may
235 LOSE ALL YOUR DATA as a side effect of the installation process. Furthermore,
236 it is alpha software, so it may BREAK IN UNEXPECTED WAYS.
238 You have been warned. Thanks for being so brave.
240 (define (normal-tty tty)
241 (mingetty-service tty
246 (list (mingetty-service "tty1"
250 ;; Documentation. The manual is in UTF-8, but
251 ;; 'console-font-service' sets up Unicode support and loads a font
252 ;; with all the useful glyphs like em dash and quotation marks.
253 (mingetty-service "tty2"
256 #:login-program (log-to-info))
258 ;; Documentation add-on.
259 (configuration-template-service)
261 ;; A bunch of 'root' ttys.
267 ;; The usual services.
270 ;; The build daemon. Register the hydra.gnu.org key as trusted.
271 ;; This allows the installation process to use substitutes by
273 (guix-service #:authorize-hydra-key? #t)
275 ;; Start udev so that useful device nodes are available.
276 ;; Use device-mapper rules for cryptsetup & co.
277 (udev-service #:rules (list lvm2))
279 ;; Add the 'cow-store' service, which users have to start manually
280 ;; since it takes the installation directory as an argument.
283 ;; Install Unicode support and a suitable font.
284 (console-font-service "tty1")
285 (console-font-service "tty2")
286 (console-font-service "tty3")
287 (console-font-service "tty4")
288 (console-font-service "tty5")
289 (console-font-service "tty6")
291 ;; Since this is running on a USB stick with a unionfs as the root
292 ;; file system, use an appropriate cache configuration.
293 (nscd-service (nscd-configuration
294 (caches %nscd-minimal-caches))))))
299 This is an installation image of the GNU system. Welcome.
301 Use Alt-F2 for documentation.
304 (define installation-os
305 ;; The operating system used on installation images for USB sticks etc.
308 (timezone "Europe/Paris")
309 (locale "en_US.utf8")
310 (bootloader (grub-configuration
311 (device "/dev/sda")))
313 ;; Note: the disk image build code overrides this root file system with
314 ;; the appropriate one.
317 (device "gnu-disk-image")
321 (users (list (user-account
324 (supplementary-groups '("wheel")) ; allow use of sudo
326 (comment "Guest of GNU")
327 (home-directory "/home/guest"))))
331 (services (installation-services))
333 ;; We don't need setuid programs so pass the empty list so we don't pull
334 ;; additional programs here.
335 (setuid-programs '())
338 ;; Explicitly allow for empty passwords.
339 (base-pam-services #:allow-empty-passwords? #t))
341 (packages (cons* texinfo-4 ;for the standalone Info reader
343 grub ;mostly so xrefs to its manual work
345 wireless-tools iw wpa-supplicant-light
346 ;; XXX: We used to have GNU fdisk here, but as of version
347 ;; 2.0.0a, that pulls Guile 1.8, which takes unreasonable
348 ;; space; furthermore util-linux's fdisk is already
349 ;; available here, so we keep that.
353 ;; Return it here so 'guix system' can consume it directly.
356 ;;; install.scm ends here