Subject: [bug#74671] [PATCH] gnu: freedesktop: Add `libsystemd`

From: Ryan Sundberg <[email-masked]>
Date: Tue, 3 Dec 2024 07:44:05 -0800

Provide libsystemd.so and associated header files for linking against
systemd. While users may not wish to use systemd as an init system, some
programs may require this for their build process.

* gnu/packages/freedesktop.scm (libsystemd): New variable

Change-Id: I3f3b16e021ccca801693a0b8e1ba2d9cb040a952
Signed-off-by: Ryan Sundberg <[email-masked]>
---
 gnu/packages/freedesktop.scm | 43 ++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/gnu/packages/freedesktop.scm b/gnu/packages/freedesktop.scm
index af35625c18..e2d2b60376 100644
--- a/gnu/packages/freedesktop.scm
+++ b/gnu/packages/freedesktop.scm
@@ -761,6 +761,49 @@ (define-public libinput-minimal
                "-Ddebug-gui=false"    ;requires gtk+@3
                ,flags))))))
 
+(define-public libsystemd
+  (package
+    (name "libsystemd")
+    (version "256.9")
+    (source
+      (origin
+        (method git-fetch)
+        (uri
+          (git-reference
+            (url "https://github.com/systemd/systemd.git")
+            (commit (string-append "v" version))))
+        (sha256
+          (base32
+            "0x7n2jwmwrprl0aqcaxw184r5x03047264ccrv24aivmf5fzk7iy"))))
+    (build-system meson-build-system)
+    (arguments
+      `(;; Don't test all of systemd
+        #:tests? #f
+        #:configure-flags (list (string-append "-Drootprefix=" %output))
+        #:phases (modify-phases %standard-phases
+                   (replace 'build
+                     (lambda* (#:key parallel-build? #:allow-other-keys)
+                       (invoke "ninja"
+                               "-j" (if parallel-build? (number->string (parallel-job-count)) "1")
+                               "libsystemd.so.0.39.0"
+                               "src/libsystemd/libsystemd.pc")))
+                   (replace 'install
+                     (lambda* (#:key outputs #:allow-other-keys)
+                       (invoke "meson" "install" "--no-rebuild" "--tags" "libsystemd")
+                       (let ((out (assoc-ref outputs "out")))
+                         (delete-file "../source/src/systemd/meson.build")
+                         (mkdir-p (string-append out "/lib/pkgconfig"))
+                         (install-file "./src/libsystemd/libsystemd.pc" (string-append out "/lib/pkgconfig"))
+                         (copy-recursively "../source/src/systemd" (string-append out "/include/systemd"))))))))
+    (inputs
+      (list gperf libcap libxcrypt (list util-linux "lib")))
+    (native-inputs
+      (list cmake pkg-config python python-jinja2))
+    (home-page "https://systemd.io/")
+    (synopsis "Functions for implementing services and interacting with systemd")
+    (description "The libsystemd library provides functions that allow interacting with various interfaces provided by the systemd(1) service manager, as well as various other functions and constants useful for implementing services in general.")
+    (license license:lgpl2.1+)))
+
 (define-public libxdg-basedir
   (package
     (name "libxdg-basedir")

base-commit: 32d1dfb5545bb01c9d8d7a2465f13f2f379dd96e
-- 
2.41.0