all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH 1/1] services: Add agetty service.
@ 2017-02-15  0:12 Leo Famulari
  2017-02-15  0:24 ` Leo Famulari
  0 siblings, 1 reply; 11+ messages in thread
From: Leo Famulari @ 2017-02-15  0:12 UTC (permalink / raw)
  To: guix-devel

* gnu/services/base.scm (<agetty-configuration>): New record type.
(agetty-shepherd-service, agetty-service): New procedures.
(agetty-service-type): New variable.
---
 gnu/services/base.scm | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 71 insertions(+), 1 deletion(-)

diff --git a/gnu/services/base.scm b/gnu/services/base.scm
index 57601eab8..58a50e38b 100644
--- a/gnu/services/base.scm
+++ b/gnu/services/base.scm
@@ -3,7 +3,7 @@
 ;;; Copyright © 2015, 2016 Alex Kost <alezost@gmail.com>
 ;;; Copyright © 2015, 2016 Mark H Weaver <mhw@netris.org>
 ;;; Copyright © 2015 Sou Bunnbu <iyzsong@gmail.com>
-;;; Copyright © 2016 Leo Famulari <leo@famulari.name>
+;;; Copyright © 2016, 2017 Leo Famulari <leo@famulari.name>
 ;;; Copyright © 2016 David Craven <david@craven.ch>
 ;;; Copyright © 2016 Ricardo Wurmus <rekado@elephly.net>
 ;;;
@@ -38,6 +38,7 @@
                 #:select (canonical-package glibc))
   #:use-module (gnu packages bash)
   #:use-module (gnu packages package-management)
+  #:use-module (gnu packages linux)
   #:use-module (gnu packages lsof)
   #:use-module (gnu packages terminals)
   #:use-module ((gnu build file-systems)
@@ -74,6 +75,11 @@
             login-service-type
             login-service
 
+            agetty-configuration
+            agetty-configuration?
+            agetty-service
+            agetty-service-type
+
             mingetty-configuration
             mingetty-configuration?
             mingetty-service
@@ -730,6 +736,70 @@ Return a service that sets up Unicode support in @var{tty} and loads
 the message of the day, among other things."
   (service login-service-type config))
 
+(define-record-type* <agetty-configuration>
+  agetty-configuration make-agetty-configuration
+  agetty-configuration?
+  (agetty         agetty-configuration-agetty   ;<package>
+                  (default util-linux))
+  (tty            agetty-configuration-tty)     ;string
+  (term           agetty-term                   ;string
+                  (default #f))
+  (extra          agetty-extra                  ;string
+                  (default #f))
+  (baud-rate      agetty-baud-rate              ;string
+                  (default #f))
+  (auto-login     agetty-auto-login             ;string | #f
+                  (default #f))
+  (login-program  agetty-login-program          ;gexp
+                  (default (file-append shadow "/bin/login")))
+  (login-pause?   agetty-login-pause?           ;Boolean
+                  (default #f)))
+
+(define agetty-shepherd-service
+  (match-lambda
+    (($ <agetty-configuration> agetty tty term extra baud-rate auto-login
+        login-program login-pause?)
+     (list
+       (shepherd-service
+         (documentation "Run agetty on a tty.")
+         (provision (list (symbol-append 'term- (string->symbol tty))))
+
+         ;; Same comment as for mingetty-shepherd-service.
+         (requirement '(user-processes host-name udev))
+
+         (start #~(make-forkexec-constructor
+                    (list #$ (file-append util-linux "/sbin/agetty")
+                          #$@(if extra
+                                 #~(#$extra)
+                                 #~())
+                          "--noclear" #$tty
+                          #$@(if baud-rate
+                                 #~(#$baud-rate)
+                                 #~())
+                          #$@(if auto-login
+                                 #~("--autologin" #$auto-login)
+                                 #~())
+                          #$@(if login-program
+                                 #~("--login-program" #$login-program)
+                                 #~())
+                          #$@(if login-pause?
+                                 #~("--login-pause")
+                                 #~())
+                          #$@(if term
+                                 #~(#$term)
+                                 #~()))))
+         (stop #~(make-kill-destructor)))))))
+
+(define agetty-service-type
+  (service-type (name 'agetty)
+                (extensions (list (service-extension shepherd-root-service-type
+                                                     agetty-shepherd-service)))))
+
+(define* (agetty-service config)
+  "Return a service to run agetty according to @var{config}, which specifies
+the tty to run, among other things."
+  (service agetty-service-type config))
+
 (define-record-type* <mingetty-configuration>
   mingetty-configuration make-mingetty-configuration
   mingetty-configuration?
-- 
2.11.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/1] services: Add agetty service.
  2017-02-15  0:12 [PATCH 1/1] services: Add agetty service Leo Famulari
@ 2017-02-15  0:24 ` Leo Famulari
  2017-02-15 15:21   ` myglc2
                     ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Leo Famulari @ 2017-02-15  0:24 UTC (permalink / raw)
  To: guix-devel


[-- Attachment #1.1: Type: text/plain, Size: 2013 bytes --]

On Tue, Feb 14, 2017 at 07:12:44PM -0500, Leo Famulari wrote:
> * gnu/services/base.scm (<agetty-configuration>): New record type.
> (agetty-shepherd-service, agetty-service): New procedures.
> (agetty-service-type): New variable.

My intention is to get a serial tty, for example /dev/ttyS0, so that I
can install GuixSD on a device that lacks any graphical display
interfaces:

http://pcengines.ch/apu2b4.htm

> +(define-record-type* <agetty-configuration>
> +  agetty-configuration make-agetty-configuration
> +  agetty-configuration?
> +  (agetty         agetty-configuration-agetty   ;<package>
> +                  (default util-linux))
> +  (tty            agetty-configuration-tty)     ;string
> +  (term           agetty-term                   ;string
> +                  (default #f))
> +  (extra          agetty-extra                  ;string
> +                  (default #f))

This 'extra' is a time-saving kludge. I'll add fields for all of
agetty's configuration options once I'm satisfied that the service works
on GuixSD.

For now, I can apply the attached diff and connect to a QEMU VM over an
emulated serial device.

Apply the diff and build a new installer image:

$ ./pre-inst-env guix system disk-image --image-size=1.5G \
gnu/system/install.scm

Copy the image out of your store, make it writable, and then boot it
with QEMU:

$ qemu-system-x86_64 -enable-kvm -m 3072 -net user -net nic,model=virtio \
-boot menu=on -drive file=/home/leo/tmp/test-image -serial pty

QEMU will tell you which pts device it's using, and then you can use
screen to connect to the correct device and log in:

$ screen -t 'test' /dev/pts/N 115200,-ixoff,-ixon

However, it doesn't work when I boot my physical device with the same
installer image.

When I connect to my physical device using the Keyspan USA-19H
serial-to-USB converter, I can watch the system boot, but Shepherd never
reports that the 'term-ttyS0' service has started, and I never see the
MOTD or login prompt.

Any advice or debugging ideas?

[-- Attachment #1.2: testing.diff --]
[-- Type: text/plain, Size: 1392 bytes --]

diff --git a/gnu/system/grub.scm b/gnu/system/grub.scm
index b18b8be6d..b04d9d346 100644
--- a/gnu/system/grub.scm
+++ b/gnu/system/grub.scm
@@ -197,7 +197,8 @@ system string---e.g., \"x86_64-linux\"."
     insmod efi_uga
   fi
 
-  terminal_output gfxterm
+  ;; Use the ncurses-type GRUB interface
+  terminal_output console
 "
         ""))
 
diff --git a/gnu/system/install.scm b/gnu/system/install.scm
index 3ec343570..301b7b98f 100644
--- a/gnu/system/install.scm
+++ b/gnu/system/install.scm
@@ -275,6 +275,12 @@ You have been warned.  Thanks for being so brave.
                              (tty "tty1")
                              (auto-login "root")))
 
+          (agetty-service (agetty-configuration
+                            (tty "ttyS0")
+                            (term "vt100")
+                            (extra "-L")
+                            (baud-rate "115200")))
+
           (login-service (login-configuration
                           (motd motd)))
 
@@ -340,6 +346,9 @@ Use Alt-F2 for documentation.
     (host-name "gnu")
     (timezone "Europe/Paris")
     (locale "en_US.utf8")
+    (kernel linux-libre-4.1)
+    (kernel-arguments
+     '("console=ttyS0,115200n8 gfxpayload=text earlyprintk=serial,ttyS0,115200"))
     (bootloader (grub-configuration
                  (device "/dev/sda")))
     (file-systems

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/1] services: Add agetty service.
  2017-02-15  0:24 ` Leo Famulari
@ 2017-02-15 15:21   ` myglc2
  2017-02-15 19:38   ` Leo Famulari
  2017-02-16  7:06   ` [V2 PATCH " Leo Famulari
  2 siblings, 0 replies; 11+ messages in thread
From: myglc2 @ 2017-02-15 15:21 UTC (permalink / raw)
  To: Leo Famulari; +Cc: guix-devel

On 02/14/2017 at 19:24 Leo Famulari writes:

> On Tue, Feb 14, 2017 at 07:12:44PM -0500, Leo Famulari wrote:
>> * gnu/services/base.scm (<agetty-configuration>): New record type.
>> (agetty-shepherd-service, agetty-service): New procedures.
>> (agetty-service-type): New variable.
>
> My intention is to get a serial tty, for example /dev/ttyS0, so that I
> can install GuixSD on a device that lacks any graphical display
> interfaces:
[...
> However, it doesn't work when I boot my physical device with the same
> installer image.
>
> When I connect to my physical device using the Keyspan USA-19H
> serial-to-USB converter, I can watch the system boot, but Shepherd never
> reports that the 'term-ttyS0' service has started, and I never see the
> MOTD or login prompt.
>
> Any advice or debugging ideas?

Hi Leo,

I'm very happy to see you doing this. I got agetty working on IPMI
serial over LAN (SOL) on a ASRock MT-C224 motherboard as follows:

I made these changes in GRUB.scm ...

diff --git a/gnu/system/grub.scm b/gnu/system/grub.scm
index b18b8be6d..e68cec7f4 100644
--- a/gnu/system/grub.scm
+++ b/gnu/system/grub.scm
@@ -197,7 +197,8 @@ system string---e.g., \"x86_64-linux\"."
     insmod efi_uga
   fi
 
-  terminal_output gfxterm
+  serial --unit=0 --speed=115200
+  terminal_input serial console; terminal_output console
 "
         ""))
 
I found the serial port like so ...

dmesg | grep tty
[    0.000000] Command line: BOOT_IMAGE=/gnu/store/ksigckplbh1669iy62pqa17j7sid9vmw-linux-libre-4.9.9/bzImage --root=/dev/md3 --system=/gnu/store/ssh2kjijcg7fvfaafmn4jj0chkmzaxzr-system --load=/gnu/store/ssh2kjijcg7fvfaafmn4jj0chkmzaxzr-system/boot console=ttyS1,115200
[    0.000000] Kernel command line: BOOT_IMAGE=/gnu/store/ksigckplbh1669iy62pqa17j7sid9vmw-linux-libre-4.9.9/bzImage --root=/dev/md3 --system=/gnu/store/ssh2kjijcg7fvfaafmn4jj0chkmzaxzr-system --load=/gnu/store/ssh2kjijcg7fvfaafmn4jj0chkmzaxzr-system/boot console=ttyS1,115200
[    0.000000] console [ttyS1] enabled
[    3.622999] 00:07: ttyS1 at I/O 0x2f8 (irq = 3, base_baud = 115200)
is a 16550A

... I installed the shadow package and I did this ...

agetty ttyS1 -l /root/.guix-profile/bin/login &

And I can log in, run screen and run emacs.

FWIW, there is no mention in sheperd.log of the serial port.

HTH, George

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/1] services: Add agetty service.
  2017-02-15  0:24 ` Leo Famulari
  2017-02-15 15:21   ` myglc2
@ 2017-02-15 19:38   ` Leo Famulari
  2017-02-16  7:06   ` [V2 PATCH " Leo Famulari
  2 siblings, 0 replies; 11+ messages in thread
From: Leo Famulari @ 2017-02-15 19:38 UTC (permalink / raw)
  To: guix-devel


[-- Attachment #1.1: Type: text/plain, Size: 504 bytes --]

On Tue, Feb 14, 2017 at 07:24:17PM -0500, Leo Famulari wrote:
> When I connect to my physical device using the Keyspan USA-19H
> serial-to-USB converter, I can watch the system boot, but Shepherd never
> reports that the 'term-ttyS0' service has started, and I never see the
> MOTD or login prompt.
> 
> Any advice or debugging ideas?

Good news, it works!

My method of testing was no good.

I just successfully booted and logged in using attached diff on top of
the agetty-service patch.

[-- Attachment #1.2: testing.diff --]
[-- Type: text/plain, Size: 1315 bytes --]

diff --git a/gnu/system/grub.scm b/gnu/system/grub.scm
index b18b8be6d..d94b1a266 100644
--- a/gnu/system/grub.scm
+++ b/gnu/system/grub.scm
@@ -197,7 +197,7 @@ system string---e.g., \"x86_64-linux\"."
     insmod efi_uga
   fi
 
-  terminal_output gfxterm
+  terminal_output console
 "
         ""))
 
diff --git a/gnu/system/install.scm b/gnu/system/install.scm
index 3ec343570..55020b147 100644
--- a/gnu/system/install.scm
+++ b/gnu/system/install.scm
@@ -275,6 +275,11 @@ You have been warned.  Thanks for being so brave.
                              (tty "tty1")
                              (auto-login "root")))
 
+          (agetty-service (agetty-configuration
+                            (extra "-i")
+                            (tty "ttyS0")
+                            (baud-rate "115200,38400,9600")))
+
           (login-service (login-configuration
                           (motd motd)))
 
@@ -340,6 +345,9 @@ Use Alt-F2 for documentation.
     (host-name "gnu")
     (timezone "Europe/Paris")
     (locale "en_US.utf8")
+    (kernel linux-libre-4.1)
+    (kernel-arguments
+     '("console=ttyS0,115200n8 gfxpayload=text earlyprintk=serial,ttyS0,115200"))
     (bootloader (grub-configuration
                  (device "/dev/sda")))
     (file-systems

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [V2 PATCH 1/1] services: Add agetty service.
  2017-02-15  0:24 ` Leo Famulari
  2017-02-15 15:21   ` myglc2
  2017-02-15 19:38   ` Leo Famulari
@ 2017-02-16  7:06   ` Leo Famulari
  2017-02-17  7:48     ` Ricardo Wurmus
  2017-02-17 18:35     ` myglc2
  2 siblings, 2 replies; 11+ messages in thread
From: Leo Famulari @ 2017-02-16  7:06 UTC (permalink / raw)
  To: guix-devel


[-- Attachment #1.1: Type: text/plain, Size: 551 bytes --]

On Tue, Feb 14, 2017 at 07:24:17PM -0500, Leo Famulari wrote:
> This 'extra' is a time-saving kludge. I'll add fields for all of
> agetty's configuration options once I'm satisfied that the service works
> on GuixSD.

Here's a patch that exposes (almost all) of agetty's command-line
options.

Is this the right way? Or would we rather wrap only the most
commonly-used options, and leave an "escape hatch" as in the first
version of the patch? If so, which options should we expose in Scheme?

I'll wait for feedback before writing the documentation.

[-- Attachment #1.2: 0001-services-Add-agetty-service.patch --]
[-- Type: text/plain, Size: 11943 bytes --]

From 215ad705a933fda1170a5883277cd9a68db693e0 Mon Sep 17 00:00:00 2001
From: Leo Famulari <leo@famulari.name>
Date: Tue, 14 Feb 2017 11:28:04 -0500
Subject: [PATCH] services: Add agetty service.

* gnu/services/base.scm (<agetty-configuration>): New record type.
(agetty-shepherd-service, agetty-service): New procedures.
(agetty-service-type): New variable.
---
 gnu/services/base.scm | 214 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 213 insertions(+), 1 deletion(-)

diff --git a/gnu/services/base.scm b/gnu/services/base.scm
index 57601eab8..a06d44bb2 100644
--- a/gnu/services/base.scm
+++ b/gnu/services/base.scm
@@ -3,7 +3,7 @@
 ;;; Copyright © 2015, 2016 Alex Kost <alezost@gmail.com>
 ;;; Copyright © 2015, 2016 Mark H Weaver <mhw@netris.org>
 ;;; Copyright © 2015 Sou Bunnbu <iyzsong@gmail.com>
-;;; Copyright © 2016 Leo Famulari <leo@famulari.name>
+;;; Copyright © 2016, 2017 Leo Famulari <leo@famulari.name>
 ;;; Copyright © 2016 David Craven <david@craven.ch>
 ;;; Copyright © 2016 Ricardo Wurmus <rekado@elephly.net>
 ;;;
@@ -38,6 +38,7 @@
                 #:select (canonical-package glibc))
   #:use-module (gnu packages bash)
   #:use-module (gnu packages package-management)
+  #:use-module (gnu packages linux)
   #:use-module (gnu packages lsof)
   #:use-module (gnu packages terminals)
   #:use-module ((gnu build file-systems)
@@ -74,6 +75,11 @@
             login-service-type
             login-service
 
+            agetty-configuration
+            agetty-configuration?
+            agetty-service
+            agetty-service-type
+
             mingetty-configuration
             mingetty-configuration?
             mingetty-service
@@ -730,6 +736,212 @@ Return a service that sets up Unicode support in @var{tty} and loads
 the message of the day, among other things."
   (service login-service-type config))
 
+(define-record-type* <agetty-configuration>
+  agetty-configuration make-agetty-configuration
+  agetty-configuration?
+  (agetty         agetty-configuration-agetty   ;<package>
+                  (default util-linux))
+  (tty            agetty-configuration-tty)     ;string
+  (term           agetty-term                   ;string
+                  (default #f))
+  (baud-rate      agetty-baud-rate              ;string
+                  (default #f))
+  (auto-login     agetty-auto-login             ;string
+                  (default #f))
+  (login-program  agetty-login-program          ;gexp
+                  (default (file-append shadow "/bin/login")))
+  (login-pause?   agetty-login-pause?           ;Boolean
+                  (default #f))
+  (eight-bits?    agetty-eight-bits?            ;Boolean
+                  (default #f))
+  (no-reset?      agetty-no-reset?              ;Boolean
+                  (default #f))
+  (remote?        agetty-remote?                ;Boolean
+                  (default #f))
+  (flow-control?  agetty-flow-control?          ;Boolean
+                  (default #f))
+  (host           agetty-host                   ;string
+                  (default #f))
+  (no-issue?      agetty-no-issue?              ;Boolean
+                  (default #f))
+  (init-string    agetty-init-string            ;string
+                  (default #f))
+  (no-clear?      agetty-no-clear?              ;Boolean
+                  (default #f))
+  (local-line     agetty-local-line             ;always | never | auto
+                  (default #f))
+  (extract-baud?  agetty-extract-baud?          ;Boolean
+                  (default #f))
+  (skip-login?    agetty-skip-login?            ;Boolean
+                  (default #f))
+  (no-newline?    agetty-no-newline?            ;Boolean
+                  (default #f))
+  (login-options  agetty-login-options          ;string
+                  (default #f))
+  (chroot         agetty-chroot                 ;string
+                  (default #f))
+  (hangup?        agetty-hangup?                ;Boolean
+                  (default #f))
+  (timeout        agetty-timeout                ;integer
+                  (default #f))
+  (detect-case?   agetty-detect-case?           ;Boolean
+                  (default #f))
+  (wait-cr?       agetty-wait-cr?               ;Boolean
+                  (default #f))
+  (no-hints?      agetty-no-hints?              ;Boolean
+                  (default #f))
+  (no-hostname?   agetty-no hostname?           ;Boolean
+                  (default #f))
+  (long-hostname? agetty-long-hostname?         ;Boolean
+                  (default #f))
+  (erase-chars    agetty-erase-chars            ;string
+                  (default #f))
+  (kill-chars     agetty-kill-chars             ;string
+                  (default #f))
+  (chdir          agetty-chdir                  ;string
+                  (default #f))
+  (delay          agetty-delay                  ;integer
+                  (default #f))
+  (nice           agetty-nice                   ;integer
+                  (default #f))
+;;; XXX Unimplemented for now!
+;;; (issue-file   agetty-issue-file             ;plain-file
+;;;               (default #f))
+  )
+
+(define agetty-shepherd-service
+  (match-lambda
+    (($ <agetty-configuration> agetty tty term baud-rate auto-login
+        login-program login-pause? eight-bits? no-reset? remote? flow-control?
+        host no-issue? init-string no-clear? local-line extract-baud?
+        skip-login? no-newline? login-options chroot hangup? timeout
+        detect-case? wait-cr? no-hints? no-hostname? long-hostname? erase-chars
+        kill-chars chdir delay nice)
+     (list
+       (shepherd-service
+         (documentation "Run agetty on a tty.")
+         (provision (list (symbol-append 'term- (string->symbol tty))))
+
+         ;; Same comment as for mingetty-shepherd-service.
+         (requirement '(user-processes host-name udev))
+
+         (start #~(make-forkexec-constructor
+                    (list #$ (file-append util-linux "/sbin/agetty")
+                          #$@(if eight-bits?
+                                 #~("--8bits")
+                                 #~())
+                          #$@(if no-reset?
+                                 #~("--noreset")
+                                 #~())
+                          #$@(if remote?
+                                 #~("--remote")
+                                 #~())
+                          #$@(if flow-control?
+                                 #~("--flow-control")
+                                 #~())
+                          #$@(if host
+                                 #~("--host" #$host)
+                                 #~())
+                          #$@(if no-issue?
+                                 #~("--noissue")
+                                 #~())
+                          #$@(if init-string
+                                 #~("--init-string" #$init-string)
+                                 #~())
+                          #$@(if no-clear?
+                                 #~("--noclear")
+                                 #~())
+                          ;; This doesn't work as expected. According to
+                          ;; agetty(8), if this option is not passed, then the
+                          ;; default is 'auto'. However, in my tests, when that
+                          ;; option is selected, agetty never presents the login
+                          ;; prompt, and the term-ttyS0 service respawns every
+                          ;; few seconds.
+                          #$@(if local-line
+                                 #~(#$(match local-line
+                                        ('auto "--local-line=auto")
+                                        ('always "--local-line=always")
+                                        ('never "-local-line=never")))
+                                 #~())
+                          #$@(if extract-baud?
+                                 #~("--extract-baud")
+                                 #~())
+                          #$@(if skip-login?
+                                 #~("--skip-login")
+                                 #~())
+                          #$@(if no-newline?
+                                 #~("--nonewline")
+                                 #~())
+                          #$@(if login-options
+                                 #~("--login-options" #$login-options)
+                                 #~())
+                          #$@(if chroot
+                                 #~("--chroot" #$chroot)
+                                 #~())
+                          #$@(if hangup?
+                                 #~("--hangup")
+                                 #~())
+                          #$@(if timeout
+                                 #~("--timeout" #$(number->string timeout))
+                                 #~())
+                          #$@(if detect-case?
+                                 #~("--detect-case")
+                                 #~())
+                          #$@(if wait-cr?
+                                 #~("--wait-cr")
+                                 #~())
+                          #$@(if no-hints?
+                                 #~("--nohints?")
+                                 #~())
+                          #$@(if no-hostname?
+                                 #~("--nohostname")
+                                 #~())
+                          #$@(if long-hostname?
+                                 #~("--long-hostname")
+                                 #~())
+                          #$@(if erase-chars
+                                 #~("--erase-chars" #$erase-chars)
+                                 #~())
+                          #$@(if kill-chars
+                                 #~("--kill-chars" #$kill-chars)
+                                 #~())
+                          #$@(if chdir
+                                 #~("--chdir" #$chdir)
+                                 #~())
+                          #$@(if delay
+                                 #~("--delay" #$(number->string delay))
+                                 #~())
+                          #$@(if nice
+                                 #~("--nice" #$(number->string nice))
+                                 #~())
+                          #$@(if auto-login
+                                 #~("--autologin" #$auto-login)
+                                 #~())
+                          #$@(if login-program
+                                 #~("--login-program" #$login-program)
+                                 #~())
+                          #$@(if login-pause?
+                                 #~("--login-pause")
+                                 #~())
+                          #$tty
+                          #$@(if baud-rate
+                                 #~(#$baud-rate)
+                                 #~())
+                          #$@(if term
+                                 #~(#$term)
+                                 #~()))))
+         (stop #~(make-kill-destructor)))))))
+
+(define agetty-service-type
+  (service-type (name 'agetty)
+                (extensions (list (service-extension shepherd-root-service-type
+                                                     agetty-shepherd-service)))))
+
+(define* (agetty-service config)
+  "Return a service to run agetty according to @var{config}, which specifies
+the tty to run, among other things."
+  (service agetty-service-type config))
+
 (define-record-type* <mingetty-configuration>
   mingetty-configuration make-mingetty-configuration
   mingetty-configuration?
-- 
2.11.1


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [V2 PATCH 1/1] services: Add agetty service.
  2017-02-16  7:06   ` [V2 PATCH " Leo Famulari
@ 2017-02-17  7:48     ` Ricardo Wurmus
  2017-02-17 14:24       ` Leo Famulari
  2017-02-17 18:35     ` myglc2
  1 sibling, 1 reply; 11+ messages in thread
From: Ricardo Wurmus @ 2017-02-17  7:48 UTC (permalink / raw)
  To: Leo Famulari; +Cc: guix-devel


Leo Famulari <leo@famulari.name> writes:

> On Tue, Feb 14, 2017 at 07:24:17PM -0500, Leo Famulari wrote:
>> This 'extra' is a time-saving kludge. I'll add fields for all of
>> agetty's configuration options once I'm satisfied that the service works
>> on GuixSD.
>
> Here's a patch that exposes (almost all) of agetty's command-line
> options.
>
> Is this the right way? Or would we rather wrap only the most
> commonly-used options, and leave an "escape hatch" as in the first
> version of the patch? If so, which options should we expose in Scheme?

That’s hard to say.  I like to *always* keep an escape hatch, which is
useful in case we are too slow to adapt our code to changes introduced
by new versions.  In my opinion this version of the patch is better
because it exposes more values; it would be even better if it added a
general purpose escape hatch.

> I'll wait for feedback before writing the documentation.

Okay.  (Can we generate documentation for the individual fields somehow?)

Some naive comments follow.

> From 215ad705a933fda1170a5883277cd9a68db693e0 Mon Sep 17 00:00:00 2001
> From: Leo Famulari <leo@famulari.name>
> Date: Tue, 14 Feb 2017 11:28:04 -0500
> Subject: [PATCH] services: Add agetty service.
>
> * gnu/services/base.scm (<agetty-configuration>): New record type.
> (agetty-shepherd-service, agetty-service): New procedures.
> (agetty-service-type): New variable.
> ---
[…]

> +(define-record-type* <agetty-configuration>
> +  agetty-configuration make-agetty-configuration
> +  agetty-configuration?
> +  (agetty         agetty-configuration-agetty   ;<package>
> +                  (default util-linux))
> +  (tty            agetty-configuration-tty)     ;string
> +  (term           agetty-term                   ;string
> +                  (default #f))
> +  (baud-rate      agetty-baud-rate              ;string
> +                  (default #f))
> +  (auto-login     agetty-auto-login             ;string
> +                  (default #f))
> +  (login-program  agetty-login-program          ;gexp
> +                  (default (file-append shadow "/bin/login")))
> +  (login-pause?   agetty-login-pause?           ;Boolean
> +                  (default #f))
> +  (eight-bits?    agetty-eight-bits?            ;Boolean
> +                  (default #f))
> +  (no-reset?      agetty-no-reset?              ;Boolean
> +                  (default #f))
> +  (remote?        agetty-remote?                ;Boolean
> +                  (default #f))
> +  (flow-control?  agetty-flow-control?          ;Boolean
> +                  (default #f))
> +  (host           agetty-host                   ;string
> +                  (default #f))
> +  (no-issue?      agetty-no-issue?              ;Boolean
> +                  (default #f))
> +  (init-string    agetty-init-string            ;string
> +                  (default #f))
> +  (no-clear?      agetty-no-clear?              ;Boolean
> +                  (default #f))
> +  (local-line     agetty-local-line             ;always | never | auto
> +                  (default #f))
> +  (extract-baud?  agetty-extract-baud?          ;Boolean
> +                  (default #f))
> +  (skip-login?    agetty-skip-login?            ;Boolean
> +                  (default #f))
> +  (no-newline?    agetty-no-newline?            ;Boolean
> +                  (default #f))
> +  (login-options  agetty-login-options          ;string
> +                  (default #f))
> +  (chroot         agetty-chroot                 ;string
> +                  (default #f))
> +  (hangup?        agetty-hangup?                ;Boolean
> +                  (default #f))
> +  (timeout        agetty-timeout                ;integer
> +                  (default #f))
> +  (detect-case?   agetty-detect-case?           ;Boolean
> +                  (default #f))
> +  (wait-cr?       agetty-wait-cr?               ;Boolean
> +                  (default #f))
> +  (no-hints?      agetty-no-hints?              ;Boolean
> +                  (default #f))
> +  (no-hostname?   agetty-no hostname?           ;Boolean
> +                  (default #f))
> +  (long-hostname? agetty-long-hostname?         ;Boolean
> +                  (default #f))
> +  (erase-chars    agetty-erase-chars            ;string
> +                  (default #f))
> +  (kill-chars     agetty-kill-chars             ;string
> +                  (default #f))
> +  (chdir          agetty-chdir                  ;string
> +                  (default #f))
> +  (delay          agetty-delay                  ;integer
> +                  (default #f))
> +  (nice           agetty-nice                   ;integer
> +                  (default #f))
> +;;; XXX Unimplemented for now!
> +;;; (issue-file   agetty-issue-file             ;plain-file
> +;;;               (default #f))
> +  )
> +
> +(define agetty-shepherd-service
> +  (match-lambda
> +    (($ <agetty-configuration> agetty tty term baud-rate auto-login
> +        login-program login-pause? eight-bits? no-reset? remote? flow-control?
> +        host no-issue? init-string no-clear? local-line extract-baud?
> +        skip-login? no-newline? login-options chroot hangup? timeout
> +        detect-case? wait-cr? no-hints? no-hostname? long-hostname? erase-chars
> +        kill-chars chdir delay nice)
> +     (list
> +       (shepherd-service
> +         (documentation "Run agetty on a tty.")
> +         (provision (list (symbol-append 'term- (string->symbol tty))))
> +
> +         ;; Same comment as for mingetty-shepherd-service.
> +         (requirement '(user-processes host-name udev))
> +
> +         (start #~(make-forkexec-constructor
> +                    (list #$ (file-append util-linux "/sbin/agetty")
> +                          #$@(if eight-bits?
> +                                 #~("--8bits")
> +                                 #~())
> +                          #$@(if no-reset?
> +                                 #~("--noreset")
> +                                 #~())
> +                          #$@(if remote?
> +                                 #~("--remote")
> +                                 #~())

Looking at all the syntactic noise makes me long for some prettier
abstraction here, but I can’t think of anything that would make this
considerably prettier.  Oh well… ¯\_(ツ)_/¯

> +                          ;; This doesn't work as expected. According to
> +                          ;; agetty(8), if this option is not passed, then the
> +                          ;; default is 'auto'. However, in my tests, when that
> +                          ;; option is selected, agetty never presents the login
> +                          ;; prompt, and the term-ttyS0 service respawns every
> +                          ;; few seconds.

Maybe add a FIXME here, so we can more easily find it.  It might also be
worth opening a bug report after merging this, so that we can track it.

> +                          #$@(if no-newline?
> +                                 #~("--nonewline")
> +                                 #~())

I’m sure this will trip me up in the future.  “nonewline” vs
“no-newline” – I prefer your choice, but the double negative is tough
for me…

> +                          #$@(if no-hostname?
> +                                 #~("--nohostname")
> +                                 #~())
> +                          #$@(if long-hostname?
> +                                 #~("--long-hostname")
> +                                 #~())

Should we try to prevent nonsensical combinations of options?
Would it just be more confusing to merge “no-hostname?” and “long-hostname?” as
“print-hostname 'none 'long 'short”?

Everything else looks good to me!

--
Ricardo

GPG: BCA6 89B6 3655 3801 C3C6  2150 197A 5888 235F ACAC
https://elephly.net

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [V2 PATCH 1/1] services: Add agetty service.
  2017-02-17  7:48     ` Ricardo Wurmus
@ 2017-02-17 14:24       ` Leo Famulari
  0 siblings, 0 replies; 11+ messages in thread
From: Leo Famulari @ 2017-02-17 14:24 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: guix-devel

[-- Attachment #1: Type: text/plain, Size: 3205 bytes --]

On Fri, Feb 17, 2017 at 08:48:28AM +0100, Ricardo Wurmus wrote:
> Leo Famulari <leo@famulari.name> writes:
> > Is this the right way? Or would we rather wrap only the most
> > commonly-used options, and leave an "escape hatch" as in the first
> > version of the patch? If so, which options should we expose in Scheme?
> 
> That’s hard to say.  I like to *always* keep an escape hatch, which is
> useful in case we are too slow to adapt our code to changes introduced
> by new versions.  In my opinion this version of the patch is better
> because it exposes more values; it would be even better if it added a
> general purpose escape hatch.

Okay.

> Okay.  (Can we generate documentation for the individual fields somehow?)

Well, I'd really like that! IMO, the service that exposes most of
agetty's options can be fully understood by reading the agetty(8) man
page. I don't look forward to paraphrasing agetty(8).

> Some naive comments follow.

It's okay, my implementation is a naive copy-and-extend of the mingetty
service :)

[...]

> > +                          #$@(if remote?
> > +                                 #~("--remote")
> > +                                 #~())
> 
> Looking at all the syntactic noise makes me long for some prettier
> abstraction here, but I can’t think of anything that would make this
> considerably prettier.  Oh well… ¯\_(ツ)_/¯

Agreed but, on the other hand, this is the level of abstraction that I
understand. So, maybe that's a good thing for other Scheme newbies.

> Maybe add a FIXME here, so we can more easily find it.  It might also be
> worth opening a bug report after merging this, so that we can track it.

Okay.

> 
> > +                          #$@(if no-newline?
> > +                                 #~("--nonewline")
> > +                                 #~())
> 
> I’m sure this will trip me up in the future.  “nonewline” vs
> “no-newline” – I prefer your choice, but the double negative is tough
> for me…

I tried to copy the upstream configuration options but make them
"Scheme-y" stylistically.

> > +                          #$@(if no-hostname?
> > +                                 #~("--nohostname")
> > +                                 #~())
> > +                          #$@(if long-hostname?
> > +                                 #~("--long-hostname")
> > +                                 #~())
> 
> Should we try to prevent nonsensical combinations of options?
> Would it just be more confusing to merge “no-hostname?” and “long-hostname?” as
> “print-hostname 'none 'long 'short”?

Sure... volunteers welcome :) 

It was suggested in the past to reimplement mingetty in Scheme (it's
~400 lines of C). That's a case where we can really understand and
control how the program is used. But for this case, we'd need an agetty
expert.

We could also add an activation phase that creates device nodes beyond
ttyS0, because only ttyS0 is created on GuixSD currently. Either that or
limit this service to ttyS0, instead of leaving the choice to the user.
That's something that I will try to do.

Thanks for your review!

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [V2 PATCH 1/1] services: Add agetty service.
  2017-02-16  7:06   ` [V2 PATCH " Leo Famulari
  2017-02-17  7:48     ` Ricardo Wurmus
@ 2017-02-17 18:35     ` myglc2
  2017-02-17 22:59       ` Leo Famulari
  1 sibling, 1 reply; 11+ messages in thread
From: myglc2 @ 2017-02-17 18:35 UTC (permalink / raw)
  To: Leo Famulari; +Cc: guix-devel

On 02/16/2017 at 02:06 Leo Famulari writes:

> On Tue, Feb 14, 2017 at 07:24:17PM -0500, Leo Famulari wrote:
>> This 'extra' is a time-saving kludge. I'll add fields for all of
>> agetty's configuration options once I'm satisfied that the service works
>> on GuixSD.
>
> Here's a patch that exposes (almost all) of agetty's command-line
> options.
>
> Is this the right way? Or would we rather wrap only the most
> commonly-used options, and leave an "escape hatch" as in the first
> version of the patch? If so, which options should we expose in Scheme?
>
> I'll wait for feedback before writing the documentation.

Hi Leo,

I think that what you have is great. With this in my system config ...

    (agetty-service (agetty-configuration
		     (tty "ttyS1")
		     (baud-rate "115200")))

... it works painlessly on a headless GuixSD server over IPMI.  I think
you can put a brief example in the doc, refer the user to the code and
the agetty man page for more info, and declare victory.

But let me digress a bit on this topic. What if, in situations like
this, Guix provided an easy way to export the "native config" generated
by Guix?

Then we could tell the user ...

1) If you want to know exactly what we are doing, export the native
config and read the native doc.

2) If you want features we don't support, export the native config, read
the doc, modify it, and feed it into the "native config hatch."

With this approach, we could implement and document only "key features"
with a clear conscience.  When we haven't implemented a feature the user
needs they will be no worse off that they were before. In fact, they
will usually be ahead, because Guix has taken care of the general
requirements and provided a sound starting point for a native config.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [V2 PATCH 1/1] services: Add agetty service.
  2017-02-17 18:35     ` myglc2
@ 2017-02-17 22:59       ` Leo Famulari
  2017-02-18  1:23         ` myglc2
  2017-03-07 14:43         ` Ludovic Courtès
  0 siblings, 2 replies; 11+ messages in thread
From: Leo Famulari @ 2017-02-17 22:59 UTC (permalink / raw)
  To: myglc2; +Cc: guix-devel

On Fri, Feb 17, 2017 at 01:35:44PM -0500, myglc2 wrote:
> Hi Leo,
> 
> I think that what you have is great. With this in my system config ...
> 
>     (agetty-service (agetty-configuration
> 		     (tty "ttyS1")
> 		     (baud-rate "115200")))
>
> ... it works painlessly on a headless GuixSD server over IPMI.  I think
> you can put a brief example in the doc, refer the user to the code and
> the agetty man page for more info, and declare victory.

Awesome!

Veering off-topic, I wonder what created that device node /dev/ttyS1? I
have 32 of them, but (gnu build linux-boot) appears to only create the
first one:

https://git.savannah.gnu.org/cgit/guix.git/tree/gnu/build/linux-boot.scm#n160

> But let me digress a bit on this topic. What if, in situations like
> this, Guix provided an easy way to export the "native config" generated
> by Guix?
> 
> Then we could tell the user ...
> 
> 1) If you want to know exactly what we are doing, export the native
> config and read the native doc.
> 
> 2) If you want features we don't support, export the native config, read
> the doc, modify it, and feed it into the "native config hatch."
> 
> With this approach, we could implement and document only "key features"
> with a clear conscience.  When we haven't implemented a feature the user
> needs they will be no worse off that they were before. In fact, they
> will usually be ahead, because Guix has taken care of the general
> requirements and provided a sound starting point for a native config.

An interesting idea! I guess the implementation would vary based on
services that use a configuration file (like nginx) and those that are
configured on the command-line (like agetty). But I'm still finding my
way around services, in general, so I'm not sure.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [V2 PATCH 1/1] services: Add agetty service.
  2017-02-17 22:59       ` Leo Famulari
@ 2017-02-18  1:23         ` myglc2
  2017-03-07 14:43         ` Ludovic Courtès
  1 sibling, 0 replies; 11+ messages in thread
From: myglc2 @ 2017-02-18  1:23 UTC (permalink / raw)
  To: Leo Famulari; +Cc: guix-devel

On 02/17/2017 at 17:59 Leo Famulari writes:

> On Fri, Feb 17, 2017 at 01:35:44PM -0500, myglc2 wrote:
>> Hi Leo,
>> 
>> I think that what you have is great. With this in my system config ...
>> 
>>     (agetty-service (agetty-configuration
>> 		     (tty "ttyS1")
>> 		     (baud-rate "115200")))
>>
>> ... it works painlessly on a headless GuixSD server over IPMI.  I think
>> you can put a brief example in the doc, refer the user to the code and
>> the agetty man page for more info, and declare victory.
>
> Awesome!
>
> Veering off-topic, I wonder what created that device node /dev/ttyS1? I
> have 32 of them, but (gnu build linux-boot) appears to only create the
> first one:
>
> https://git.savannah.gnu.org/cgit/guix.git/tree/gnu/build/linux-boot.scm#n160

I found the serial line on my server by doing ...

g1@g1 ~$ dmesg | grep tty
[    0.000000] console [tty0] enabled
[    2.192386] 00:07: ttyS1 at I/O 0x2f8 (irq = 3, base_baud = 115200) is a 16550A

... but linux-boot.scm only specifies ttyS0 ...

 160    ;; Serial line.  
 161    (mknod (scope "dev/ttyS0") 'char-special #o660  
 162           (device-number 4 64))  

... but gnu/packages/linux-libre-4.9-i686.conf has ...

CONFIG_SND_SERIAL_U16550=m

... so maybe the kernel probes for and finds the UART.

>> But let me digress a bit on this topic. What if, in situations like
>> this, Guix provided an easy way to export the "native config" generated
>> by Guix?
>> 
>> Then we could tell the user ...
>> 
>> 1) If you want to know exactly what we are doing, export the native
>> config and read the native doc.
>> 
>> 2) If you want features we don't support, export the native config, read
>> the doc, modify it, and feed it into the "native config hatch."
>> 
>> With this approach, we could implement and document only "key features"
>> with a clear conscience.  When we haven't implemented a feature the user
>> needs they will be no worse off that they were before. In fact, they
>> will usually be ahead, because Guix has taken care of the general
>> requirements and provided a sound starting point for a native config.
>
> An interesting idea! I guess the implementation would vary based on
> services that use a configuration file (like nginx) and those that are
> configured on the command-line (like agetty). But I'm still finding my
> way around services, in general, so I'm not sure.

Agreed. Ideally there would be a strategy and reusable modules that
supports either approach, or a mix. Then maybe this would lighten the
effort required for each service and help regularize these interfaces.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [V2 PATCH 1/1] services: Add agetty service.
  2017-02-17 22:59       ` Leo Famulari
  2017-02-18  1:23         ` myglc2
@ 2017-03-07 14:43         ` Ludovic Courtès
  1 sibling, 0 replies; 11+ messages in thread
From: Ludovic Courtès @ 2017-03-07 14:43 UTC (permalink / raw)
  To: Leo Famulari; +Cc: guix-devel, myglc2

Leo Famulari <leo@famulari.name> skribis:

> Veering off-topic, I wonder what created that device node /dev/ttyS1? I
> have 32 of them, but (gnu build linux-boot) appears to only create the
> first one:

udev did!

Ludo’.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2017-03-07 14:43 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-15  0:12 [PATCH 1/1] services: Add agetty service Leo Famulari
2017-02-15  0:24 ` Leo Famulari
2017-02-15 15:21   ` myglc2
2017-02-15 19:38   ` Leo Famulari
2017-02-16  7:06   ` [V2 PATCH " Leo Famulari
2017-02-17  7:48     ` Ricardo Wurmus
2017-02-17 14:24       ` Leo Famulari
2017-02-17 18:35     ` myglc2
2017-02-17 22:59       ` Leo Famulari
2017-02-18  1:23         ` myglc2
2017-03-07 14:43         ` Ludovic Courtès

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.