Subject: [PATCH gnome-team v4 2/4] guix: Add udev-hwdb-bin profile hook.

From: Vivien Kraus <[email-masked]>
Date: Sat, 30 Sep 2023 21:32:59 +0200

The new eudev introduced an index for a hardware database. This index file
must be unique.

* guix/profiles.scm (udev-hwdb-bin): New profile hook to generate hwdb.bin.
(%default-profile-hooks): Register it here.
---
 guix/profiles.scm | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/guix/profiles.scm b/guix/profiles.scm
index c88672c25a..d308e7fb88 100644
--- a/guix/profiles.scm
+++ b/guix/profiles.scm
@@ -1905,6 +1905,34 @@ (define (texlive-font-maps manifest)
                             (hook . texlive-font-maps)))
         (return #f))))
 
+(define (udev-hwdb-bin manifest)
+  "Return a derivation that builds lib/udev/hwdb.bin."
+  (define eudev
+    (module-ref (resolve-interface '(gnu packages linux)) 'eudev))
+  (define build
+    (with-imported-modules
+        (source-module-closure '((guix build utils)))
+      #~(begin
+          (use-modules (guix build utils))
+          (let* ((inputs '#$(manifest-inputs manifest))
+                 (hwdb-directories
+                  (filter
+                   file-exists?
+                   (map (lambda (directory)
+                          (string-append directory "/lib/udev/hwdb.d"))
+                        inputs))))
+            (setenv "UDEV_HWDB_PATH"
+                    (string-join hwdb-directories ":")))
+          (invoke #$(file-append eudev "/bin/udevadm")
+                  "hwdb" "--update"
+                  "-o" (string-append #$output "/lib/udev/hwdb.bin")))))
+  (gexp->derivation "udev-hwdb-bin" build
+                    #:substitutable? #f
+                    #:local-build? #t
+                    #:properties
+                    `((type . profile-hook)
+                      (hook . udev-hwdb-bin))))
+
 (define %default-profile-hooks
   ;; This is the list of derivation-returning procedures that are called by
   ;; default when making a non-empty profile.
@@ -1919,6 +1947,7 @@ (define %default-profile-hooks
         gtk-icon-themes
         gtk-im-modules
         texlive-font-maps
+        udev-hwdb-bin
         xdg-desktop-database
         xdg-mime-database))
 
-- 
2.41.0