linux-modules: Add 'load-pci-device-database'.
[jackhill/guix/guix.git] / gnu / installer / newt.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2018, 2020 Mathieu Othacehe <m.othacehe@gmail.com>
3 ;;;
4 ;;; This file is part of GNU Guix.
5 ;;;
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.
10 ;;;
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.
15 ;;;
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/>.
18
19 (define-module (gnu installer newt)
20 #:use-module (gnu installer record)
21 #:use-module (gnu installer utils)
22 #:use-module (gnu installer dump)
23 #:use-module (gnu installer newt ethernet)
24 #:use-module (gnu installer newt final)
25 #:use-module (gnu installer newt parameters)
26 #:use-module (gnu installer newt hostname)
27 #:use-module (gnu installer newt keymap)
28 #:use-module (gnu installer newt locale)
29 #:use-module (gnu installer newt menu)
30 #:use-module (gnu installer newt network)
31 #:use-module (gnu installer newt page)
32 #:use-module (gnu installer newt partition)
33 #:use-module (gnu installer newt services)
34 #:use-module (gnu installer newt substitutes)
35 #:use-module (gnu installer newt timezone)
36 #:use-module (gnu installer newt user)
37 #:use-module (gnu installer newt utils)
38 #:use-module (gnu installer newt welcome)
39 #:use-module (gnu installer newt wifi)
40 #:use-module (guix config)
41 #:use-module (guix discovery)
42 #:use-module (guix i18n)
43 #:use-module (srfi srfi-1)
44 #:use-module (srfi srfi-26)
45 #:use-module (srfi srfi-34)
46 #:use-module (srfi srfi-35)
47 #:use-module (ice-9 ftw)
48 #:use-module (ice-9 match)
49 #:use-module (newt)
50 #:export (newt-installer))
51
52 (define (init)
53 (newt-init)
54 (clear-screen)
55 (set-screen-size!)
56 (installer-log-line "Display is ~ax~a." (screen-columns) (screen-rows))
57 (push-help-line
58 (format #f (G_ "Press <F1> for installation parameters."))))
59
60 (define (exit)
61 (newt-finish)
62 (clear-screen))
63
64 (define (exit-error error)
65 ;; Newt may be suspended in the context of the "install-system"
66 ;; procedure. Resume it unconditionnally.
67 (newt-resume)
68 (newt-set-color COLORSET-ROOT "white" "red")
69 (define action
70 (run-textbox-page
71 #:info-text (G_ "The installer has encountered an unexpected problem. \
72 The backtrace is displayed below. You may choose to exit or create a dump \
73 archive.")
74 #:title (G_ "Unexpected problem")
75 #:content error
76 #:buttons-spec
77 (list
78 (cons (G_ "Dump") (const 'dump))
79 (cons (G_ "Exit") (const 'exit)))))
80 (newt-set-color COLORSET-ROOT "white" "blue")
81 action)
82
83 (define (report-page dump-archive)
84 (define text
85 (format #f (G_ "The dump archive was created as ~a. Would you like to \
86 send this archive to the Guix servers?") dump-archive))
87 (define title (G_ "Dump archive created"))
88 (when (run-confirmation-page text title)
89 (let* ((uploaded-name (send-dump-report dump-archive))
90 (text (if uploaded-name
91 (format #f (G_ "The dump was uploaded as ~a. Please \
92 report it by email to ~a.") uploaded-name %guix-bug-report-address)
93 (G_ "The dump could not be uploaded."))))
94 (run-error-page
95 text
96 (G_ "Dump upload result")))))
97
98 (define (dump-page dump-dir)
99 (define files
100 (scandir dump-dir (lambda (x)
101 (not (or (string=? x ".")
102 (string=? x ".."))))))
103 (fold (match-lambda*
104 (((file . enable?) acc)
105 (if enable?
106 (cons file acc)
107 acc)))
108 '()
109 (run-dump-page
110 dump-dir
111 (map (lambda (x)
112 (cons x #f))
113 files))))
114
115 (define (newt-run-command . args)
116 (define command-output "")
117 (define (line-accumulator line)
118 (set! command-output
119 (string-append/shared command-output line "\n")))
120 (define result (run-external-command-with-line-hooks (list line-accumulator)
121 args))
122 (define exit-val (status:exit-val result))
123 (define term-sig (status:term-sig result))
124 (define stop-sig (status:stop-sig result))
125
126 (if (and exit-val (zero? exit-val))
127 #t
128 (let ((info-text
129 (cond
130 (exit-val
131 (format #f (G_ "External command ~s exited with code ~a")
132 args exit-val))
133 (term-sig
134 (format #f (G_ "External command ~s terminated by signal ~a")
135 args term-sig))
136 (stop-sig
137 (format #f (G_ "External command ~s stopped by signal ~a")
138 args stop-sig)))))
139 (run-textbox-page #:title (G_ "External command error")
140 #:info-text info-text
141 #:content command-output
142 #:buttons-spec
143 (list
144 (cons "Ignore" (const #t))
145 (cons "Abort"
146 (lambda ()
147 (abort-to-prompt 'installer-step 'abort)))
148 (cons "Report"
149 (lambda ()
150 (raise
151 (condition
152 ((@@ (guix build utils)
153 &invoke-error)
154 (program (car args))
155 (arguments (cdr args))
156 (exit-status exit-val)
157 (term-signal term-sig)
158 (stop-signal stop-sig)))))))))))
159
160 (define (final-page result prev-steps)
161 (run-final-page result prev-steps))
162
163 (define* (locale-page #:key
164 supported-locales
165 iso639-languages
166 iso3166-territories)
167 (run-locale-page
168 #:supported-locales supported-locales
169 #:iso639-languages iso639-languages
170 #:iso3166-territories iso3166-territories))
171
172 (define (timezone-page zonetab)
173 (run-timezone-page zonetab))
174
175 (define (welcome-page logo)
176 (run-welcome-page logo))
177
178 (define (menu-page steps)
179 (run-menu-page steps))
180
181 (define* (keymap-page layouts context)
182 (run-keymap-page layouts #:context context))
183
184 (define (network-page)
185 (run-network-page))
186
187 (define (substitutes-page)
188 (run-substitutes-page))
189
190 (define (hostname-page)
191 (run-hostname-page))
192
193 (define (user-page)
194 (run-user-page))
195
196 (define (partition-page)
197 (run-partitioning-page))
198
199 (define (services-page)
200 (run-services-page))
201
202 (define (parameters-menu menu-proc)
203 (newt-set-help-callback menu-proc))
204
205 (define (parameters-page keyboard-layout-selection)
206 (run-parameters-page keyboard-layout-selection))
207
208 (define newt-installer
209 (installer
210 (name 'newt)
211 (init init)
212 (exit exit)
213 (exit-error exit-error)
214 (final-page final-page)
215 (keymap-page keymap-page)
216 (locale-page locale-page)
217 (menu-page menu-page)
218 (network-page network-page)
219 (substitutes-page substitutes-page)
220 (timezone-page timezone-page)
221 (hostname-page hostname-page)
222 (user-page user-page)
223 (partition-page partition-page)
224 (services-page services-page)
225 (welcome-page welcome-page)
226 (parameters-menu parameters-menu)
227 (parameters-page parameters-page)
228 (dump-page dump-page)
229 (run-command newt-run-command)
230 (report-page report-page)))