Subject: [bug#49969] [PATCH v5 03/10] gnu: freedesktop: Add greetd 0.7.0

From: muradm <[email-masked]>
Date: Mon, 23 Aug 2021 00:50:41 +0300

Also adds greetd-next which is built from master that includes
configurable terminal switch flag, required for smooth operation.
See https://lists.sr.ht/~kennylevinsen/greetd-devel/patches/24441
for more details.

* gnu/packages/freedesktop.scm (greetd): Add greetd 0.7.0
---
 gnu/packages/freedesktop.scm | 120 +++++++++++++++++++++++++++++++++++
 1 file changed, 120 insertions(+)

diff --git a/gnu/packages/freedesktop.scm b/gnu/packages/freedesktop.scm
index 693a79c738..aa83eb0a37 100644
--- a/gnu/packages/freedesktop.scm
+++ b/gnu/packages/freedesktop.scm
@@ -24,6 +24,7 @@
 ;;; Copyright © 2020 Raghav Gururajan <[email-masked]>
 ;;; Copyright © 2021 Brendan Tildesley <[email-masked]>
 ;;; Copyright © 2021 pineapples <[email-masked]>
+;;; Copyright © 2021 muradm <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -46,6 +47,7 @@
   #:use-module (guix packages)
   #:use-module (guix download)
   #:use-module (guix git-download)
+  #:use-module (guix build-system cargo)
   #:use-module (guix build-system cmake)
   #:use-module (guix build-system gnu)
   #:use-module (guix build-system meson)
@@ -62,6 +64,7 @@
   #:use-module (gnu packages check)
   #:use-module (gnu packages cmake)
   #:use-module (gnu packages compression)
+  #:use-module (gnu packages crates-io)
   #:use-module (gnu packages cryptsetup)
   #:use-module (gnu packages databases)
   #:use-module (gnu packages disk)
@@ -862,6 +865,123 @@ that require it.  It also provides a universal seat management library that
 allows applications to use whatever seat management is available.")
     (license license:expat)))
 
+(define-public greetd
+  (package
+    (name "greetd")
+    (version "0.7.0")
+    (home-page "https://git.sr.ht/~kennylevinsen/greetd")
+    (source (origin
+              (method git-fetch)
+              (uri (git-reference
+                    (url home-page)
+                    (commit version)))
+              (file-name (git-file-name name version))
+              (sha256
+               (base32 "0lmwr5ld9x2wlq00i7mjgm9by8zndiq9girj8g93k0kww9zbgr3g"))))
+    (build-system cargo-build-system)
+    (arguments
+     `(#:cargo-inputs
+       (("rust-nix" ,rust-nix-0.17)
+        ("rust-pam-sys" ,rust-pam-sys-0.5.6)
+        ("rust-rpassword" ,rust-rpassword-4)
+        ("rust-users" ,rust-users-0.9)
+        ("rust-serde" ,rust-serde-1)
+        ("rust-serde-json" ,rust-serde-json-1)
+        ("rust-libc" ,rust-libc-0.2)
+        ("rust-tokio" ,rust-tokio-0.2)
+        ("rust-getopts" ,rust-getopts-0.2)
+        ("rust-thiserror" ,rust-thiserror-1)
+        ("rust-async-trait" ,rust-async-trait-0.1)
+        ("rust-enquote" ,rust-enquote-1))
+       #:phases
+       (modify-phases %standard-phases
+         ;; issue with terminal activation solved by this feature:
+         ;; https://lists.sr.ht/~kennylevinsen/greetd-devel/patches/24441
+         ;; greetd-next builds from head of #24441
+         ;; below substitute is provided as workaround for tagged version
+         (add-after 'unpack 'patch-terminal-switch
+           (lambda* (#:key inputs #:allow-other-keys)
+             (substitute* "greetd/src/server.rs"
+               (("switch: true,")
+                "switch: false,"))))
+         (delete 'package)
+         (add-after 'build 'build-man-pages
+           (lambda* (#:key inputs #:allow-other-keys)
+             (define (scdoc-cmd doc lvl)
+               (system (string-append "scdoc < "
+                                      doc "-" lvl ".scd > "
+                                      doc "." lvl)))
+             (with-directory-excursion "man"
+               (scdoc-cmd "greetd" "1")
+               (scdoc-cmd "greetd" "5")
+               (scdoc-cmd "greetd-ipc" "7")
+               (scdoc-cmd "agreety" "1"))))
+         (replace 'install
+           (lambda* (#:key inputs outputs #:allow-other-keys)
+             (let* ((out (assoc-ref outputs "out"))
+                    (bin (string-append out "/bin"))
+                    (sbin (string-append out "/sbin"))
+                    (share (string-append out "/share"))
+                    (man (string-append share "/man"))
+                    (man1 (string-append man "/man1"))
+                    (man5 (string-append man "/man5"))
+                    (man7 (string-append man "/man7"))
+                    (release "target/release")
+                    (greetd-bin (string-append release "/greetd"))
+                    (agreety-bin (string-append release "/agreety")))
+               (install-file greetd-bin sbin)
+               (install-file agreety-bin bin)
+               (with-directory-excursion "man"
+                 (install-file "greetd.1" man1)
+                 (install-file "greetd.5" man5)
+                 (install-file "greetd-ipc.7" man7)
+                 (install-file "agreety.1" man1))))))))
+    (native-inputs
+     `(("linux-pam" ,linux-pam)
+       ("scdoc" ,scdoc)))
+    (synopsis "minimal and flexible login manager daemon")
+    (description
+     "greetd is a minimal and flexible login manager daemon
+that makes no assumptions about what you want to launch.
+
+If you can run it from your shell in a TTY, greetd can start it.
+
+If it can be taught to speak a simple JSON-based IPC protocol,
+then it can be a greeter.")
+    (license license:gpl3+)))
+
+(define-public greetd-next
+  (package
+    (inherit greetd)
+    (name "greetd-next")
+    (version "0.7.0-87e9277")
+    (source (origin
+              (method git-fetch)
+              (uri (git-reference
+                    (url (package-home-page greetd))
+                    (commit "87e92776543c224676d64316f4519b509c21a0d5")))
+              (file-name (git-file-name name version))
+              (sha256
+               (base32 "13dblvhx5vbsx0yqyz2sq1ayffqwadbkn90p52wd5b66ij1z6v1a"))))
+    (arguments
+     (substitute-keyword-arguments (package-arguments greetd)
+       ((#:cargo-inputs inputs)
+        `(("rust-nix" ,rust-nix-0.19)
+           ("rust-pam-sys" ,rust-pam-sys-0.5.6)
+           ("rust-rpassword" ,rust-rpassword-5)
+           ("rust-users" ,rust-users-0.11)
+           ("rust-serde" ,rust-serde-1)
+           ("rust-serde-json" ,rust-serde-json-1)
+           ("rust-libc" ,rust-libc-0.2)
+           ("rust-tokio" ,rust-tokio-1)
+           ("rust-getopts" ,rust-getopts-0.2)
+           ("rust-thiserror" ,rust-thiserror-1)
+           ("rust-async-trait" ,rust-async-trait-0.1)
+           ("rust-enquote" ,rust-enquote-1)))
+       ((#:phases phases)
+        `(modify-phases ,phases
+           (delete 'patch-terminal-switch)))))))
+
 (define-public packagekit
   (package
     (name "packagekit")
-- 
2.32.0