1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2018 Mathieu Othacehe <m.othacehe@gmail.com>
3 ;;; Copyright © 2019 Ludovic Courtès <ludo@gnu.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 installer)
21 #:use-module (guix discovery)
22 #:use-module (guix packages)
23 #:use-module (guix gexp)
24 #:use-module (guix modules)
25 #:use-module (guix utils)
26 #:use-module (guix ui)
27 #:use-module ((guix self) #:select (make-config.scm))
28 #:use-module (gnu packages admin)
29 #:use-module (gnu packages base)
30 #:use-module (gnu packages bash)
31 #:use-module (gnu packages connman)
32 #:use-module (gnu packages cryptsetup)
33 #:use-module (gnu packages disk)
34 #:use-module (gnu packages guile)
35 #:use-module (gnu packages guile-xyz)
36 #:autoload (gnu packages gnupg) (guile-gcrypt)
37 #:use-module (gnu packages iso-codes)
38 #:use-module (gnu packages linux)
39 #:use-module (gnu packages ncurses)
40 #:use-module (gnu packages package-management)
41 #:use-module (gnu packages xorg)
42 #:use-module (ice-9 match)
43 #:use-module (srfi srfi-1)
44 #:export (installer-program))
46 (define module-to-import?
47 ;; Return true for modules that should be imported. For (gnu system …) and
48 ;; (gnu packages …) modules, we simply add the whole 'guix' package via
49 ;; 'with-extensions' (to avoid having to rebuild it all), which is why these
50 ;; modules are excluded here.
53 (('gnu 'installer _ ...) #t)
54 (('gnu 'build _ ...) #t)
55 (('guix 'build _ ...) #t)
58 (define* (build-compiled-file name locale-builder)
59 "Return a file-like object that evalutes the gexp LOCALE-BUILDER and store
60 its result in the scheme file NAME. The derivation will also build a compiled
61 version of this file."
62 (define set-utf8-locale
65 #$(file-append glibc-utf8-locales "/lib/locale/"
67 (package-version glibc-utf8-locales))))
68 (setlocale LC_ALL "en_US.utf8")))
71 (with-extensions (list guile-json)
72 (with-imported-modules (source-module-closure
73 '((gnu installer locale)))
75 (use-modules (gnu installer locale))
77 ;; The locale files contain non-ASCII characters.
82 (string-append #$output "/" #$name ".scm"))
84 (string-append #$output "/" #$name ".go")))
85 (call-with-output-file locale-file
87 (write #$locale-builder port)))
88 (compile-file locale-file
89 #:output-file locale-compiled-file))))))
90 (computed-file name builder))
93 ;; Install the specified locale.
94 #~(lambda (locale-name)
96 (setlocale LC_ALL locale-name))))
98 (define* (compute-locale-step #:key
100 iso639-languages-name
101 iso3166-territories-name)
102 "Return a gexp that run the locale-page of INSTALLER, and install the
103 selected locale. The list of locales, languages and territories passed to
104 locale-page are computed in derivations named respectively LOCALES-NAME,
105 ISO639-LANGUAGES-NAME and ISO3166-TERRITORIES-NAME. Those lists are compiled,
106 so that when the installer is run, all the lengthy operations have already
107 been performed at build time."
108 (define (compiled-file-loader file name)
110 (string-append #$file "/" #$name ".go")))
112 (let* ((supported-locales #~(supported-locales->locales
113 #$(local-file "installer/aux-files/SUPPORTED")))
114 (iso-codes #~(string-append #$iso-codes "/share/iso-codes/json/"))
115 (iso639-3 #~(string-append #$iso-codes "iso_639-3.json"))
116 (iso639-5 #~(string-append #$iso-codes "iso_639-5.json"))
117 (iso3166 #~(string-append #$iso-codes "iso_3166-1.json"))
118 (locales-file (build-compiled-file
120 #~`(quote ,#$supported-locales)))
121 (iso639-file (build-compiled-file
122 iso639-languages-name
123 #~`(quote ,(iso639->iso639-languages
125 #$iso639-3 #$iso639-5))))
126 (iso3166-file (build-compiled-file
127 iso3166-territories-name
128 #~`(quote ,(iso3166->iso3166-territories #$iso3166))))
129 (locales-loader (compiled-file-loader locales-file
131 (iso639-loader (compiled-file-loader iso639-file
132 iso639-languages-name))
133 (iso3166-loader (compiled-file-loader iso3166-file
134 iso3166-territories-name)))
135 #~(lambda (current-installer)
137 ((installer-locale-page current-installer)
138 #:supported-locales #$locales-loader
139 #:iso639-languages #$iso639-loader
140 #:iso3166-territories #$iso3166-loader)))
141 (#$apply-locale result)
145 ;; Apply the specified keymap. Use the default keyboard model.
148 (kmscon-update-keymap (default-keyboard-model)
151 (define* (compute-keymap-step)
152 "Return a gexp that runs the keymap-page of INSTALLER and install the
154 #~(lambda (current-installer)
158 (xkb-rules->models+layouts
159 (string-append #$xkeyboard-config
160 "/share/X11/xkb/rules/base.xml")))
161 (lambda (models layouts)
162 ((installer-keymap-page current-installer)
164 (#$apply-keymap result)
167 (define (installer-steps)
168 (let ((locale-step (compute-locale-step
169 #:locales-name "locales"
170 #:iso639-languages-name "iso639-languages"
171 #:iso3166-territories-name "iso3166-territories"))
172 (keymap-step (compute-keymap-step))
173 (timezone-data #~(string-append #$tzdata
174 "/share/zoneinfo/zone.tab")))
175 #~(lambda (current-installer)
177 ;; Welcome the user and ask him to choose between manual
178 ;; installation and graphical install.
182 ((installer-welcome-page current-installer)
183 #$(local-file "installer/aux-files/logo.txt")))))
185 ;; Ask the user to choose a locale among those supported by
186 ;; the glibc. Install the selected locale right away, so that
187 ;; the user may benefit from any available translation for the
188 ;; installer messages.
191 (description (G_ "Locale"))
193 (#$locale-step current-installer)))
194 (configuration-formatter locale->configuration))
196 ;; Ask the user to select a timezone under glibc format.
199 (description (G_ "Timezone"))
201 ((installer-timezone-page current-installer)
203 (configuration-formatter posix-tz->configuration))
205 ;; The installer runs in a kmscon virtual terminal where loadkeys
206 ;; won't work. kmscon uses libxkbcommon as a backend for keyboard
207 ;; input. It is possible to update kmscon current keymap by sending it
208 ;; a keyboard model, layout and variant, in a somehow similar way as
209 ;; what is done with setxkbmap utility.
211 ;; So ask for a keyboard model, layout and variant to update the
212 ;; current kmscon keymap.
215 (description (G_ "Keyboard mapping selection"))
217 (#$keymap-step current-installer)))
218 (configuration-formatter keyboard-layout->configuration))
220 ;; Run a partitioning tool allowing the user to modify
221 ;; partition tables, partitions and their mount points.
224 (description (G_ "Partitioning"))
226 ((installer-partition-page current-installer))))
227 (configuration-formatter user-partitions->configuration))
229 ;; Ask the user to input a hostname for the system.
232 (description (G_ "Hostname"))
234 ((installer-hostname-page current-installer))))
235 (configuration-formatter hostname->configuration))
237 ;; Provide an interface above connmanctl, so that the user can select
238 ;; a network susceptible to acces Internet.
241 (description (G_ "Network selection"))
243 ((installer-network-page current-installer)))))
245 ;; Prompt for users (name, group and home directory).
248 (description (G_ "User creation"))
250 ((installer-user-page current-installer))))
251 (configuration-formatter users->configuration))
253 ;; Ask the user to choose one or many desktop environment(s).
256 (description (G_ "Services"))
258 ((installer-services-page current-installer))))
259 (configuration-formatter
260 desktop-environments->configuration))
264 (description (G_ "Configuration file"))
266 (lambda (result prev-steps)
267 ((installer-final-page current-installer)
268 result prev-steps))))))))
270 (define (installer-program)
271 "Return a file-like object that runs the given INSTALLER."
273 ;; Initialize gettext support, so that installer messages can be
276 (bindtextdomain "guix" (string-append #$guix "/share/locale"))
277 (textdomain "guix")))
279 (define set-installer-path
280 ;; Add the specified binary to PATH for later use by the installer.
282 '#$(append (list bash ;start subshells
283 connman ;call connmanctl
288 guix ;guix system init call
291 (map canonical-package (list coreutils)))))
292 (with-output-to-port (%make-void-port "w")
294 (set-path-environment-variable "PATH" '("bin" "sbin") inputs)))))
296 (define steps (installer-steps))
299 (string-append (current-source-directory) "/..")
302 (define installer-builder
303 ;; Note: Include GUIX as an extension to get all the (gnu system …), (gnu
304 ;; packages …), etc. modules.
305 (with-extensions (list guile-gcrypt guile-newt
306 guile-parted guile-bytestructures
307 guile-json guile-git guix)
308 (with-imported-modules `(,@(source-module-closure
311 #:select? module-to-import?)
312 ((guix config) => ,(make-config.scm)))
314 (use-modules (gnu installer record)
315 (gnu installer keymap)
316 (gnu installer steps)
317 (gnu installer final)
318 (gnu installer hostname)
319 (gnu installer locale)
320 (gnu installer parted)
321 (gnu installer services)
322 (gnu installer timezone)
325 ((gnu installer newt keymap)
326 #:select (keyboard-layout->configuration))
331 ;; Initialize gettext support so that installers can use
332 ;; (guix i18n) module.
335 ;; Add some binaries used by the installers to PATH.
338 (let* ((current-installer newt-installer)
339 (steps (#$steps current-installer)))
340 ((installer-init current-installer))
345 #:rewind-strategy 'menu
346 #:menu-proc (installer-menu-page current-installer)
350 (let ((error-file "/tmp/last-installer-error"))
351 (call-with-output-file error-file
353 (display-backtrace (make-stack #t) port)
354 (print-exception port
355 (stack-ref (make-stack #t) 1)
357 ((installer-exit-error current-installer)
358 error-file key args))
361 ((installer-exit current-installer)))))))
366 ;; Set the default locale to install unicode support. For
367 ;; some reason, unicode support is not correctly installed
368 ;; when calling this in 'installer-builder'.
369 (setenv "LANG" "en_US.UTF-8")
370 (system #$(program-file "installer-real" installer-builder)))))