;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2013 Andreas Enge ;;; Copyright © 2014 Mark H Weaver ;;; Copyright © 2016 Ricardo Wurmus ;;; Copyright © 2017 Ludovic Courtès ;;; Copyright © 2019, 2020 Efraim Flashner ;;; Copyright © 2019 Eric Bavier ;;; Copyright © 2019 Mathieu Othacehe ;;; Copyright © 2020 Michael Rohleder ;;; Copyright © 2020 Prafulla Giri ;;; ;;; This file is part of GNU Guix. ;;; ;;; GNU Guix is free software; you can redistribute it and/or modify it ;;; under the terms of the GNU General Public License as published by ;;; the Free Software Foundation; either version 3 of the License, or (at ;;; your option) any later version. ;;; ;;; GNU Guix is distributed in the hope that it will be useful, but ;;; WITHOUT ANY WARRANTY; without even the implied warr
aboutsummaryrefslogtreecommitdiff
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2018, 2020 Mathieu Othacehe <m.othacehe@gmail.com>
;;; Copyright © 2019, 2020 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2024 Janneke Nieuwenhuizen <janneke@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (gnu installer newt final)
  #:use-module (gnu installer final)
  #:use-module (gnu installer parted)
  #:use-module (gnu installer steps)
  #:use-module (gnu installer utils)
  #:use-module (gnu installer newt page)
  #:use-module (gnu installer newt utils)
  #:use-module (guix i18n)
  #:use-module (guix colors)
  #:use-module (srfi srfi-34)
  #:use-module (srfi srfi-35)
  #:use-module (ice-9 match)
  #:use-module ((ice-9 rdelim) #:select (read-line))
  #:use-module (newt)
  #:export (run-final-page))

(define* (strip-prefix file #:optional (prefix (%installer-target-dir)))
  "Strip PREFIX from FILE, if PREFIX actually is a prefix of FILE."
  (if (string-prefix? prefix file)
      (string-drop file (string-length prefix))
      file))

(define* (run-config-display-page #:key locale)
  (let ((width (max 70 (- (screen-columns) 20)))
        (height (default-listbox-height)))
    (run-file-textbox-page
     #:info-text (format #f (G_ "\
We're now ready to proceed with the installation! \
A system configuration file has been generated, it is displayed below.  \
This file will be available as '~a' on the installed system.  \
The new system will be created from this file once you've pressed OK.  \
This will take a few minutes.")
                         (strip-prefix (%installer-configuration-file)))
     #:title (G_ "Configuration file")
     #:file (%installer-configuration-file)
     #:edit-button? #t
     #:editor-locale locale
     #:info-textbox-width width
     #:file-textbox-width width
     #:file-textbox-height height
     #:exit-button-callback-procedure
     (lambda ()
       (abort-to-prompt 'installer-step 'abort)))))

(define (run-install-success-page)
  (match (current-clients)
    (()
     (message-window
      (G_ "Installation complete")
      (G_ "Reboot")
      (G_ "Congratulations!  Installation is now complete.  \
You may remove the device containing the installation image and \
press the button to reboot.")))
    (_
     ;; When there are clients connected, send them a message and keep going.
     (send-to-clients '(installation-complete))))

  ;; Return success so that the installer happily reboots.
  'success)

(define (run-install-failed-page)
  (match (current-clients)
    (()
     (match (ternary-window
             (G_ "Installation failed")
             (G_ "Resume")
             (G_ "Restart the installer")
             (G_ "Report the failure")
             (G_ "The final system installation step failed.  You can resume from \
a specific step, or restart the installer."))
       (1 (abort-to-prompt 'installer-step 'abort))
       (2
        ;; Keep going, the installer will be restarted later on.
        #t)
       (3 (raise
            (condition
             (&user-abort-error))))))
    (_
     (send-to-clients '(installation-failure))
     #t)))

(define* (run-install-shell locale
                            #:key (users '()))
  (clear-screen)
  (newt-suspend)
  (let ((install-ok? (install-system locale #:users users)))
    (newt-resume)
    install-ok?))

(define (run-final-page-install result prev-steps)
  (define (wait-for-clients)
    (unless (null? (current-clients))
      (installer-log-line "waiting with clients before starting final step")
      (send-to-clients '(starting-final-step))
      (match (select (current-clients) '() '())
        (((port _ ...) _ _)
         (read-line port)))))

  ;; Before generating the configuration file, give clients a chance to do
  ;; things such as changing the swap partition label.
  (wait-for-clients)

  (installer-log-line "proceeding with final step")
  (let* ((configuration   (format-configuration prev-steps result))
         (user-partitions (result-step result 'partition))
         (locale          (result-step result 'locale))
         (users           (result-step result 'user))
         (install-ok?
          (with-mounted-partitions
           user-partitions
           (configuration->file configuration)
           (run-config-display-page #:locale locale)
           (run-install-shell locale #:users users))))
    (if install-ok?
        (run-install-success-page)
        (run-install-failed-page))))

(define (dry-run-final-page result prev-steps)
  (installer-log-line "proceeding with final step -- dry-run")
  (let* ((configuration   (format-configuration prev-steps result))
         (user-partitions (result-step result 'partition))
         (locale          (result-step result 'locale))
         (users           (result-step result 'user))
         (file            (configuration->file configuration))
         (install-ok?     (run-config-display-page #:locale locale)))
    (if install-ok?
        (run-install-success-page)
        (run-install-failed-page))))

(define (run-final-page result prev-steps dry-run?)
  (if dry-run?
      (dry-run-final-page result prev-steps)
      (run-final-page-install result prev-steps)))
s `(#:test-target "test" #:phases (modify-phases %standard-phases (delete 'configure) (replace 'install (lambda* (#:key outputs #:allow-other-keys) (let ((out (assoc-ref outputs "out"))) (install-file "roffit" (string-append out "/bin")) (install-file "roffit.1" (string-append out "/share/man/man1")) #t))) (add-after 'install 'wrap-program (lambda* (#:key outputs #:allow-other-keys) (let ((out (assoc-ref outputs "out"))) (wrap-program (string-append out "/bin/roffit") `("PERL5LIB" ":" prefix (,(getenv "PERL5LIB")))) #t)))))) (native-inputs `(("html-tree" ,perl-html-tree))) ; for test (inputs `(("perl" ,perl))) (home-page "https://daniel.haxx.se/projects/roffit/") (synopsis "Convert nroff files to HTML") (description "Roffit is a program that reads an nroff file and outputs an HTML file. It is typically used to display man pages on a web site.") (license expat)))) (define-public ronn-ng (package (name "ronn-ng") (version "0.9.1") (source (origin (method url-fetch) (uri (rubygems-uri "ronn-ng" version)) (sha256 (base32 "1slxfg57cabmh98fw507z4ka6lwq1pvbrqwppflxw6700pi8ykfh")))) (build-system ruby-build-system) (arguments `(#:phases (modify-phases %standard-phases (add-after 'extract-gemspec 'fix-gemspec-mustache (lambda _ (substitute* "ronn-ng.gemspec" (("(.freeze.*~>).*(\".*$)" all start end) (string-append start " 1.0" end))) #t)) (add-after 'wrap 'wrap-program (lambda* (#:key outputs #:allow-other-keys) (let ((prog (string-append (assoc-ref %outputs "out") "/bin/ronn"))) (wrap-program prog `("PATH" ":" suffix ,(map (lambda (exp_inpt) (string-append (assoc-ref %build-inputs exp_inpt) "/bin")) '("ruby-kramdown" "ruby-mustache" "ruby-nokogiri"))))) #t))))) (inputs `(("ruby-kramdown" ,ruby-kramdown) ("ruby-mustache" ,ruby-mustache) ("ruby-nokogiri" ,ruby-nokogiri))) (synopsis "Build manuals in HTML and Unix man page format from Markdown") (description "Ronn-NG is an updated fork of ronn. It builds manuals in HTML and Unix man page format from Markdown.") (home-page "https://github.com/apjanke/ronn-ng") (license expat)))