1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2018, 2020 Mathieu Othacehe <m.othacehe@gmail.com>
3 ;;; Copyright © 2019, 2020, 2022 Ludovic Courtès <ludo@gnu.org>
4 ;;; Copyright © 2019, 2020 Tobias Geerinckx-Rice <me@tobias.gr>
5 ;;; Copyright © 2020 Florian Pelz <pelzflorian@pelzflorian.de>
7 ;;; This file is part of GNU Guix.
9 ;;; GNU Guix is free software; you can redistribute it and/or modify it
10 ;;; under the terms of the GNU General Public License as published by
11 ;;; the Free Software Foundation; either version 3 of the License, or (at
12 ;;; your option) any later version.
14 ;;; GNU Guix is distributed in the hope that it will be useful, but
15 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;;; GNU General Public License for more details.
19 ;;; You should have received a copy of the GNU General Public License
20 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
22 (define-module (gnu installer)
23 #:use-module (guix discovery)
24 #:use-module (guix packages)
25 #:use-module (guix gexp)
26 #:use-module (guix modules)
27 #:use-module (guix utils)
28 #:use-module (guix ui)
29 #:use-module ((guix self) #:select (make-config.scm))
30 #:use-module (guix packages)
31 #:use-module (guix git-download)
32 #:use-module (gnu installer utils)
33 #:use-module (gnu packages admin)
34 #:use-module (gnu packages base)
35 #:use-module (gnu packages bash)
36 #:use-module (gnu packages compression)
37 #:use-module (gnu packages connman)
38 #:use-module (gnu packages cryptsetup)
39 #:use-module (gnu packages disk)
40 #:use-module (gnu packages file-systems)
41 #:use-module (gnu packages guile)
42 #:use-module (gnu packages guile-xyz)
43 #:autoload (gnu packages gnupg) (guile-gcrypt)
44 #:use-module (gnu packages iso-codes)
45 #:use-module (gnu packages linux)
46 #:use-module (gnu packages nano)
47 #:use-module (gnu packages ncurses)
48 #:use-module (gnu packages package-management)
49 #:use-module (gnu packages tls)
50 #:use-module (gnu packages xorg)
51 #:use-module (gnu system locale)
52 #:use-module (ice-9 match)
53 #:use-module (srfi srfi-1)
54 #:export (installer-program))
56 (define module-to-import?
57 ;; Return true for modules that should be imported. For (gnu system …) and
58 ;; (gnu packages …) modules, we simply add the whole 'guix' package via
59 ;; 'with-extensions' (to avoid having to rebuild it all), which is why these
60 ;; modules are excluded here.
63 (('gnu 'installer _ ...) #t)
64 (('gnu 'build _ ...) #t)
65 (('guix 'build _ ...) #t)
66 (('guix 'read-print) #t)
70 ;; Select (guix …) and (gnu …) modules, except (guix config).
77 (define* (build-compiled-file name locale-builder)
78 "Return a file-like object that evaluates the gexp LOCALE-BUILDER and store
79 its result in the scheme file NAME. The derivation will also build a compiled
80 version of this file."
81 (define set-utf8-locale
84 #$(file-append glibc-utf8-locales "/lib/locale/"
86 (package-version glibc-utf8-locales))))
87 (setlocale LC_ALL "en_US.utf8")))
90 (with-extensions (list guile-json-3)
91 (with-imported-modules `(,@(source-module-closure
92 '((gnu installer locale))
93 #:select? not-config?)
94 ((guix config) => ,(make-config.scm)))
96 (use-modules (gnu installer locale))
98 ;; The locale files contain non-ASCII characters.
103 (string-append #$output "/" #$name ".scm"))
104 (locale-compiled-file
105 (string-append #$output "/" #$name ".go")))
106 (call-with-output-file locale-file
108 (write #$locale-builder port)))
109 (compile-file locale-file
110 #:output-file locale-compiled-file))))))
111 (computed-file name builder))
114 ;; Install the specified locale.
115 (with-imported-modules (source-module-closure '((gnu services herd)))
118 (setlocale LC_ALL locale))
120 ;; Restart the documentation viewer so it displays the manual in
121 ;; language that corresponds to LOCALE. Make sure that nothing is
122 ;; printed on the console.
123 (parameterize ((shepherd-message-port
124 (%make-void-port "w")))
125 (stop-service 'term-tty2)
126 (start-service 'term-tty2 (list locale))))))
128 (define* (compute-locale-step #:key
130 iso639-languages-name
131 iso3166-territories-name)
132 "Return a gexp that run the locale-page of INSTALLER, and install the
133 selected locale. The list of locales, languages and territories passed to
134 locale-page are computed in derivations named respectively LOCALES-NAME,
135 ISO639-LANGUAGES-NAME and ISO3166-TERRITORIES-NAME. Those lists are compiled,
136 so that when the installer is run, all the lengthy operations have already
137 been performed at build time."
138 (define (compiled-file-loader file name)
140 (string-append #$file "/" #$name ".go")))
142 (let* ((supported-locales #~(supported-locales->locales
143 #+(glibc-supported-locales)))
144 (iso-codes #~(string-append #$iso-codes "/share/iso-codes/json/"))
145 (iso639-3 #~(string-append #$iso-codes "iso_639-3.json"))
146 (iso639-5 #~(string-append #$iso-codes "iso_639-5.json"))
147 (iso3166 #~(string-append #$iso-codes "iso_3166-1.json"))
148 (locales-file (build-compiled-file
150 #~`(quote ,#$supported-locales)))
151 (iso639-file (build-compiled-file
152 iso639-languages-name
153 #~`(quote ,(iso639->iso639-languages
155 #$iso639-3 #$iso639-5))))
156 (iso3166-file (build-compiled-file
157 iso3166-territories-name
158 #~`(quote ,(iso3166->iso3166-territories #$iso3166))))
159 (locales-loader (compiled-file-loader locales-file
161 (iso639-loader (compiled-file-loader iso639-file
162 iso639-languages-name))
163 (iso3166-loader (compiled-file-loader iso3166-file
164 iso3166-territories-name)))
165 #~(lambda (current-installer)
167 ((installer-locale-page current-installer)
168 #:supported-locales #$locales-loader
169 #:iso639-languages #$iso639-loader
170 #:iso3166-territories #$iso3166-loader)))
171 (#$apply-locale result)
175 ;; Apply the specified keymap. Use the default keyboard model.
177 ((layout variant options)
178 (kmscon-update-keymap (default-keyboard-model)
179 layout variant options))))
181 (define* (compute-keymap-step context)
182 "Return a gexp that runs the keymap-page of INSTALLER and install the
184 #~(lambda (current-installer)
188 (xkb-rules->models+layouts
189 (string-append #$xkeyboard-config
190 "/share/X11/xkb/rules/base.xml")))
191 (lambda (models layouts)
192 ((installer-keymap-page current-installer)
193 layouts '#$context)))))
194 (and result (#$apply-keymap result))
197 (define (installer-steps)
198 (let ((locale-step (compute-locale-step
199 #:locales-name "locales"
200 #:iso639-languages-name "iso639-languages"
201 #:iso3166-territories-name "iso3166-territories"))
202 (timezone-data #~(string-append #$tzdata
203 "/share/zoneinfo/zone.tab")))
204 #~(lambda (current-installer)
205 ((installer-parameters-menu current-installer)
207 ((installer-parameters-page current-installer)
209 (#$(compute-keymap-step 'param)
210 current-installer)))))
212 ;; Ask the user to choose a locale among those supported by
213 ;; the glibc. Install the selected locale right away, so that
214 ;; the user may benefit from any available translation for the
215 ;; installer messages.
218 (description (G_ "Locale"))
220 (#$locale-step current-installer)))
221 (configuration-formatter locale->configuration))
223 ;; Welcome the user and ask them to choose between manual
224 ;; installation and graphical install.
228 ((installer-welcome-page current-installer)
229 #$(local-file "installer/aux-files/logo.txt")))))
231 ;; Ask the user to select a timezone under glibc format.
234 (description (G_ "Timezone"))
236 ((installer-timezone-page current-installer)
238 (configuration-formatter posix-tz->configuration))
240 ;; The installer runs in a kmscon virtual terminal where loadkeys
241 ;; won't work. kmscon uses libxkbcommon as a backend for keyboard
242 ;; input. It is possible to update kmscon current keymap by sending
243 ;; it a keyboard model, layout, variant and options, in a somehow
244 ;; similar way as what is done with setxkbmap utility.
246 ;; So ask for a keyboard model, layout and variant to update the
247 ;; current kmscon keymap. For non-Latin layouts, we add an
248 ;; appropriate second layout and toggle via Alt+Shift.
251 (description (G_ "Keyboard mapping selection"))
253 (#$(compute-keymap-step 'default)
255 (configuration-formatter keyboard-layout->configuration))
257 ;; Ask the user to input a hostname for the system.
260 (description (G_ "Hostname"))
262 ((installer-hostname-page current-installer))))
263 (configuration-formatter hostname->configuration))
265 ;; Provide an interface above connmanctl, so that the user can select
266 ;; a network susceptible to acces Internet.
269 (description (G_ "Network selection"))
271 ((installer-network-page current-installer)))))
273 ;; Ask whether to enable substitute server discovery.
276 (description (G_ "Substitute server discovery"))
278 ((installer-substitutes-page current-installer)))))
280 ;; Prompt for users (name, group and home directory).
283 (description (G_ "User creation"))
285 ((installer-user-page current-installer))))
286 (configuration-formatter users->configuration))
288 ;; Ask the user to choose one or many desktop environment(s).
291 (description (G_ "Services"))
293 ((installer-services-page current-installer))))
294 (configuration-formatter system-services->configuration))
296 ;; Run a partitioning tool allowing the user to modify
297 ;; partition tables, partitions and their mount points.
298 ;; Do this last so the user has something to boot if any
299 ;; of the previous steps didn't go as expected.
302 (description (G_ "Partitioning"))
304 ((installer-partition-page current-installer))))
305 (configuration-formatter user-partitions->configuration))
309 (description (G_ "Configuration file"))
311 (lambda (result prev-steps)
312 ((installer-final-page current-installer)
313 result prev-steps))))))))
315 (define (installer-program)
316 "Return a file-like object that runs the given INSTALLER."
318 ;; Initialize gettext support, so that installer messages can be
321 (bindtextdomain "guix" (string-append #$guix "/share/locale"))
323 (setlocale LC_ALL "")))
325 (define set-installer-path
326 ;; Add the specified binary to PATH for later use by the installer.
328 '#$(list bash ;start subshells
329 connman ;call connmanctl
345 (with-output-to-port (%make-void-port "w")
347 (set-path-environment-variable "PATH" '("bin" "sbin") inputs)))))
349 (define steps (installer-steps))
352 (string-append (current-source-directory) "/..")
355 (define installer-builder
356 ;; Note: Include GUIX as an extension to get all the (gnu system …), (gnu
357 ;; packages …), etc. modules.
358 (with-extensions (list guile-gcrypt guile-newt
359 guile-parted guile-bytestructures
360 guile-json-3 guile-git guile-webutils
362 (with-imported-modules `(,@(source-module-closure
366 #:select? module-to-import?)
367 ((guix config) => ,(make-config.scm)))
369 (use-modules (gnu installer record)
370 (gnu installer keymap)
371 (gnu installer steps)
373 (gnu installer final)
374 (gnu installer hostname)
375 (gnu installer locale)
376 (gnu installer parted)
377 (gnu installer services)
378 (gnu installer timezone)
380 (gnu installer utils)
382 ((gnu installer newt keymap)
383 #:select (keyboard-layout->configuration))
388 #:select (terminal-width))
390 (ice-9 textual-ports))
392 ;; Enable core dump generation.
393 (setrlimit 'core #f #f)
394 (call-with-output-file "/proc/sys/kernel/core_pattern"
396 (format port %core-dump)))
398 ;; Initialize gettext support so that installers can use
399 ;; (guix i18n) module.
402 ;; Add some binaries used by the installers to PATH.
405 ;; Arrange for language and territory name translations to be
406 ;; available. We need them at run time, not just compile time,
407 ;; because some territories have several corresponding languages
408 ;; (e.g., "French" is always displayed as "français", but
409 ;; "Belgium" could be translated to Dutch, French, or German.)
410 (bindtextdomain "iso_639-3" ;languages
411 #+(file-append iso-codes "/share/locale"))
412 (bindtextdomain "iso_3166-1" ;territories
413 #+(file-append iso-codes "/share/locale"))
415 ;; Likewise for XKB keyboard layout names.
416 (bindtextdomain "xkeyboard-config"
417 #+(file-append xkeyboard-config "/share/locale"))
419 ;; Initialize 'terminal-width' in (system repl debug)
420 ;; to a large-enough value to make backtrace more
424 (define current-installer newt-installer)
425 (define steps (#$steps current-installer))
428 (installer-init current-installer)
431 ((run-command-in-installer
432 (installer-run-command current-installer)))
437 #:rewind-strategy 'menu
438 #:menu-proc (installer-menu-page current-installer)
441 (match (result-step results 'final)
443 ;; We did it! Let's reboot!
445 (stop-service 'root))
447 ;; The installation failed, exit so that it is
448 ;; restarted by login.
452 (installer-log-line "crashing due to uncaught exception: ~s ~s"
455 (prepare-dump key args #:result %current-result))
457 ((installer-exit-error current-installer)
460 (string-append dump-dir "/installer-backtrace")))))
464 ((installer-dump-page current-installer)
467 (make-dump dump-dir dump-files)))
468 ((installer-report-page current-installer)
473 (installer-exit current-installer))))))
478 ;; Set the default locale to install unicode support. For
479 ;; some reason, unicode support is not correctly installed
480 ;; when calling this in 'installer-builder'.
481 (setenv "LANG" "en_US.UTF-8")
482 (execl #$(program-file "installer-real" installer-builder
483 #:guile guile-3.0-latest)