guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

32/80: installer: Add a task to actually call guix system init.


From: John Darrington
Subject: 32/80: installer: Add a task to actually call guix system init.
Date: Tue, 3 Jan 2017 15:49:43 +0000 (UTC)

jmd pushed a commit to branch wip-installer
in repository guix.

commit 563cf3aa1d10f8efc8d826b1312de9c451e3205a
Author: John Darrington <address@hidden>
Date:   Sun Dec 25 12:10:54 2016 +0100

    installer: Add a task to actually call guix system init.
    
    * gnu/system/installer/install.scm: New file.
    * gnu/local.mk (GNU_SYSTEM_MODULES): Add it.
    * gnu/system/installer/new.scm (main-options): New task.
---
 gnu/local.mk                     |    1 +
 gnu/system/installer/install.scm |  169 ++++++++++++++++++++++++++++++++++++++
 gnu/system/installer/new.scm     |   23 ++++--
 3 files changed, 187 insertions(+), 6 deletions(-)

diff --git a/gnu/local.mk b/gnu/local.mk
index 6e39d83..8c8c5c5 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -440,6 +440,7 @@ GNU_SYSTEM_MODULES =                                \
   %D%/system/installer/filesystems.scm          \
   %D%/system/installer/network.scm              \
   %D%/system/installer/wireless.scm             \
+  %D%/system/installer/install.scm              \
   %D%/system/installer/dialog.scm               \
   %D%/system/installer/hostname.scm             \
   %D%/system/installer/mount-point.scm          \
diff --git a/gnu/system/installer/install.scm b/gnu/system/installer/install.scm
new file mode 100644
index 0000000..6576c12
--- /dev/null
+++ b/gnu/system/installer/install.scm
@@ -0,0 +1,169 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2016 John Darrington <address@hidden>
+;;;
+;;; 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 system installer install)
+  #:use-module (gnu system installer page)
+  #:use-module (gnu system installer ping)
+  #:use-module (gnu system installer misc)
+  #:use-module (gnu system installer utils)
+  #:use-module (ice-9 format)
+  #:use-module (ice-9 match)
+  #:use-module (gurses buttons)
+  #:use-module (ncurses curses)
+  #:use-module (guix store)
+  #:use-module (guix utils)
+  #:use-module (guix build utils)
+
+  #:export (make-install-page))
+
+
+(define (make-install-page parent title)
+  (let ((page (make-page (page-surface parent)
+                         title
+                         install-page-refresh
+                         install-page-key-handler)))
+
+    page))
+
+
+(define my-buttons `((continue ,(N_ "_Continue") #t)
+                     (back ,(N_ "_Back") #t)))
+
+(define (install-page-key-handler page ch)
+  (let ((nav  (page-datum page 'navigation))
+        (config-window  (page-datum page 'config-window)))
+
+    (cond
+     ((eq? ch KEY_RIGHT)
+      (buttons-select-next nav))
+
+     ((eq? ch #\tab)
+      (cond
+       ((eqv? (buttons-selected nav) (1- (buttons-n-buttons nav)))
+       (buttons-unselect-all nav))
+
+       (else
+       (buttons-select-next nav))))
+
+     ((eq? ch KEY_LEFT)
+      (buttons-select-prev nav))
+
+     ((eq? ch KEY_UP)
+      (buttons-unselect-all nav))
+
+
+     ((buttons-key-matches-symbol? nav ch 'back)
+      ;; Close the menu and return
+      (delwin (outer (page-wwin page)))
+      (delwin (inner (page-wwin page)))
+      (set! page-stack (cdr page-stack)))
+
+     ((buttons-key-matches-symbol? nav ch 'continue)
+      (let ((target "/target")
+            (tmp-config (port-filename %temporary-configuration-file-port))
+            (window-port (make-window-port config-window))
+            (root-device (find-mount-device "/" mount-points)))
+
+        (catch #t
+          (lambda ()
+           (and
+             ;; Undo any previous attempt to install ...
+             (or (pipe-cmd window-port  "herd"
+                              "herd" "stop" "cow-store")
+                 #t)
+
+             (or (pipe-cmd window-port "umount"
+                              "umount" target) #t)
+
+             (mkdir-p target)
+             (zero? (pipe-cmd window-port "mount"
+                                 "mount" "-t" "ext4" root-device target))
+             (mkdir-p (string-append target "/etc"))
+             (or (copy-file tmp-config
+                            (string-append target "/etc/config.scm"))
+                 #t)
+
+             (file-exists? (string-append target "/etc/config.scm"))
+
+             ;; Cow store seems to mess with temporary files.
+             (zero? (pipe-cmd window-port  "herd"
+                                 "herd" "start" "cow-store" target))
+
+             (zero? (pipe-cmd window-port "guix" "guix" "system" "init"
+                                 (string-append target "/etc/config.scm")
+                                 target))))
+          (lambda (key . args)
+            (addstr* config-window
+                     (gettext
+                      (format #f "A \"~s\" exception occured: ~s" key args))))
+          )
+        (close-port window-port))))
+       #f
+     )
+    )
+
+(define (install-page-refresh page)
+  (when (not (page-initialised? page))
+    (install-page-init page)
+    (page-set-initialised! page #t))
+  (touchwin (outer (page-wwin page)))
+  (refresh (outer (page-wwin page)))
+  (refresh (inner (page-wwin page))))
+
+
+(define (install-page-init p)
+  (let* ((s (page-surface p))
+        (pr (make-boxed-window  #f
+             (- (getmaxy s) 3) (- (getmaxx s) 2)
+             2 1
+             #:title (page-title p)))
+        (text-window (derwin
+                      (inner pr)
+                      3 (getmaxx (inner pr))
+                      0 0
+                      #:panel #f))
+                       
+        (bwin (derwin (inner pr)
+                      3 (getmaxx (inner pr))
+                      (- (getmaxy (inner pr)) 3) 0
+                         #:panel #f))
+        (buttons (make-buttons my-buttons 1))
+
+         (config-window (make-boxed-window
+                         (inner pr)
+                         (- (getmaxy (inner pr))
+                            (getmaxy bwin)
+                            (getmaxy text-window))
+                         (getmaxx (inner pr))
+                         (getmaxy text-window)
+                         0))
+         )
+
+
+    (addstr* text-window
+             (gettext
+              "Choose \"Continue\" to start installing the system."))
+
+    (page-set-wwin! p pr)
+    (page-set-datum! p 'navigation buttons)
+    (page-set-datum! p 'config-window (inner config-window))
+    (buttons-post buttons bwin)
+    (refresh (outer pr))
+    (refresh text-window)
+    (refresh bwin)))
+                       
diff --git a/gnu/system/installer/new.scm b/gnu/system/installer/new.scm
index aa393b8..b97bf74 100644
--- a/gnu/system/installer/new.scm
+++ b/gnu/system/installer/new.scm
@@ -30,6 +30,7 @@
             (gnu system installer file-browser)
             (gnu system installer time-zone)
             (gnu system installer network)
+             (gnu system installer install)
             (gnu system installer page)
             (gnu system installer dialog)
 
@@ -51,11 +52,12 @@
   (complete task-complete?)
   (init task-init))
 
-(define partition-menu-title  (N_ "Partition the disk(s)"))
-(define filesystem-menu-title (N_ "Allocate disk partitions"))
-(define network-menu-title    (N_ "Setup the network"))
-(define timezone-menu-title    (N_ "Set the time zone"))
-(define hostname-menu-title    (N_ "Set the host name"))
+(define partition-menu-title    (N_ "Partition the disk(s)"))
+(define filesystem-menu-title   (N_ "Allocate disk partitions"))
+(define network-menu-title      (N_ "Setup the network"))
+(define timezone-menu-title     (N_ "Set the time zone"))
+(define hostname-menu-title     (N_ "Set the host name"))
+(define installation-menu-title (N_ "Install the system"))
 
 (define (size-of-largest-disk)
   (fold (lambda (disk prev) (max (disk-size disk) prev))
@@ -148,7 +150,16 @@
                             (packages (cons* nss-certs %base-packages))
                             (services (cons* %desktop-services))
                             (name-service-switch %mdns-host-lookup-nss))))
-                      #:justify #f))))))
+                      #:justify #f))))
+
+    (install .  ,(make-task installation-menu-title
+                            ;;                            '(generate network)
+                            '(filesystems)
+                            (lambda () #f)
+                            (lambda (page)
+                              (make-install-page
+                               page
+                               installation-menu-title))))))
 
 (define (generate-guix-config cfg)
   (call-with-output-string



reply via email to

[Prev in Thread] Current Thread [Next in Thread]