Subject: [bug#77037] [PATCH] services: `file-database-mcron-jobs' search updatedb in package field

From: Sergio Pastor Pérez <[email-masked]>
Date: Sat, 15 Mar 2025 15:18:30 +0100

`file-database-service-type' appends 'bin/updatedb' path to the `package'
field provided by `file-database-configuration'. This prevents users from
using alternate packages which also provide 'updatedb' but in a different
location.

For example, the `plocate' package installs 'updatedb' it in 'sbin/updatedb'.

Use `find-files' to locate the binary within the user configured package.

* gnu/services/admin.scm (file-database-mcron-jobs): locate 'updatedb' binary.

Change-Id: Id35b26cbe41261a0ac3add53757d240b003aa26e
---
 gnu/services/admin.scm | 31 +++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/gnu/services/admin.scm b/gnu/services/admin.scm
index 2a11a4f4f10..19b0d64f2c2 100644
--- a/gnu/services/admin.scm
+++ b/gnu/services/admin.scm
@@ -37,13 +37,16 @@ (define-module (gnu services admin)
   #:use-module (gnu services shepherd)
   #:use-module (gnu system accounts)
   #:use-module ((gnu system shadow) #:select (account-service-type))
-  #:use-module ((guix store) #:select (%store-prefix))
+  #:use-module ((guix store) #:select (%store-prefix
+                                       open-connection))
   #:use-module (guix deprecation)
   #:use-module (guix gexp)
   #:use-module (guix modules)
   #:use-module (guix packages)
   #:use-module (guix records)
+  #:use-module (guix build utils)
   #:use-module (srfi srfi-1)
+  #:use-module (srfi srfi-26)
   #:use-module (ice-9 match)
   #:use-module (ice-9 vlist)
   #:export (log-rotation-configuration
@@ -473,17 +476,21 @@ (define (file-database-mcron-jobs configuration)
                      #~(begin
                          ;; 'updatedb' is a shell script that expects various
                          ;; commands in $PATH.
-                         (setenv "PATH"
-                                 (string-append #$package "/bin:"
-                                                #$(canonical-package coreutils)
-                                                "/bin:"
-                                                #$(canonical-package sed)
-                                                "/bin"))
-                         (execl #$(file-append package "/bin/updatedb")
-                                "updatedb"
-                                #$(string-append "--prunepaths="
-                                                 (string-join
-                                                  excluded-directories)))))))
+                         (let ((updatedb-bin #$(find (cut executable-file? <>)
+                                                     (find-files (package-output (open-connection)
+                                                                                 package)
+                                                                 "^updatedb$"))))
+                           (setenv "PATH"
+                                   (string-append (dirname updatedb-bin) ":"
+                                                  #$(canonical-package coreutils)
+                                                  "/bin:"
+                                                  #$(canonical-package sed)
+                                                  "/bin"))
+                           (execl updatedb-bin
+                                  "updatedb"
+                                  #$(string-append "--prunepaths="
+                                                   (string-join
+                                                    excluded-directories))))))))
       (list #~(job #$schedule #$updatedb)))))
 
 (define file-database-service-type

base-commit: 412f411d4f8780e6b60b448caae17f01c09be0eb
-- 
2.48.1