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

From: muradm <[email-masked]>
Date: Sat, 4 Jan 2025 19:58:43 +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: I7af64ac6f12cc30ee358df73db57b41ac42b8aca
---
 doc/guix.texi         | 38 ++++++++++++++++++++++++++++++++++++++
 gnu/services/base.scm | 31 +++++++++++++++++++++++++++++++
 2 files changed, 69 insertions(+)

diff --git a/doc/guix.texi b/doc/guix.texi
index 6d0c349b1a..819d1de79f 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -20642,6 +20642,44 @@ Base Services
 @end table
 @end deftp
 
+@deftp {Data Type} greetd-gtkgreet-sway-session
+Configuration record for the gtkgreet greetd greeter.  Can be used as
+following:
+
+@lisp
+  (greetd-configuration
+   ;; Graphical greeter require additional group membership.
+   (greeter-supplementary-groups (list "video" "input" "seat"))
+   (terminals
+    (list (greetd-terminal-configuration
+           (terminal-vt "1")
+           (terminal-switch #t)
+           (default-session-command
+            (greetd-gtkgreet-sway-session
+             (command
+              (greetd-user-session
+               ;; signal to our .bashrc that we want wayland compositor
+               (xdg-session-type "wayland")))))))))
+@end lisp
+
+@table @asis
+@item @code{sway} (default: @code{sway})
+The package with @command{/bin/sway} and @command{/bin/swaymsg} commands.
+
+@item @code{sway-config} (default: @code{(plain-file "greetd-wlgreet-sway-config" "")})
+Extra configuration for sway to be included before executing greeter.
+
+@item @code{gtkgreet} (default: @code{gtkgreet})
+The package with @command{/bin/gtkgreet} command.
+
+@item @code{command} (default: @code{(greetd-user-session)})
+Command to be started by @command{/bin/agreety} on successful login.
+Normally should be a variation of @code{greetd-user-session}, but could
+be any @code{gexp->script} like object.
+
+@end table
+@end deftp
+
 @deftp {Data Type} greetd-wlgreet-color
 
 @table @asis
diff --git a/gnu/services/base.scm b/gnu/services/base.scm
index 4105da6c05..05c0a1a4e9 100644
--- a/gnu/services/base.scm
+++ b/gnu/services/base.scm
@@ -276,6 +276,7 @@ (define-module (gnu services base)
             greetd-terminal-configuration
             greetd-user-session
             greetd-agreety-session
+            greetd-gtkgreet-sway-session
             greetd-wlgreet-color
             greetd-wlgreet-configuration
             greetd-wlgreet-sway-session
@@ -3470,6 +3471,36 @@ (define (make-greetd-sway-greeter-command sway sway-config)
            (dup2 1 2)
            (execl #$sway-bin #$sway-bin "-d" "-c" #$sway-config))))))
 
+(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-config greetd-wlgreet-sway-session-sway-config
+               (default (plain-file "greetd-wlgreet-sway-config" "")))
+  (gtkgreet greetd-gtkgreet-sway-session-gtkgreet (default gtkgreet))
+  (command greetd-gtkgreet-sway-session-command (default (greetd-user-session))))
+
+(define make-greetd-gtkgreet-sway-session-sway-config
+  (match-lambda
+    (($ <greetd-gtkgreet-sway-session> sway sway-config gtkgreet command)
+     (let ((gtkgreet-bin (file-append gtkgreet "/bin/gtkgreet"))
+           (swaymsg-bin (file-append sway "/bin/swaymsg")))
+       (mixed-text-file
+        "gtkgreet-sway-config"
+        "include " sway-config "\n"
+        "xwayland disable\n"
+        "exec \"" gtkgreet-bin " -l -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-wlgreet-color>
   greetd-wlgreet-color make-greetd-wlgreet-color greetd-wlgreet-color?
   (red greetd-wlgreet-color-red)
-- 
2.47.1