1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2018, 2020 Mathieu Othacehe <m.othacehe@gmail.com>
3 ;;; Copyright © 2019, 2020 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 connman)
37 #:use-module (gnu packages cryptsetup)
38 #:use-module (gnu packages disk)
39 #:use-module (gnu packages file-systems)
40 #:use-module (gnu packages guile)
41 #:use-module (gnu packages guile-xyz)
42 #:autoload (gnu packages gnupg) (guile-gcrypt)
43 #:use-module (gnu packages iso-codes)
44 #:use-module (gnu packages linux)
45 #:use-module (gnu packages ncurses)
46 #:use-module (gnu packages package-management)
47 #:use-module (gnu packages xorg)
48 #:use-module (gnu system locale)
49 #:use-module (ice-9 match)
50 #:use-module (srfi srfi-1)
51 #:export (installer-program))
53 (define module-to-import?
54 ;; Return true for modules that should be imported. For (gnu system …) and
55 ;; (gnu packages …) modules, we simply add the whole 'guix' package via
56 ;; 'with-extensions' (to avoid having to rebuild it all), which is why these
57 ;; modules are excluded here.
60 (('gnu 'installer _ ...) #t)
61 (('gnu 'build _ ...) #t)
62 (('guix 'build _ ...) #t)
66 ;; Select (guix …) and (gnu …) modules, except (guix config).
73 (define* (build-compiled-file name locale-builder)
74 "Return a file-like object that evalutes the gexp LOCALE-BUILDER and store
75 its result in the scheme file NAME. The derivation will also build a compiled
76 version of this file."
77 (define set-utf8-locale
80 #$(file-append glibc-utf8-locales "/lib/locale/"
82 (package-version glibc-utf8-locales))))
83 (setlocale LC_ALL "en_US.utf8")))
86 (with-extensions (list guile-json-3)
87 (with-imported-modules `(,@(source-module-closure
88 '((gnu installer locale))
89 #:select? not-config?)
90 ((guix config) => ,(make-config.scm)))
92 (use-modules (gnu installer locale))
94 ;; The locale files contain non-ASCII characters.
99 (string-append #$output "/" #$name ".scm"))
100 (locale-compiled-file
101 (string-append #$output "/" #$name ".go")))
102 (call-with-output-file locale-file
104 (write #$locale-builder port)))
105 (compile-file locale-file
106 #:output-file locale-compiled-file))))))
107 (computed-file name builder))
110 ;; Install the specified locale.
111 (with-imported-modules (source-module-closure '((gnu services herd)))
114 (setlocale LC_ALL locale))
116 ;; Restart the documentation viewer so it displays the manual in
117 ;; language that corresponds to LOCALE. Make sure that nothing is
118 ;; printed on the console.
119 (parameterize ((shepherd-message-port
120 (%make-void-port "w")))
121 (stop-service 'term-tty2)
122 (start-service 'term-tty2 (list locale))))))
124 (define* (compute-locale-step #:key
126 iso639-languages-name
127 iso3166-territories-name)
128 "Return a gexp that run the locale-page of INSTALLER, and install the
129 selected locale. The list of locales, languages and territories passed to
130 locale-page are computed in derivations named respectively LOCALES-NAME,
131 ISO639-LANGUAGES-NAME and ISO3166-TERRITORIES-NAME. Those lists are compiled,
132 so that when the installer is run, all the lengthy operations have already
133 been performed at build time."
134 (define (compiled-file-loader file name)
136 (string-append #$file "/" #$name ".go")))
138 (let* ((supported-locales #~(supported-locales->locales
139 #+(glibc-supported-locales)))
140 (iso-codes #~(string-append #$iso-codes "/share/iso-codes/json/"))
141 (iso639-3 #~(string-append #$iso-codes "iso_639-3.json"))
142 (iso639-5 #~(string-append #$iso-codes "iso_639-5.json"))
143 (iso3166 #~(string-append #$iso-codes "iso_3166-1.json"))
144 (locales-file (build-compiled-file
146 #~`(quote ,#$supported-locales)))
147 (iso639-file (build-compiled-file
148 iso639-languages-name
149 #~`(quote ,(iso639->iso639-languages
151 #$iso639-3 #$iso639-5))))
152 (iso3166-file (build-compiled-file
153 iso3166-territories-name
154 #~`(quote ,(iso3166->iso3166-territories #$iso3166))))
155 (locales-loader (compiled-file-loader locales-file
157 (iso639-loader (compiled-file-loader iso639-file
158 iso639-languages-name))
159 (iso3166-loader (compiled-file-loader iso3166-file
160 iso3166-territories-name)))
161 #~(lambda (current-installer)
163 ((installer-locale-page current-installer)
164 #:supported-locales #$locales-loader
165 #:iso639-languages #$iso639-loader
166 #:iso3166-territories #$iso3166-loader)))
167 (#$apply-locale result)
171 ;; Apply the specified keymap. Use the default keyboard model.
173 ((layout variant options)
174 (kmscon-update-keymap (default-keyboard-model)
175 layout variant options))))
177 (define* (compute-keymap-step context)
178 "Return a gexp that runs the keymap-page of INSTALLER and install the
180 #~(lambda (current-installer)
184 (xkb-rules->models+layouts
185 (string-append #$xkeyboard-config
186 "/share/X11/xkb/rules/base.xml")))
187 (lambda (models layouts)
188 ((installer-keymap-page current-installer)
189 layouts '#$context)))))
190 (#$apply-keymap result)
193 (define (installer-steps)
194 (let ((locale-step (compute-locale-step
195 #:locales-name "locales"
196 #:iso639-languages-name "iso639-languages"
197 #:iso3166-territories-name "iso3166-territories"))
198 (timezone-data #~(string-append #$tzdata
199 "/share/zoneinfo/zone.tab")))
200 #~(lambda (current-installer)
201 ((installer-parameters-menu current-installer)
203 ((installer-parameters-page current-installer)
205 (#$(compute-keymap-step 'param)
206 current-installer)))))
208 ;; Ask the user to choose a locale among those supported by
209 ;; the glibc. Install the selected locale right away, so that
210 ;; the user may benefit from any available translation for the
211 ;; installer messages.
214 (description (G_ "Locale"))
216 (#$locale-step current-installer)))
217 (configuration-formatter locale->configuration))
219 ;; Welcome the user and ask them to choose between manual
220 ;; installation and graphical install.
224 ((installer-welcome-page current-installer)
225 #$(local-file "installer/aux-files/logo.txt")))))
227 ;; Ask the user to select a timezone under glibc format.
230 (description (G_ "Timezone"))
232 ((installer-timezone-page current-installer)
234 (configuration-formatter posix-tz->configuration))
236 ;; The installer runs in a kmscon virtual terminal where loadkeys
237 ;; won't work. kmscon uses libxkbcommon as a backend for keyboard
238 ;; input. It is possible to update kmscon current keymap by sending
239 ;; it a keyboard model, layout, variant and options, in a somehow
240 ;; similar way as what is done with setxkbmap utility.
242 ;; So ask for a keyboard model, layout and variant to update the
243 ;; current kmscon keymap. For non-Latin layouts, we add an
244 ;; appropriate second layout and toggle via Alt+Shift.
247 (description (G_ "Keyboard mapping selection"))
249 (#$(compute-keymap-step 'default)
251 (configuration-formatter keyboard-layout->configuration))
253 ;; Ask the user to input a hostname for the system.
256 (description (G_ "Hostname"))
258 ((installer-hostname-page current-installer))))
259 (configuration-formatter hostname->configuration))
261 ;; Provide an interface above connmanctl, so that the user can select
262 ;; a network susceptible to acces Internet.
265 (description (G_ "Network selection"))
267 ((installer-network-page current-installer)))))
269 ;; Prompt for users (name, group and home directory).
272 (description (G_ "User creation"))
274 ((installer-user-page current-installer))))
275 (configuration-formatter users->configuration))
277 ;; Ask the user to choose one or many desktop environment(s).
280 (description (G_ "Services"))
282 ((installer-services-page current-installer))))
283 (configuration-formatter system-services->configuration))
285 ;; Run a partitioning tool allowing the user to modify
286 ;; partition tables, partitions and their mount points.
287 ;; Do this last so the user has something to boot if any
288 ;; of the previous steps didn't go as expected.
291 (description (G_ "Partitioning"))
293 ((installer-partition-page current-installer))))
294 (configuration-formatter user-partitions->configuration))
298 (description (G_ "Configuration file"))
300 (lambda (result prev-steps)
301 ((installer-final-page current-installer)
302 result prev-steps))))))))
304 (define (installer-program)
305 "Return a file-like object that runs the given INSTALLER."
307 ;; Initialize gettext support, so that installer messages can be
310 (bindtextdomain "guix" (string-append #$guix "/share/locale"))
311 (textdomain "guix")))
313 (define set-installer-path
314 ;; Add the specified binary to PATH for later use by the installer.
316 '#$(list bash ;start subshells
317 connman ;call connmanctl
324 guix ;guix system init call
328 (with-output-to-port (%make-void-port "w")
330 (set-path-environment-variable "PATH" '("bin" "sbin") inputs)))))
332 (define steps (installer-steps))
335 (string-append (current-source-directory) "/..")
338 (define installer-builder
339 ;; Note: Include GUIX as an extension to get all the (gnu system …), (gnu
340 ;; packages …), etc. modules.
341 (with-extensions (list guile-gcrypt guile-newt
342 guile-parted guile-bytestructures
343 guile-json-3 guile-git guix)
344 (with-imported-modules `(,@(source-module-closure
348 #:select? module-to-import?)
349 ((guix config) => ,(make-config.scm)))
351 (use-modules (gnu installer record)
352 (gnu installer keymap)
353 (gnu installer steps)
354 (gnu installer final)
355 (gnu installer hostname)
356 (gnu installer locale)
357 (gnu installer parted)
358 (gnu installer services)
359 (gnu installer timezone)
361 (gnu installer utils)
363 ((gnu installer newt keymap)
364 #:select (keyboard-layout->configuration))
369 #:select (terminal-width))
372 ;; Initialize gettext support so that installers can use
373 ;; (guix i18n) module.
376 ;; Add some binaries used by the installers to PATH.
379 ;; Arrange for language and territory name translations to be
380 ;; available. We need them at run time, not just compile time,
381 ;; because some territories have several corresponding languages
382 ;; (e.g., "French" is always displayed as "français", but
383 ;; "Belgium" could be translated to Dutch, French, or German.)
384 (bindtextdomain "iso_639-3" ;languages
385 #+(file-append iso-codes "/share/locale"))
386 (bindtextdomain "iso_3166-1" ;territories
387 #+(file-append iso-codes "/share/locale"))
389 ;; Likewise for XKB keyboard layout names.
390 (bindtextdomain "xkeyboard-config"
391 #+(file-append xkeyboard-config "/share/locale"))
393 ;; Initialize 'terminal-width' in (system repl debug)
394 ;; to a large-enough value to make backtrace more
398 (let* ((current-installer newt-installer)
399 (steps (#$steps current-installer)))
400 ((installer-init current-installer))
406 #:rewind-strategy 'menu
407 #:menu-proc (installer-menu-page current-installer)
410 (match (result-step results 'final)
412 ;; We did it! Let's reboot!
414 (stop-service 'root))
416 ;; The installation failed, exit so that it is restarted
421 (syslog "crashing due to uncaught exception: ~s ~s~%"
423 (let ((error-file "/tmp/last-installer-error"))
424 (call-with-output-file error-file
426 (display-backtrace (make-stack #t) port)
427 (print-exception port
428 (stack-ref (make-stack #t) 1)
430 ((installer-exit-error current-installer)
431 error-file key args))
434 ((installer-exit current-installer)))))))
439 ;; Set the default locale to install unicode support. For
440 ;; some reason, unicode support is not correctly installed
441 ;; when calling this in 'installer-builder'.
442 (setenv "LANG" "en_US.UTF-8")
443 (execl #$(program-file "installer-real" installer-builder)