aboutsummaryrefslogtreecommitdiff
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2018 Mathieu Othacehe <m.othacehe@gmail.com>
;;; Copyright © 2019, 2020 Ludovic Courtès <ludo@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 network)
  #:use-module (gnu installer connman)
  #:use-module (gnu installer steps)
  #:use-module (gnu installer utils)
  #:use-module (gnu installer newt ethernet)
  #:use-module (gnu installer newt page)
  #:use-module (gnu installer newt wifi)
  #:use-module (guix i18n)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-11)
  #:use-module (srfi srfi-34)
  #:use-module (srfi srfi-35)
  #:use-module (ice-9 match)
  #:use-module (web client)
  #:use-module (web response)
  #:use-module (newt)
  #:export (run-network-page))

;; Maximum length of a technology name.
(define technology-name-max-length (make-parameter 20))

(define (technology->text technology)
  "Return a string describing the given TECHNOLOGY."
  (let* ((name (technology-name technology))
         (padded-name (string-pad-right name
                                        (technology-name-max-length))))
    (format #f "~a~%" padded-name)))

(define (run-technology-page)
  "Run a page to ask the user which technology shall be used to access
Internet and return the selected technology. For now, only technologies with
\"ethernet\" or \"wifi\" types are supported."
  (define (technology-items)
    (filter (lambda (technology)
              (let ((type (technology-type technology)))
                (or
                 (string=? type "ethernet")
                 (string=? type "wifi"))))
            (connman-technologies)))

  (match (technology-items)
    (()
     (case (choice-window
            (G_ "Internet access")
            (G_ "Continue")
            (G_ "Exit")
            (G_ "The install process requires Internet access but no \
network devices were found. Do you want to continue anyway?"))
       ((1) (abort-to-prompt 'installer-step 'break))
       ((2) (abort-to-prompt 'installer-step 'abort))))
    ((technology)
     ;; Since there's only one technology available, skip the selection
     ;; screen.
     technology)
    ((items ...)
     (run-listbox-selection-page
      #:info-text (G_ "The install process requires Internet access.\
 Please select a network device.")
      #:title (G_ "Internet access")
      #:listbox-items items
      #:listbox-item->text technology->text
      #:listbox-height (min (+ (length items) 2) 5)
      #:button-text (G_ "Exit")
      #:button-callback-procedure
      (lambda _
        (abort-to-prompt 'installer-step 'abort))))))

(define (find-technology-by-type technologies type)
  "Find and return a technology with the given TYPE in TECHNOLOGIES list."
  (find (lambda (technology)
          (string=? (technology-type technology)
                    type))
        technologies))

(define (wait-technology-powered technology)
  "Wait and display a progress bar until the given TECHNOLOGY is powered."
  (let ((name (technology-name technology))
        (full-value 5))
    (run-scale-page
     #:title (G_ "Powering technology")
     #:info-text (format #f (G_ "Waiting for technology ~a to be powered.")
                         name)
     #:scale-full-value full-value
     #:scale-update-proc
     (lambda (value)
       (let* ((technologies (connman-technologies))
              (type (technology-type technology))
              (updated-technology
               (find-technology-by-type technologies type))
              (technology-powered? updated-technology))
         (sleep 1)
         (if technology-powered?
             full-value
             (+ value 1)))))))

(define (wait-service-online)
  "Display a newt scale until connman detects an Internet access. Do
FULL-VALUE tentatives, spaced by 1 second."
  (define (url-alive? url)
    (false-if-exception
     (= (response-code (http-request url))
        200)))

  (define (ci-available?)
    (dynamic-wind
      (lambda ()
        (sigaction SIGALRM
          (lambda _ #f))
        (alarm 3))
      (lambda ()
        (or (url-alive? "https://bordeaux.guix.gnu.org")
            (url-alive? "https://ci.guix.gnu.org")))
      (lambda ()
        (alarm 0))))

  (define (online?)
    (or (and (connman-online?)
             (ci-available?))
        (file-exists? "/tmp/installer-assume-online")))

  (let* ((full-value 5))
    (run-scale-page
     #:title (G_ "Checking connectivity")
     #:info-text (G_ "Waiting for Internet access establishment...")
     #:scale-full-value full-value
     #:scale-update-proc
     (lambda (value)
       (sleep 1)
       (if (online?)
           full-value
           (+ value 1))))
    (unless (online?)
      (run-error-page
       (G_ "The selected network does not provide access to the \
Internet and the Guix substitute server, please try again.")
       (G_ "Connection error"))
      (abort-to-prompt 'installer-step 'abort))))

(define (run-network-page)
  "Run a page to allow the user to configure connman so that it can access the
Internet."
  (define network-steps
    (list
     ;; Ask the user to choose between ethernet and wifi technologies.
     (installer-step
      (id 'select-technology)
      (compute
       (lambda _
         (run-technology-page))))
     ;; Enable the previously selected technology.
     (installer-step
      (id 'power-technology)
      (compute
       (lambda (result _)
         (let ((technology (result-step result 'select-technology)))
           (connman-enable-technology technology)
           (wait-technology-powered technology)))))
     ;; Propose the user to connect to one of the service available for the
     ;; previously selected technology.
     (installer-step
      (id 'connect-service)
      (compute
       (lambda (result _)
         (let* ((technology (result-step result 'select-technology))
                (type (technology-type technology)))
           (cond
            ((string=? "wifi" type)
             (run-wifi-page))
            ((string=? "ethernet" type)
             (run-ethernet-page)))))))
     ;; Wait for connman status to switch to 'online, which means it can
     ;; access Internet.
     (installer-step
      (id 'wait-online)
      (compute (lambda _
                 (wait-service-online))))))
  (run-installer-steps
   #:steps network-steps
   #:rewind-strategy 'start))
/a>...* gnu/system.scm (operating-system-hosts-file): Deprecate procedure. (warn-hosts-file-field-deprecation): New procedure, helper for deprecated variable. (operating-system)[hosts-file]: Use helper to warn deprecated field. (local-host-aliases): Mark as deprecated. (local-host-entries): New procedure. (operating-system-default-essential-services, hurd-default-essential-services): Use hosts-service-type. Use '%operating-system-hosts-file' and 'local-host-entries'. (default-/etc/hosts): Remove procedure. (operating-system-etc-service): Remove hosts file. * doc/guix.texi (operating-system Reference) (Networking Services) (Virtualization Services): Rewrite documentation entries to use hosts-service-type. Co-authored-by: Ludovic Courtès <ludo@gnu.org> Bruno Victal 2023-01-30Merge remote-tracking branch 'origin/master' into core-updates... Conflicts: doc/guix.texi gnu/local.mk gnu/packages/admin.scm gnu/packages/base.scm gnu/packages/chromium.scm gnu/packages/compression.scm gnu/packages/databases.scm gnu/packages/diffoscope.scm gnu/packages/freedesktop.scm gnu/packages/gnome.scm gnu/packages/gnupg.scm gnu/packages/guile.scm gnu/packages/inkscape.scm gnu/packages/llvm.scm gnu/packages/openldap.scm gnu/packages/pciutils.scm gnu/packages/ruby.scm gnu/packages/samba.scm gnu/packages/sqlite.scm gnu/packages/statistics.scm gnu/packages/syndication.scm gnu/packages/tex.scm gnu/packages/tls.scm gnu/packages/version-control.scm gnu/packages/xml.scm guix/build-system/copy.scm guix/scripts/home.scm Efraim Flashner 2023-01-05system: Define default 'PS1' in /etc/bashrc rather than ~/.bashrc....Users can override 'PS1' in ~/.bashrc if they wish. Previously, on Guix Home, the "default" 'PS1' would be set in ~/.bashrc when 'home-bash-configuration-guix-defaults?' is true, preventing users from overriding it via the 'environment-variables' field of 'home-bash-extension'. * gnu/system/shadow.scm (%default-bashrc): Remove 'PS1' setting. * gnu/system.scm (operating-system-etc-service): Define PS1 in /etc/bashrc. * gnu/home/services/shells.scm (add-bash-configuration): When 'home-bash-configuration-guix-defaults?' is true, add a default 'PS1' to ~/.bash_profile. Ludovic Courtès 2022-12-05system: Add e2fsprogs to %base-packages-utils....Rationale: Even when not using an ext file system, the utilities provided by e2fsprogs are useful, for example to set the copy-on-write attribute of a Btrfs file system. * gnu/system.scm (%base-packages-utils): Add e2fsprogs. Maxim Cournoyer 2022-12-05system: Rename and move %base-packages-disk-utilities....Rationale: It is only used in INSTALLATION-OS and doesn't make sense to be used in another context, given that file systems now automatically pull their dependencies since commit 45eac6cdf5c8d9d7b0c564b105c790d2d2007799 (services: Add file system utilities to profile). * gnu/system.scm (%base-packages-disk-utilities): Deprecate and rename to... * gnu/system/install.scm (%installer-disk-utilities): ... this. (installation-os) [packages]: Adjust accordingly. Maxim Cournoyer 2022-11-27gnu: shadow: Merge in shadow-with-man-pages....* gnu/packages/admin.scm (shadow)[arguments]: Add phase to install the manpages. Make sure 'remove-groups comes after installing the manpages. [properties]: Remove field. (shadow-with-man-pages): Remove variable. * gnu/system.scm (%base-packages-utils): Replace shadow-with-man-pages with shadow. Efraim Flashner 2022-10-23gnu: Fix typos....* gnu/packages/emacs-xyz.scm (emacs-piem)[description]: Fix use of "This packages". * gnu/packages/tex.scm (texlive-hardwrap)[description]: Fix spelling of "arbitrary". * gnu/packages/cran.scm (r-shinymanager)[description]: Fix spelling of "authentication". * gnu/packages/lisp-xyz.scm (sbcl-utils-kt)[description]: Fix spelling of "developed". * gnu/packages/crates-io.scm (rust-fs-utils-1)[description]: Fix spelling of "filesystem". [synopsis]: Likewise. * gnu/packages/haxe.scm (neko)[description]: Fix spelling of "functions". * gnu/packages/animation.scm (swftools)[description]: Fix needless pluralization of "information". * gnu/packages/lisp-xyz.scm (sbcl-slot-extra-options)[description]: Fix spelling of "inheritance". * gnu/packages/emacs-xyz.scm (emacs-js-comint)[description]: Fix spelling of "interpreter". * gnu/packages/coq.scm (coq-mathcomp-finmap)[description]: Fix spelling of "library". * gnu/services/lightdm.scm (lightdm-configuration): Fix spelling of "mechanism". * gnu/packages/emacs-xyz.scm (emacs-citar-org-roam)[synopsis]: Fix spelling of "package". * gnu/packages/games.scm (freerct)[description]: Fix spelling of "responsibilities". * gnu/packages/statistics.scm (r-mixedpower)[description]: Fix spelling of "separate". * gnu/packages/accessibility.scm (espeakup)[description]: Fix spelling of "speech". * gnu/packages/bioinformatics.scm (r-skitools)[synopsis]: Fix spelling of "utilities". * gnu/packages/golang.scm (go-github-com-savsgio-gotils)[synopsis]: Fix spelling of "utilities". [description]: Likewise. * gnu/system.scm (boot-file-system-service os): Fix spelling of "utilities". Vagrant Cascadian 2022-10-23system: hurd: Boot with the statically-linked 'exec' server....This works around <https://issues.guix.gnu.org/58631>. * gnu/system.scm (hurd-multiboot-modules): Use '/hurd/exec.static' instead of 'ld.so /hurd/exec'. Ludovic Courtès 2022-10-11system: operating-system: Make the timezone field default to Etc/UTC....* gnu/system.scm (<operating-system>) [timezone]: Default to "Etc/UTC". Maxim Cournoyer 2022-09-28services: Add file system utilities to profile....* gnu/services/base.scm (file-system-type->utilities) (file-system-utilities): New procedures. (file-system-service-type): Extend 'profile-service-type' with 'file-system-utilities'. * gnu/system.scm (boot-file-system-service): New procedure. (operating-system-default-essential-services): Use it. (%base-packages): Remove 'e2fsprogs'. Signed-off-by: Maxim Cournoyer <maxim.cournoyer@gmail.com> Modified-by: Maxim Cournoyer <maxim.cournoyer@gmail.com> Brice Waegeneire 2022-07-14gnu: system: Add fusermount3 to setuid-programs....Fixes <https://issues.guix.gnu.org/47716>. * gnu/system.scm (%setuid-programs): Add /bin/fusermount3 from the fuse-3 package. Reported-by: raingloom <raingloom@riseup.net> Maxim Cournoyer 2022-06-15system: <operating-system> compiler truly honors the 'system' argument....Fixes <https://issues.guix.gnu.org/55951>. * gnu/system.scm (operating-system-compiler): Parameterize '%current-system' and '%current-target-system' before calling 'operating-system-derivation'. * tests/system.scm ("lower-object, %current-system sensitivity"): New test. Ludovic Courtès 2022-06-06system: Fix typo, add doc....* gnu/system.scm (operating-system-kernel-arguments): Fix typo in doc. (boot-parameters->menu-entry): Add doc. Maxim Cournoyer