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 #:autoload (gnu packages gnupg) (guile-gcrypt)
35 #:use-module (gnu packages iso-codes)
36 #:use-module (gnu packages linux)
37 #:use-module (gnu packages ncurses)
38 #:use-module (gnu packages package-management)
39 #:use-module (gnu packages xorg)
40 #:use-module (ice-9 match)
41 #:use-module (srfi srfi-1)
42 #:export (installer-program))
45 ;; Select (guix …) and (gnu …) modules, except (guix config).
52 (define* (build-compiled-file name locale-builder)
53 "Return a file-like object that evalutes the gexp LOCALE-BUILDER and store
54 its result in the scheme file NAME. The derivation will also build a compiled
55 version of this file."
56 (define set-utf8-locale
59 #$(file-append glibc-utf8-locales "/lib/locale/"
61 (package-version glibc-utf8-locales))))
62 (setlocale LC_ALL "en_US.utf8")))
65 (with-extensions (list guile-json)
66 (with-imported-modules (source-module-closure
67 '((gnu installer locale)))
69 (use-modules (gnu installer locale))
71 ;; The locale files contain non-ASCII characters.
76 (string-append #$output "/" #$name ".scm"))
78 (string-append #$output "/" #$name ".go")))
79 (call-with-output-file locale-file
81 (write #$locale-builder port)))
82 (compile-file locale-file
83 #:output-file locale-compiled-file))))))
84 (computed-file name builder))
87 ;; Install the specified locale.
88 #~(lambda (locale-name)
90 (setlocale LC_ALL locale-name))))
92 (define* (compute-locale-step #:key
95 iso3166-territories-name)
96 "Return a gexp that run the locale-page of INSTALLER, and install the
97 selected locale. The list of locales, languages and territories passed to
98 locale-page are computed in derivations named respectively LOCALES-NAME,
99 ISO639-LANGUAGES-NAME and ISO3166-TERRITORIES-NAME. Those lists are compiled,
100 so that when the installer is run, all the lengthy operations have already
101 been performed at build time."
102 (define (compiled-file-loader file name)
104 (string-append #$file "/" #$name ".go")))
106 (let* ((supported-locales #~(supported-locales->locales
107 #$(local-file "installer/aux-files/SUPPORTED")))
108 (iso-codes #~(string-append #$iso-codes "/share/iso-codes/json/"))
109 (iso639-3 #~(string-append #$iso-codes "iso_639-3.json"))
110 (iso639-5 #~(string-append #$iso-codes "iso_639-5.json"))
111 (iso3166 #~(string-append #$iso-codes "iso_3166-1.json"))
112 (locales-file (build-compiled-file
114 #~`(quote ,#$supported-locales)))
115 (iso639-file (build-compiled-file
116 iso639-languages-name
117 #~`(quote ,(iso639->iso639-languages
119 #$iso639-3 #$iso639-5))))
120 (iso3166-file (build-compiled-file
121 iso3166-territories-name
122 #~`(quote ,(iso3166->iso3166-territories #$iso3166))))
123 (locales-loader (compiled-file-loader locales-file
125 (iso639-loader (compiled-file-loader iso639-file
126 iso639-languages-name))
127 (iso3166-loader (compiled-file-loader iso3166-file
128 iso3166-territories-name)))
129 #~(lambda (current-installer)
131 ((installer-locale-page current-installer)
132 #:supported-locales #$locales-loader
133 #:iso639-languages #$iso639-loader
134 #:iso3166-territories #$iso3166-loader)))
135 (#$apply-locale result)
139 ;; Apply the specified keymap. Use the default keyboard model.
142 (kmscon-update-keymap (default-keyboard-model)
145 (define* (compute-keymap-step)
146 "Return a gexp that runs the keymap-page of INSTALLER and install the
148 #~(lambda (current-installer)
152 (xkb-rules->models+layouts
153 (string-append #$xkeyboard-config
154 "/share/X11/xkb/rules/base.xml")))
155 (lambda (models layouts)
156 ((installer-keymap-page current-installer)
158 (#$apply-keymap result))))
160 (define (installer-steps)
161 (let ((locale-step (compute-locale-step
162 #:locales-name "locales"
163 #:iso639-languages-name "iso639-languages"
164 #:iso3166-territories-name "iso3166-territories"))
165 (keymap-step (compute-keymap-step))
166 (timezone-data #~(string-append #$tzdata
167 "/share/zoneinfo/zone.tab")))
168 #~(lambda (current-installer)
170 ;; Welcome the user and ask him to choose between manual
171 ;; installation and graphical install.
175 ((installer-welcome-page current-installer)
176 #$(local-file "installer/aux-files/logo.txt")))))
178 ;; Ask the user to choose a locale among those supported by
179 ;; the glibc. Install the selected locale right away, so that
180 ;; the user may benefit from any available translation for the
181 ;; installer messages.
184 (description (G_ "Locale"))
186 (#$locale-step current-installer)))
187 (configuration-formatter locale->configuration))
189 ;; Ask the user to select a timezone under glibc format.
192 (description (G_ "Timezone"))
194 ((installer-timezone-page current-installer)
196 (configuration-formatter posix-tz->configuration))
198 ;; The installer runs in a kmscon virtual terminal where loadkeys
199 ;; won't work. kmscon uses libxkbcommon as a backend for keyboard
200 ;; input. It is possible to update kmscon current keymap by sending it
201 ;; a keyboard model, layout and variant, in a somehow similar way as
202 ;; what is done with setxkbmap utility.
204 ;; So ask for a keyboard model, layout and variant to update the
205 ;; current kmscon keymap.
208 (description (G_ "Keyboard mapping selection"))
210 (#$keymap-step current-installer))))
212 ;; Run a partitioning tool allowing the user to modify
213 ;; partition tables, partitions and their mount points.
216 (description (G_ "Partitioning"))
218 ((installer-partition-page current-installer))))
219 (configuration-formatter user-partitions->configuration))
221 ;; Ask the user to input a hostname for the system.
224 (description (G_ "Hostname"))
226 ((installer-hostname-page current-installer))))
227 (configuration-formatter hostname->configuration))
229 ;; Provide an interface above connmanctl, so that the user can select
230 ;; a network susceptible to acces Internet.
233 (description (G_ "Network selection"))
235 ((installer-network-page current-installer)))))
237 ;; Prompt for users (name, group and home directory).
240 (description (G_ "User creation"))
242 ((installer-user-page current-installer))))
243 (configuration-formatter users->configuration))
245 ;; Ask the user to choose one or many desktop environment(s).
248 (description (G_ "Services"))
250 ((installer-services-page current-installer))))
251 (configuration-formatter
252 desktop-environments->configuration))
256 (description (G_ "Configuration file"))
258 (lambda (result prev-steps)
259 ((installer-final-page current-installer)
260 result prev-steps))))))))
262 (define (installer-program)
263 "Return a file-like object that runs the given INSTALLER."
265 ;; Initialize gettext support, so that installer messages can be
268 (bindtextdomain "guix" (string-append #$guix "/share/locale"))
269 (textdomain "guix")))
271 (define set-installer-path
272 ;; Add the specified binary to PATH for later use by the installer.
274 '#$(append (list bash ;start subshells
275 connman ;call connmanctl
280 guix ;guix system init call
283 (map canonical-package (list coreutils)))))
284 (with-output-to-port (%make-void-port "w")
286 (set-path-environment-variable "PATH" '("bin" "sbin") inputs)))))
288 (define steps (installer-steps))
291 (string-append (current-source-directory) "/..")
294 (define installer-builder
295 (with-extensions (list guile-gcrypt guile-newt
296 guile-parted guile-bytestructures
298 (with-imported-modules `(,@(source-module-closure
301 #:select? not-config?)
302 ((guix config) => ,(make-config.scm)))
304 (use-modules (gnu installer record)
305 (gnu installer keymap)
306 (gnu installer steps)
307 (gnu installer final)
308 (gnu installer hostname)
309 (gnu installer locale)
310 (gnu installer parted)
311 (gnu installer services)
312 (gnu installer timezone)
319 ;; Initialize gettext support so that installers can use
320 ;; (guix i18n) module.
323 ;; Add some binaries used by the installers to PATH.
326 (let* ((current-installer newt-installer)
327 (steps (#$steps current-installer)))
328 ((installer-init current-installer))
333 #:rewind-strategy 'menu
334 #:menu-proc (installer-menu-page current-installer)
338 (let ((error-file "/tmp/last-installer-error"))
339 (call-with-output-file error-file
341 (display-backtrace (make-stack #t) port)
342 (print-exception port
343 (stack-ref (make-stack #t) 1)
345 ((installer-exit-error current-installer)
346 error-file key args))
349 ((installer-exit current-installer)))))))
354 ;; Set the default locale to install unicode support. For
355 ;; some reason, unicode support is not correctly installed
356 ;; when calling this in 'installer-builder'.
357 (setenv "LANG" "en_US.UTF-8")
358 (system #$(program-file "installer-real" installer-builder)))))