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

Message ID 2cbc00c8029bcaed82b5dfbc49053e28a966d3c9.1743115012.git.sergio.pastorperez@gmail.com
State New
Headers
Series [bug#77037,v2] services: `file-database-mcron-jobs' search updatedb in package field |

Commit Message

Sergio Pastor PĂ©rez March 27, 2025, 10:36 p.m. UTC
  `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' in 'sbin/updatedb'.

Fallback to 'sbin/' if 'updatedb' is not found in 'bin/'.

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

Change-Id: Ic741716044be3a8f51a157510f9f923bd66c41d7
---
 gnu/services/admin.scm | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)


base-commit: 71ae6f2a191e715c96b02e876f5e40e4932debd8
  

Patch

diff --git a/gnu/services/admin.scm b/gnu/services/admin.scm
index e4737940438..0eb38555951 100644
--- a/gnu/services/admin.scm
+++ b/gnu/services/admin.scm
@@ -448,8 +448,8 @@  (define-configuration/no-serialization file-database-configuration
                  (if target
                      findutils
                      (canonical-package findutils))))
-    "The GNU@tie{}Findutils package from which the @command{updatedb} command
-is taken.")
+    "The package from which the @command{updatedb} command is taken.
+Examples of such packages are GNU@tie{}Findutils and Plocate.")
   (schedule
    (string-or-gexp %default-file-database-update-schedule)
    "String or G-exp denoting an mcron schedule for the periodic
@@ -468,15 +468,20 @@  (define (file-database-shepherd-services configuration)
     (let ((updatedb (program-file
                      "updatedb"
                      #~(begin
+                         (define updatedb
+                           (let ((try (lambda (file)
+                                        (and (file-exists? file) file))))
+                             (or (try #$(file-append package "/bin/updatedb"))
+                                 (try #$(file-append package "/sbin/updatedb")))))
                          ;; 'updatedb' is a shell script that expects various
                          ;; commands in $PATH.
                          (setenv "PATH"
-                                 (string-append #$package "/bin:"
+                                 (string-append (dirname updatedb) ":"
                                                 #$(canonical-package coreutils)
                                                 "/bin:"
                                                 #$(canonical-package sed)
                                                 "/bin"))
-                         (execl #$(file-append package "/bin/updatedb")
+                         (execl updatedb
                                 "updatedb"
                                 #$(string-append "--prunepaths="
                                                  (string-join