linux-modules: Add 'load-pci-device-database'.
[jackhill/guix/guix.git] / gnu / installer / newt.scm
CommitLineData
d0f3a672 1;;; GNU Guix --- Functional package management for GNU
786c9c39 2;;; Copyright © 2018, 2020 Mathieu Othacehe <m.othacehe@gmail.com>
d0f3a672
MO
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)
a49d633c 20 #:use-module (gnu installer record)
133c401f 21 #:use-module (gnu installer utils)
ad55ccf9 22 #:use-module (gnu installer dump)
a49d633c 23 #:use-module (gnu installer newt ethernet)
dc5f3275 24 #:use-module (gnu installer newt final)
07a53bd5 25 #:use-module (gnu installer newt parameters)
a49d633c
MO
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)
133c401f 31 #:use-module (gnu installer newt page)
69a934f2 32 #:use-module (gnu installer newt partition)
b51bde71 33 #:use-module (gnu installer newt services)
8361817b 34 #:use-module (gnu installer newt substitutes)
a49d633c
MO
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)
133c401f 40 #:use-module (guix config)
d0f3a672 41 #:use-module (guix discovery)
a49d633c 42 #:use-module (guix i18n)
ad55ccf9 43 #:use-module (srfi srfi-1)
a49d633c 44 #:use-module (srfi srfi-26)
7cbd95a9
JP
45 #:use-module (srfi srfi-34)
46 #:use-module (srfi srfi-35)
ad55ccf9
JP
47 #:use-module (ice-9 ftw)
48 #:use-module (ice-9 match)
a49d633c 49 #:use-module (newt)
d0f3a672
MO
50 #:export (newt-installer))
51
a49d633c
MO
52(define (init)
53 (newt-init)
54 (clear-screen)
786c9c39 55 (set-screen-size!)
4f2fd33b 56 (installer-log-line "Display is ~ax~a." (screen-columns) (screen-rows))
786c9c39 57 (push-help-line
07a53bd5 58 (format #f (G_ "Press <F1> for installation parameters."))))
d0f3a672 59
a49d633c 60(define (exit)
df3664f1
MO
61 (newt-finish)
62 (clear-screen))
d0f3a672 63
ad55ccf9 64(define (exit-error error)
bf5e78d5
MO
65 ;; Newt may be suspended in the context of the "install-system"
66 ;; procedure. Resume it unconditionnally.
67 (newt-resume)
133c401f 68 (newt-set-color COLORSET-ROOT "white" "red")
ad55ccf9
JP
69 (define action
70 (run-textbox-page
71 #:info-text (G_ "The installer has encountered an unexpected problem. \
72The backtrace is displayed below. You may choose to exit or create a dump \
73archive.")
133c401f 74 #:title (G_ "Unexpected problem")
ad55ccf9
JP
75 #:content error
76 #:buttons-spec
77 (list
78 (cons (G_ "Dump") (const 'dump))
79 (cons (G_ "Exit") (const 'exit)))))
133c401f 80 (newt-set-color COLORSET-ROOT "white" "blue")
ad55ccf9
JP
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 \
86send 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 \
92report 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))))
d0f3a672 114
408427a3 115(define (newt-run-command . args)
7cbd95a9
JP
116 (define command-output "")
117 (define (line-accumulator line)
118 (set! command-output
119 (string-append/shared command-output line "\n")))
7cbd95a9
JP
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)))
ad55ccf9 148 (cons "Report"
7cbd95a9
JP
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)))))))))))
408427a3 159
dc5f3275
MO
160(define (final-page result prev-steps)
161 (run-final-page result prev-steps))
162
a49d633c
MO
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))
d0f3a672 171
a49d633c
MO
172(define (timezone-page zonetab)
173 (run-timezone-page zonetab))
d0f3a672 174
a49d633c
MO
175(define (welcome-page logo)
176 (run-welcome-page logo))
d0f3a672 177
a49d633c
MO
178(define (menu-page steps)
179 (run-menu-page steps))
d0f3a672 180
786c9c39
MO
181(define* (keymap-page layouts context)
182 (run-keymap-page layouts #:context context))
d0f3a672 183
a49d633c
MO
184(define (network-page)
185 (run-network-page))
d0f3a672 186
8361817b
MO
187(define (substitutes-page)
188 (run-substitutes-page))
189
a49d633c
MO
190(define (hostname-page)
191 (run-hostname-page))
d0f3a672 192
a49d633c
MO
193(define (user-page)
194 (run-user-page))
d0f3a672 195
69a934f2 196(define (partition-page)
5e17ae7f 197 (run-partitioning-page))
69a934f2 198
b51bde71
MO
199(define (services-page)
200 (run-services-page))
201
07a53bd5 202(define (parameters-menu menu-proc)
786c9c39
MO
203 (newt-set-help-callback menu-proc))
204
07a53bd5
MO
205(define (parameters-page keyboard-layout-selection)
206 (run-parameters-page keyboard-layout-selection))
786c9c39 207
d0f3a672
MO
208(define newt-installer
209 (installer
210 (name 'newt)
d0f3a672
MO
211 (init init)
212 (exit exit)
213 (exit-error exit-error)
dc5f3275 214 (final-page final-page)
d0f3a672
MO
215 (keymap-page keymap-page)
216 (locale-page locale-page)
217 (menu-page menu-page)
218 (network-page network-page)
8361817b 219 (substitutes-page substitutes-page)
d0f3a672
MO
220 (timezone-page timezone-page)
221 (hostname-page hostname-page)
222 (user-page user-page)
69a934f2 223 (partition-page partition-page)
b51bde71 224 (services-page services-page)
786c9c39 225 (welcome-page welcome-page)
07a53bd5 226 (parameters-menu parameters-menu)
0d37a5df 227 (parameters-page parameters-page)
408427a3 228 (dump-page dump-page)
ad55ccf9
JP
229 (run-command newt-run-command)
230 (report-page report-page)))