gnu: csound: Update to 6.16.2.
[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-set-color COLORSET-ROOT "white" "red")
66 (define action
67 (run-textbox-page
68 #:info-text (G_ "The installer has encountered an unexpected problem. \
69 The backtrace is displayed below. You may choose to exit or create a dump \
70 archive.")
71 #:title (G_ "Unexpected problem")
72 #:content error
73 #:buttons-spec
74 (list
75 (cons (G_ "Dump") (const 'dump))
76 (cons (G_ "Exit") (const 'exit)))))
77 (newt-set-color COLORSET-ROOT "white" "blue")
78 action)
79
80 (define (report-page dump-archive)
81 (define text
82 (format #f (G_ "The dump archive was created as ~a. Would you like to \
83 send this archive to the Guix servers?") dump-archive))
84 (define title (G_ "Dump archive created"))
85 (when (run-confirmation-page text title)
86 (let* ((uploaded-name (send-dump-report dump-archive))
87 (text (if uploaded-name
88 (format #f (G_ "The dump was uploaded as ~a. Please \
89 report it by email to ~a.") uploaded-name %guix-bug-report-address)
90 (G_ "The dump could not be uploaded."))))
91 (run-error-page
92 text
93 (G_ "Dump upload result")))))
94
95 (define (dump-page dump-dir)
96 (define files
97 (scandir dump-dir (lambda (x)
98 (not (or (string=? x ".")
99 (string=? x ".."))))))
100 (fold (match-lambda*
101 (((file . enable?) acc)
102 (if enable?
103 (cons file acc)
104 acc)))
105 '()
106 (run-dump-page
107 dump-dir
108 (map (lambda (x)
109 (cons x #f))
110 files))))
111
112 (define (newt-run-command . args)
113 (define command-output "")
114 (define (line-accumulator line)
115 (set! command-output
116 (string-append/shared command-output line "\n")))
117 (define displayed-command
118 (string-join
119 (map (lambda (s) (string-append "\"" s "\"")) args)
120 " "))
121 (define result (run-external-command-with-line-hooks (list line-accumulator)
122 args))
123 (define exit-val (status:exit-val result))
124 (define term-sig (status:term-sig result))
125 (define stop-sig (status:stop-sig result))
126
127 (if (and exit-val (zero? exit-val))
128 #t
129 (let ((info-text
130 (cond
131 (exit-val
132 (format #f (G_ "External command ~s exited with code ~a")
133 args exit-val))
134 (term-sig
135 (format #f (G_ "External command ~s terminated by signal ~a")
136 args term-sig))
137 (stop-sig
138 (format #f (G_ "External command ~s stopped by signal ~a")
139 args stop-sig)))))
140 (run-textbox-page #:title (G_ "External command error")
141 #:info-text info-text
142 #:content command-output
143 #:buttons-spec
144 (list
145 (cons "Ignore" (const #t))
146 (cons "Abort"
147 (lambda ()
148 (abort-to-prompt 'installer-step 'abort)))
149 (cons "Report"
150 (lambda ()
151 (raise
152 (condition
153 ((@@ (guix build utils)
154 &invoke-error)
155 (program (car args))
156 (arguments (cdr args))
157 (exit-status exit-val)
158 (term-signal term-sig)
159 (stop-signal stop-sig)))))))))))
160
161 (define (final-page result prev-steps)
162 (run-final-page result prev-steps))
163
164 (define* (locale-page #:key
165 supported-locales
166 iso639-languages
167 iso3166-territories)
168 (run-locale-page
169 #:supported-locales supported-locales
170 #:iso639-languages iso639-languages
171 #:iso3166-territories iso3166-territories))
172
173 (define (timezone-page zonetab)
174 (run-timezone-page zonetab))
175
176 (define (welcome-page logo)
177 (run-welcome-page logo))
178
179 (define (menu-page steps)
180 (run-menu-page steps))
181
182 (define* (keymap-page layouts context)
183 (run-keymap-page layouts #:context context))
184
185 (define (network-page)
186 (run-network-page))
187
188 (define (substitutes-page)
189 (run-substitutes-page))
190
191 (define (hostname-page)
192 (run-hostname-page))
193
194 (define (user-page)
195 (run-user-page))
196
197 (define (partition-page)
198 (run-partitioning-page))
199
200 (define (services-page)
201 (run-services-page))
202
203 (define (parameters-menu menu-proc)
204 (newt-set-help-callback menu-proc))
205
206 (define (parameters-page keyboard-layout-selection)
207 (run-parameters-page keyboard-layout-selection))
208
209 (define newt-installer
210 (installer
211 (name 'newt)
212 (init init)
213 (exit exit)
214 (exit-error exit-error)
215 (final-page final-page)
216 (keymap-page keymap-page)
217 (locale-page locale-page)
218 (menu-page menu-page)
219 (network-page network-page)
220 (substitutes-page substitutes-page)
221 (timezone-page timezone-page)
222 (hostname-page hostname-page)
223 (user-page user-page)
224 (partition-page partition-page)
225 (services-page services-page)
226 (welcome-page welcome-page)
227 (parameters-menu parameters-menu)
228 (parameters-page parameters-page)
229 (dump-page dump-page)
230 (run-command newt-run-command)
231 (report-page report-page)))