1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2018 Mathieu Othacehe <m.othacehe@gmail.com>
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 installer)
20 #:use-module (guix discovery)
21 #:use-module (guix packages)
22 #:use-module (guix gexp)
23 #:use-module (guix modules)
24 #:use-module (guix utils)
25 #:use-module (guix ui)
26 #:use-module ((guix self) #:select (make-config.scm))
27 #:use-module (gnu packages admin)
28 #:use-module (gnu packages base)
29 #:use-module (gnu packages bash)
30 #:use-module (gnu packages connman)
31 #:use-module (gnu packages cryptsetup)
32 #:use-module (gnu packages disk)
33 #:use-module (gnu packages guile)
34 #:use-module (gnu packages guile-xyz)
35 #:autoload (gnu packages gnupg) (guile-gcrypt)
36 #:use-module (gnu packages iso-codes)
37 #:use-module (gnu packages linux)
38 #:use-module (gnu packages ncurses)
39 #:use-module (gnu packages package-management)
40 #:use-module (gnu packages xorg)
41 #:use-module (ice-9 match)
42 #:use-module (srfi srfi-1)
43 #:export (installer-program))
46 ;; Select (guix …) and (gnu …) modules, except (guix config).
53 (define* (build-compiled-file name locale-builder)
54 "Return a file-like object that evalutes the gexp LOCALE-BUILDER and store
55 its result in the scheme file NAME. The derivation will also build a compiled
56 version of this file."
57 (define set-utf8-locale
60 #$(file-append glibc-utf8-locales "/lib/locale/"
62 (package-version glibc-utf8-locales))))
63 (setlocale LC_ALL "en_US.utf8")))
66 (with-extensions (list guile-json)
67 (with-imported-modules (source-module-closure
68 '((gnu installer locale)))
70 (use-modules (gnu installer locale))
72 ;; The locale files contain non-ASCII characters.
77 (string-append #$output "/" #$name ".scm"))
79 (string-append #$output "/" #$name ".go")))
80 (call-with-output-file locale-file
82 (write #$locale-builder port)))
83 (compile-file locale-file
84 #:output-file locale-compiled-file))))))
85 (computed-file name builder))
88 ;; Install the specified locale.
89 #~(lambda (locale-name)
91 (setlocale LC_ALL locale-name))))
93 (define* (compute-locale-step #:key
96 iso3166-territories-name)
97 "Return a gexp that run the locale-page of INSTALLER, and install the
98 selected locale. The list of locales, languages and territories passed to
99 locale-page are computed in derivations named respectively LOCALES-NAME,
100 ISO639-LANGUAGES-NAME and ISO3166-TERRITORIES-NAME. Those lists are compiled,
101 so that when the installer is run, all the lengthy operations have already
102 been performed at build time."
103 (define (compiled-file-loader file name)
105 (string-append #$file "/" #$name ".go")))
107 (let* ((supported-locales #~(supported-locales->locales
108 #$(local-file "installer/aux-files/SUPPORTED")))
109 (iso-codes #~(string-append #$iso-codes "/share/iso-codes/json/"))
110 (iso639-3 #~(string-append #$iso-codes "iso_639-3.json"))
111 (iso639-5 #~(string-append #$iso-codes "iso_639-5.json"))
112 (iso3166 #~(string-append #$iso-codes "iso_3166-1.json"))
113 (locales-file (build-compiled-file
115 #~`(quote ,#$supported-locales)))
116 (iso639-file (build-compiled-file
117 iso639-languages-name
118 #~`(quote ,(iso639->iso639-languages
120 #$iso639-3 #$iso639-5))))
121 (iso3166-file (build-compiled-file
122 iso3166-territories-name
123 #~`(quote ,(iso3166->iso3166-territories #$iso3166))))
124 (locales-loader (compiled-file-loader locales-file
126 (iso639-loader (compiled-file-loader iso639-file
127 iso639-languages-name))
128 (iso3166-loader (compiled-file-loader iso3166-file
129 iso3166-territories-name)))
130 #~(lambda (current-installer)
132 ((installer-locale-page current-installer)
133 #:supported-locales #$locales-loader
134 #:iso639-languages #$iso639-loader
135 #:iso3166-territories #$iso3166-loader)))
136 (#$apply-locale result)
140 ;; Apply the specified keymap. Use the default keyboard model.
143 (kmscon-update-keymap (default-keyboard-model)
146 (define* (compute-keymap-step)
147 "Return a gexp that runs the keymap-page of INSTALLER and install the
149 #~(lambda (current-installer)
153 (xkb-rules->models+layouts
154 (string-append #$xkeyboard-config
155 "/share/X11/xkb/rules/base.xml")))
156 (lambda (models layouts)
157 ((installer-keymap-page current-installer)
159 (#$apply-keymap result))))
161 (define (installer-steps)
162 (let ((locale-step (compute-locale-step
163 #:locales-name "locales"
164 #:iso639-languages-name "iso639-languages"
165 #:iso3166-territories-name "iso3166-territories"))
166 (keymap-step (compute-keymap-step))
167 (timezone-data #~(string-append #$tzdata
168 "/share/zoneinfo/zone.tab")))
169 #~(lambda (current-installer)
171 ;; Welcome the user and ask him to choose between manual
172 ;; installation and graphical install.
176 ((installer-welcome-page current-installer)
177 #$(local-file "installer/aux-files/logo.txt")))))
179 ;; Ask the user to choose a locale among those supported by
180 ;; the glibc. Install the selected locale right away, so that
181 ;; the user may benefit from any available translation for the
182 ;; installer messages.
185 (description (G_ "Locale"))
187 (#$locale-step current-installer)))
188 (configuration-formatter locale->configuration))
190 ;; Ask the user to select a timezone under glibc format.
193 (description (G_ "Timezone"))
195 ((installer-timezone-page current-installer)
197 (configuration-formatter posix-tz->configuration))
199 ;; The installer runs in a kmscon virtual terminal where loadkeys
200 ;; won't work. kmscon uses libxkbcommon as a backend for keyboard
201 ;; input. It is possible to update kmscon current keymap by sending it
202 ;; a keyboard model, layout and variant, in a somehow similar way as
203 ;; what is done with setxkbmap utility.
205 ;; So ask for a keyboard model, layout and variant to update the
206 ;; current kmscon keymap.
209 (description (G_ "Keyboard mapping selection"))
211 (#$keymap-step current-installer))))
213 ;; Run a partitioning tool allowing the user to modify
214 ;; partition tables, partitions and their mount points.
217 (description (G_ "Partitioning"))
219 ((installer-partition-page current-installer))))
220 (configuration-formatter user-partitions->configuration))
222 ;; Ask the user to input a hostname for the system.
225 (description (G_ "Hostname"))
227 ((installer-hostname-page current-installer))))
228 (configuration-formatter hostname->configuration))
230 ;; Provide an interface above connmanctl, so that the user can select
231 ;; a network susceptible to acces Internet.
234 (description (G_ "Network selection"))
236 ((installer-network-page current-installer)))))
238 ;; Prompt for users (name, group and home directory).
241 (description (G_ "User creation"))
243 ((installer-user-page current-installer))))
244 (configuration-formatter users->configuration))
246 ;; Ask the user to choose one or many desktop environment(s).
249 (description (G_ "Services"))
251 ((installer-services-page current-installer))))
252 (configuration-formatter
253 desktop-environments->configuration))
257 (description (G_ "Configuration file"))
259 (lambda (result prev-steps)
260 ((installer-final-page current-installer)
261 result prev-steps))))))))
263 (define (installer-program)
264 "Return a file-like object that runs the given INSTALLER."
266 ;; Initialize gettext support, so that installer messages can be
269 (bindtextdomain "guix" (string-append #$guix "/share/locale"))
270 (textdomain "guix")))
272 (define set-installer-path
273 ;; Add the specified binary to PATH for later use by the installer.
275 '#$(append (list bash ;start subshells
276 connman ;call connmanctl
281 guix ;guix system init call
284 (map canonical-package (list coreutils)))))
285 (with-output-to-port (%make-void-port "w")
287 (set-path-environment-variable "PATH" '("bin" "sbin") inputs)))))
289 (define steps (installer-steps))
292 (string-append (current-source-directory) "/..")
295 (define installer-builder
296 (with-extensions (list guile-gcrypt guile-newt
297 guile-parted guile-bytestructures
299 (with-imported-modules `(,@(source-module-closure
302 #:select? not-config?)
303 ((guix config) => ,(make-config.scm)))
305 (use-modules (gnu installer record)
306 (gnu installer keymap)
307 (gnu installer steps)
308 (gnu installer final)
309 (gnu installer hostname)
310 (gnu installer locale)
311 (gnu installer parted)
312 (gnu installer services)
313 (gnu installer timezone)
320 ;; Initialize gettext support so that installers can use
321 ;; (guix i18n) module.
324 ;; Add some binaries used by the installers to PATH.
327 (let* ((current-installer newt-installer)
328 (steps (#$steps current-installer)))
329 ((installer-init current-installer))
334 #:rewind-strategy 'menu
335 #:menu-proc (installer-menu-page current-installer)
339 (let ((error-file "/tmp/last-installer-error"))
340 (call-with-output-file error-file
342 (display-backtrace (make-stack #t) port)
343 (print-exception port
344 (stack-ref (make-stack #t) 1)
346 ((installer-exit-error current-installer)
347 error-file key args))
350 ((installer-exit current-installer)))))))
355 ;; Set the default locale to install unicode support. For
356 ;; some reason, unicode support is not correctly installed
357 ;; when calling this in 'installer-builder'.
358 (setenv "LANG" "en_US.UTF-8")
359 (system #$(program-file "installer-real" installer-builder)))))