welcome.scm 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2018 Mathieu Othacehe <m.othacehe@gmail.com>
  3. ;;; Copyright © 2020, 2022 Ludovic Courtès <ludo@gnu.org>
  4. ;;; Copyright © 2022 Florian Pelz <pelzflorian@pelzflorian.de>
  5. ;;;
  6. ;;; This file is part of GNU Guix.
  7. ;;;
  8. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  9. ;;; under the terms of the GNU General Public License as published by
  10. ;;; the Free Software Foundation; either version 3 of the License, or (at
  11. ;;; your option) any later version.
  12. ;;;
  13. ;;; GNU Guix is distributed in the hope that it will be useful, but
  14. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;;;
  17. ;;; You should have received a copy of the GNU General Public License
  18. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  19. (define-module (gnu installer newt welcome)
  20. #:use-module ((gnu build linux-modules)
  21. #:select (modules-loaded
  22. pci-devices))
  23. #:use-module (gnu installer dump)
  24. #:use-module (gnu installer hardware)
  25. #:use-module (gnu installer steps)
  26. #:use-module (gnu installer utils)
  27. #:use-module (gnu installer newt page)
  28. #:use-module (gnu installer newt utils)
  29. #:use-module (guix build syscalls)
  30. #:use-module (guix i18n)
  31. #:use-module (srfi srfi-1)
  32. #:use-module (srfi srfi-34)
  33. #:use-module (srfi srfi-35)
  34. #:use-module (srfi srfi-71)
  35. #:use-module (ice-9 format)
  36. #:use-module (ice-9 match)
  37. #:use-module (ice-9 receive)
  38. #:use-module (newt)
  39. #:export (run-welcome-page))
  40. ;; Expected width and height for the logo.
  41. (define logo-width (make-parameter 43))
  42. (define logo-height (make-parameter 19))
  43. (define info-textbox-width (make-parameter 70))
  44. (define options-listbox-height (make-parameter 5))
  45. (define (display-logo?)
  46. (> (screen-rows) 35))
  47. (define* (run-menu-page title info-text logo
  48. #:key
  49. listbox-items
  50. listbox-item->text)
  51. "Run a page with the given TITLE, to ask the user to choose between
  52. LISTBOX-ITEMS displayed in a listbox. The listbox items are converted to text
  53. using LISTBOX-ITEM->TEXT procedure. Display the textual LOGO in the center of
  54. the page. Contrary to other pages, we cannot resort to grid layouts, because
  55. we want this page to occupy all the screen space available."
  56. (define (fill-listbox listbox items)
  57. (map (lambda (item)
  58. (let* ((text (listbox-item->text item))
  59. (key (append-entry-to-listbox listbox text)))
  60. (cons key item)))
  61. items))
  62. (let* ((logo-textbox
  63. (make-textbox -1 -1
  64. (if (display-logo?) (logo-width) 0)
  65. (if (display-logo?) (logo-height) 0)
  66. 0))
  67. (info-textbox
  68. (make-reflowed-textbox -1 -1
  69. info-text
  70. (info-textbox-width)))
  71. (options-listbox
  72. (make-listbox -1 -1
  73. (options-listbox-height)
  74. (logior FLAG-BORDER FLAG-RETURNEXIT)))
  75. (keys (fill-listbox options-listbox listbox-items))
  76. (grid (vertically-stacked-grid
  77. GRID-ELEMENT-COMPONENT logo-textbox
  78. GRID-ELEMENT-COMPONENT info-textbox
  79. GRID-ELEMENT-COMPONENT options-listbox))
  80. (form (make-form)))
  81. (define (choice->item str)
  82. ;; Return the item that corresponds to STR.
  83. (match (find (match-lambda
  84. ((key . item)
  85. (string=? str (listbox-item->text item))))
  86. keys)
  87. ((key . item) item)
  88. (#f (abort-to-prompt 'installer-step 'abort))))
  89. (set-textbox-text logo-textbox (read-all logo))
  90. (add-form-to-grid grid form #t)
  91. (make-wrapped-grid-window grid title)
  92. (receive (exit-reason argument)
  93. (run-form-with-clients form
  94. `(menu (title ,title)
  95. (text ,info-text)
  96. (items
  97. ,(map listbox-item->text
  98. listbox-items))))
  99. (dynamic-wind
  100. (const #t)
  101. (lambda ()
  102. (match exit-reason
  103. ('exit-component
  104. (let* ((entry (current-listbox-entry options-listbox))
  105. (item (assoc-ref keys entry)))
  106. (match item
  107. ((text . proc)
  108. (proc)))))
  109. ('exit-fd-ready
  110. (let* ((choice argument)
  111. (item (choice->item choice)))
  112. (match item
  113. ((text . proc)
  114. (proc)))))))
  115. (lambda ()
  116. (destroy-form-and-pop form))))))
  117. (define (check-hardware-support pci-database)
  118. "Warn about unsupported devices."
  119. (when (member "uvesafb" (modules-loaded))
  120. (run-error-page (G_ "\
  121. This may be a false alarm, but possibly your graphics hardware does not
  122. work well with only free software. Expect trouble. If after installation,
  123. the system does not boot, perhaps you will need to add nomodeset to the
  124. kernel arguments and need to configure the uvesafb kernel module.")
  125. (G_ "Pre-install warning")))
  126. (let ((devices (pci-devices)))
  127. (match (filter unsupported-pci-device? devices)
  128. (() ;no unsupported device
  129. #t)
  130. (unsupported
  131. (run-error-page (format #f (G_ "\
  132. Devices not supported by free software were found on your computer:
  133. ~{ - ~a~%~}
  134. Unfortunately, it means those devices will not be usable.
  135. To address it, we recommend choosing hardware that respects your freedom as a \
  136. user--hardware for which free drivers and firmware exist. See \"Hardware \
  137. Considerations\" in the manual for more information.")
  138. (map (pci-device-description pci-database)
  139. unsupported))
  140. (G_ "Hardware support warning")
  141. #:width 76)))))
  142. (define* (run-welcome-page logo #:key pci-database)
  143. "Run a welcome page with the given textual LOGO displayed at the center of
  144. the page. Ask the user to choose between manual installation, graphical
  145. installation and reboot."
  146. (when (file-exists? %core-dump)
  147. (match (choice-window
  148. (G_ "Previous installation failed")
  149. (G_ "Continue")
  150. (G_ "Report the failure")
  151. (G_ "It seems that the previous installation exited unexpectedly \
  152. and generated a core dump. Do you want to continue or to report the failure \
  153. first?"))
  154. (1 #t)
  155. (2 (raise
  156. (condition
  157. (&user-abort-error))))))
  158. (run-menu-page
  159. (G_ "GNU Guix install")
  160. (G_ "Welcome to GNU Guix system installer!
  161. You will be guided through a graphical installation program.
  162. If you are familiar with GNU/Linux and you want tight control over \
  163. the installation process, you can instead choose manual installation. \
  164. Documentation is accessible at any time by pressing Ctrl-Alt-F2.")
  165. logo
  166. #:listbox-items
  167. `((,(G_ "Graphical install using a terminal based interface")
  168. .
  169. ,(lambda ()
  170. (check-hardware-support pci-database)))
  171. (,(G_ "Install using the shell based process")
  172. .
  173. ,(lambda ()
  174. (check-hardware-support pci-database)
  175. ;; Switch to TTY3, where a root shell is available for shell based
  176. ;; install. The other root TTY's would have been ok too.
  177. (system* "chvt" "3")
  178. (run-welcome-page logo #:pci-database pci-database)))
  179. (,(G_ "Reboot")
  180. .
  181. ,(lambda ()
  182. (newt-finish)
  183. (reboot))))
  184. #:listbox-item->text car))