Subject: [bug#75270] [PATCH v6 3/3] services: greetd: Add new gtkgreet greeter.

From: muradm <[email-masked]>
Date: Wed, 5 Feb 2025 16:09:33 +0300

* gnu/services/base.scm (<greetd-gtkgreet-sway-session>): New record,
represents 'gtkgreet' greeter session configuration.
* doc/guix.texi (Base Services): Document new 'gtkgreet' greeter.

Change-Id: I2e8b5710965faa05795af1d0b2a0e2f774af1d5a
---
 doc/guix.texi         | 47 +++++++++++++++++++++++++++++++++++++++++--
 gnu/services/base.scm | 36 +++++++++++++++++++++++++++++++++
 2 files changed, 81 insertions(+), 2 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 2a0fa6b37d1..b25ead9d587 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -20599,8 +20599,8 @@ Base Services
 The user to use for running the greeter.
 
 @item @code{default-session-command} (default: @code{(greetd-agreety-session)})
-Can be either @code{greetd-agreety-session}, @code{greetd-wlgreet-sway-session} or
-@code{gexp->script} like object to use as greeter.
+Can be either @code{greetd-agreety-session}, @code{greetd-wlgreet-sway-session},
+@code{greetd-gtkgreet-sway-session} or file-like object to use as greeter.
 
 @end table
 @end deftp
@@ -20725,6 +20725,49 @@ Base Services
 @end lisp
 @end deftp
 
+@deftp {Data Type} greetd-gtkgreet-sway-session
+Configuration record for the gtkgreet greetd greeter.  Can be used as
+following:
+
+@lisp
+  (greetd-configuration
+   ;; The graphical greeter requires additional groups membership.
+   (greeter-supplementary-groups (list "video" "input" "seat"))
+   (terminals
+    (list (greetd-terminal-configuration
+           ;; Sway requires seatd service.
+           (extra-shepherd-requirement '(seatd))
+           (terminal-vt "1")
+           (terminal-switch #t)
+           (default-session-command
+            (greetd-gtkgreet-sway-session
+             (command
+              (greetd-user-session
+               ;; Optionally signal to .bashrc that we want wayland compositor.
+               (xdg-session-type "wayland")))))))))
+@end lisp
+
+@table @asis
+@item @code{sway} (default: @code{sway})
+The package providing the @command{sway} and @command{swaymsg} commands.
+
+@item @code{sway-configuration} (default: @code{#f})
+Extra file-like configuration for sway to be included before executing
+the greeter.
+
+@item @code{gtkgreet} (default: @code{gtkgreet})
+The package with @command{gtkgreet} command.
+
+@item @code{gtkgreet-style} (default: @code{#f})
+Extra file-like CSS stylesheet to customize the GTK look.
+
+@item @code{command} (default: @code{(greetd-user-session)})
+Command to be started by @command{gtkgreet} on successful login, an
+instance of @code{greetd-user-session}.
+
+@end table
+@end deftp
+
 @node Scheduled Job Execution
 @subsection Scheduled Job Execution
 
diff --git a/gnu/services/base.scm b/gnu/services/base.scm
index 8c9947c1914..86d8683a520 100644
--- a/gnu/services/base.scm
+++ b/gnu/services/base.scm
@@ -279,6 +279,7 @@ (define-module (gnu services base)
             greetd-wlgreet-session  ; deprecated
             greetd-wlgreet-configuration
             greetd-wlgreet-sway-session
+            greetd-gtkgreet-sway-session
 
             %base-services))
 
@@ -3710,6 +3711,41 @@ (define-gexp-compiler (greetd-wlgreet-sway-session-compiler
         sway
         (make-greetd-wlgreet-sway-session-sway-config s))))))
 
+(define-record-type* <greetd-gtkgreet-sway-session>
+  greetd-gtkgreet-sway-session make-greetd-gtkgreet-sway-session
+  greetd-gtkgreet-sway-session?
+  (sway greetd-gtkgreet-sway-session-sway (default sway))
+  (sway-configuration greetd-gtkgreet-sway-session-sway-configuration
+                      (default #f))
+  (gtkgreet greetd-gtkgreet-sway-session-gtkgreet (default gtkgreet))
+  (gtkgreet-style greetd-gtkgreet-sway-session-gtkgreet-style (default #f))
+  (command greetd-gtkgreet-sway-session-command
+           (default (greetd-user-session))))
+
+(define (make-greetd-gtkgreet-sway-session-sway-config session)
+  (match-record session <greetd-gtkgreet-sway-session>
+                (sway sway-configuration gtkgreet gtkgreet-style command)
+    (let ((gtkgreet-bin (file-append gtkgreet "/bin/gtkgreet"))
+          (swaymsg-bin (file-append sway "/bin/swaymsg")))
+      (mixed-text-file
+       "gtkgreet-sway-config"
+       (if sway-configuration
+           #~(string-append "include " #$sway-configuration "\n")
+           "")
+       "xwayland disable\n"
+       "exec \"" gtkgreet-bin " -l"
+       (if gtkgreet-style #~(string-append " -s " #$gtkgreet-style) "")
+       " -c " command "; " swaymsg-bin " exit\"\n"))))
+
+(define-gexp-compiler (greetd-gtkgreet-sway-session-compiler
+                       (session <greetd-gtkgreet-sway-session>)
+                       system target)
+  (match-record session <greetd-gtkgreet-sway-session> (sway)
+    (lower-object
+     (make-greetd-sway-greeter-command
+      sway
+      (make-greetd-gtkgreet-sway-session-sway-config session)))))
+
 (define-record-type* <greetd-terminal-configuration>
   greetd-terminal-configuration make-greetd-terminal-configuration
   greetd-terminal-configuration?
-- 
2.47.1