Subject: Re: [PATCH] installer: Recommend 'ntp-service-type' for non-graphical systems.

From: Leo Famulari <[email-masked]>
Date: Fri, 23 Apr 2021 18:45:59 -0400

Okay, here is a patch that does what I want.

That is, when the user does not select any desktop environments, it
prompts them about enabling NTP, with the checkbox already checked.

However, with this patch, the installer crashes after partitioning, like
this:

------
In ./gnu/installer/services.scm:
     38:0 19 (%system-service-snippet-procedure (#<<system-service> name: "Network time service, to set the clock automatically" type: administration recommended?: #t snippet: ((service ntp-servi…>))
In ice-9/boot-9.scm:
  1669:16 18 (raise-exception _ #:continuable? _)
  1667:16 17 (raise-exception _ #:continuable? _)
  1667:16 16 (raise-exception _ #:continuable? _)
  1667:16 15 (raise-exception _ #:continuable? _)
  1667:16 14 (raise-exception _ #:continuable? _)
  1667:16 13 (raise-exception _ #:continuable? _)
  1667:16 12 (raise-exception _ #:continuable? _)
  1667:16 11 (raise-exception _ #:continuable? _)
  1667:16 10 (raise-exception _ #:continuable? _)
  1667:16  9 (raise-exception _ #:continuable? _)
  1667:16  8 (raise-exception _ #:continuable? _)
  1667:16  7 (raise-exception _ #:continuable? _)
  1764:13  6 (_ #<&compound-exception components: (#<&assertion-failure> #<&origin origin: "struct-vtable"> #<&message message: "Wrong type argument in position 1 (expecting struct): ~S"> #<&irrit…>)
In ice-9/eval.scm:
    619:8  5 (_ #(#(#<directory (guile-user) 7f8be12f4c80> #<<installer> name: newt init: #<procedure init ()> exit: #<procedure exit ()> exit-error: #<procedure exit-error (file key args)> f…>) …))
    619:8  4 (_ #(#(#(#<directory (guile-user) 7f8be12f4c80> #<<installer> name: newt init: #<procedure init ()> exit: #<procedure exit ()> exit-error: #<procedure exit-error (file key arg…>) …) #))
In ice-9/ports.scm:
   463:17  3 (call-with-output-file _ _ #:binary _ #:encoding _)
In ice-9/eval.scm:
    619:8  2 (_ #(#(#<directory (guile-user) 7f8be12f4c80> wrong-type-arg ("struct-vtable" "Wrong type argument in position 1 (expecting struct): ~S" ((#<<system-service> name: "Network …>)) …)) #))
    159:9  1 (_ #(#(#<directory (guile-user) 7f8be12f4c80> wrong-type-arg ("struct-vtable" "Wrong type argument in position 1 (expecting struct): ~S" ((#<<system-service> name: "Network …>)) …)) #))
In unknown file:
           0 (make-stack #t)
ice-9/eval.scm:159:9: In procedure struct-vtable: Wrong type argument in position 1 (expecting struct): (#<<system-service> name: "Network time service, to set the clock automatically" type: administration recommended?: #t snippet: ((service ntp-service-type)) packages: ()>)
------

So, I've done something wrong. But I don't know what :)

I'm going to keep trying but hopefully somebody can help me.
From c70ed1b6ed621a56ab258cf5cfce45c50cb1831f Mon Sep 17 00:00:00 2001
From: Leo Famulari <[email-masked]>
Date: Fri, 23 Apr 2021 14:50:15 -0400
Subject: [PATCH] installer: Recommend 'ntp-service-type' for non-graphical
 systems.

We had several bug reports with a root cause of "the clock was
incorrect" from users who used the installer to install a non-graphical
Guix System.

* gnu/installer/services.scm (%system-services): Add the ntp-service-type.
* gnu/installer/newt/services.scm (run-system-administration-cbt-page): New
variable.
(run-services-page): Use run-system-administration-cbt-page when not
installing a desktop.
---
 gnu/installer/newt/services.scm | 23 ++++++++++++++++++++++-
 gnu/installer/services.scm      |  8 ++++++++
 2 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/gnu/installer/newt/services.scm b/gnu/installer/newt/services.scm
index 74f28e41ba..60c62a52b1 100644
--- a/gnu/installer/newt/services.scm
+++ b/gnu/installer/newt/services.scm
@@ -3,6 +3,7 @@
 ;;; Copyright © 2019, 2020 Ludovic Courtès <[email-masked]>
 ;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <[email-masked]>
 ;;; Copyright © 2021 Tobias Geerinckx-Rice <[email-masked]>
+;;; Copyright © 2021 Leo Famulari <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -68,6 +69,25 @@ system.")
         (condition
          (&installer-step-abort)))))))
 
+(define (run-system-administration-cbt-page)
+  "Run a page to select various system adminstrative services."
+  (let ((items (filter (lambda (service)
+                         (eq? 'administration
+                              (system-service-type service)))
+                       %system-services)))
+    (run-checkbox-tree-page
+      #:title (G_ "Miscellaneous services")
+      #:info-text (G_ "Select miscellaneous system services to run on your system.")
+      #:items items
+      #:selection (map system-service-recommended? items)
+      #:item->text (compose G_ system-service-name)
+      #:checkbox-tree-height 5
+      #:exit-button-callback-procedure
+      (lambda ()
+        (raise
+          (condition
+            (&installer-step-abort)))))))
+
 (define (run-network-management-page)
   "Run a page to select among several network management methods."
   (let ((title (G_ "Network management")))
@@ -99,5 +119,6 @@ client may be enough for a server.")
     (append desktop
             (run-networking-cbt-page)
             (if (null? desktop)
-                (list (run-network-management-page))
+                (list (run-network-management-page)
+                      (run-system-administration-cbt-page))
                 '()))))
diff --git a/gnu/installer/services.scm b/gnu/installer/services.scm
index ec5ea30594..17ff31d2ec 100644
--- a/gnu/installer/services.scm
+++ b/gnu/installer/services.scm
@@ -2,6 +2,7 @@
 ;;; Copyright © 2018 Mathieu Othacehe <[email-masked]>
 ;;; Copyright © 2019 Ludovic Courtès <[email-masked]>
 ;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <[email-masked]>
+;;; Copyright © 2021 Leo Famulari <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -104,6 +105,13 @@
       (packages '((specification->package "nss-certs")))
       (recommended? #t))
 
+     ;; System administration
+     (system-service
+       (name (G_ "Network time service, to set the clock automatically"))
+       (type 'administration)
+       (snippet '((service ntp-service-type)))
+       (recommended? #t))
+
      ;; Network connectivity management.
      (system-service
       (name (G_ "NetworkManager network connection manager"))
-- 
2.31.1