Subject: [PATCH] doc: Add auto login to tty guide to the cookbook.

From: Joshua Branson <[email-masked]>
Date: Tue, 6 Jul 2021 02:20:04 -0400

From: Joshua Branson <[email-masked]>

* doc/guix-cookbook.texi (System Configuration): Add a brief guide that
explains auto login to a TTY.  This is a follow up to bug 48974.
---
 doc/guix-cookbook.texi | 59 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 58 insertions(+), 1 deletion(-)

diff --git a/doc/guix-cookbook.texi b/doc/guix-cookbook.texi
index 1cddaa7faf..47f8d60ade 100644
--- a/doc/guix-cookbook.texi
+++ b/doc/guix-cookbook.texi
@@ -17,6 +17,7 @@ Copyright @copyright{} 2020 Marcin Karpezo@*
 Copyright @copyright{} 2020 Brice Waegeneire@*
 Copyright @copyright{} 2020 André Batista@*
 Copyright @copyright{} 2020 Christopher Lemmer Webber
+Copyright @copyright{} 2021 Joshua Branson@*
 
 Permission is granted to copy, distribute and/or modify this document
 under the terms of the GNU Free Documentation License, Version 1.3 or
@@ -85,7 +86,7 @@ Packaging
 
 System Configuration
 
-* Customizing the Kernel::      Creating and using a custom Linux kernel
+* Auto Login to TTY::            Set up auto login via a TTY

 @end detailmenu
@@ -1353,6 +1354,7 @@ chapter is to demonstrate some advanced configuration concepts.
 reference.
 
 @menu
+* Auto Login to TTY::            Set up auto login via a TTY.
 * Customizing the Kernel::       Creating and using a custom Linux kernel on Guix System.
 * Guix System Image API::        Customizing images to target specific platforms.
 * Connecting to Wireguard VPN::  Connecting to a Wireguard VPN.
@@ -1363,6 +1365,61 @@ reference.
 * Setting up NGINX with Lua:: Configuring NGINX web-server to load Lua modules.
 @end menu
 
+@node Auto Login to TTY
+@section Auto Login to TTY
+
+Guix System currently offers auto login to a tty via @code{mingetty},
+but a newcomer to Guix System may be unfamiliar with setting up auto
+login.  First, a note of caution.  Setting up auto login to a tty, means
+that anyone can turn on your computer and run commands as your regular
+user. If you have encrypted your @code{/} partition, and thus need to
+enter in a passphrase at boot, then perhaps auto login is a secure and
+convenient option for you.
+
+Here is how one might go about setting up auto login to a tty:
+
+@lisp
+(define (auto-login-to-tty config tty user)
+  (if (string=? tty (mingetty-configuration-tty config))
+        (mingetty-configuration
+         (inherit config)
+         (auto-login user))
+        config))
+
+(define %my-base-services
+  (modify-services %base-services
+    (mingetty-service-type config =>
+                           (auto-login-to-tty config "tty3" "joshua"))))
+
+(operating-system
+    (host-name "dobby")
+    ...
+    (services
+     (append
+      (list (service dhcp-client-service-type))
+      %my-base-services)))
+@end lisp
+
+Note that the above code automatically logs the user into @code{tty3}.
+Any TTY will work, though perhaps it is best not to use @code{tty1},
+which is reserved for error messages.
+
+You could also start your graphical environment via your
+@code{~/.bash_profile}.  Here is an example script to auto start the
+sway window manager:
+
+@example shell
+# Honor per-interactive-shell startup file
+if [ -f ~/.bashrc ]; then . ~/.bashrc; fi
+
+if [[ -z $DISPLAY ]] && [[ $(tty) = /dev/tty3 ]]; then
+    exec dbus-run-session sway
+fi
+@end example
+
+When Guix Home is merged, the above bash script may be replaced by a
+@code{home.scm} file.
+
 @node Customizing the Kernel
 @section Customizing the Kernel
 
-- 
2.32.0