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

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

Commit Message

Sergio Pastor Pérez March 15, 2025, 2:18 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' 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(-)


base-commit: 412f411d4f8780e6b60b448caae17f01c09be0eb
  

Comments

Ludovic Courtès March 15, 2025, 9:35 p.m. UTC | #1
Hello,

Sergio Pastor Pérez <sergio.pastorperez@gmail.com> skribis:

> `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'.

I didn’t know about ‘plocate’.  :-)

Could yoiu add a line in the doc explicitly mentioning that ‘plocate’ is
supported, in addition to Findutils?

> +                         (let ((updatedb-bin #$(find (cut executable-file? <>)
> +                                                     (find-files (package-output (open-connection)
> +                                                                                 package)
> +                                                                 "^updatedb$"))))

This wouldn’t work for instance if ‘package’ hasn’t been built yet, and
also, it opens an extra connection to the daemon, which should be
avoided.

Instead, I’d write something like:

  (define updatedb
    (let ((try (lambda (file)
                 (and (file-exists? file) file))))
      (or (try #$(file-append package "/bin/updatedb"))
          (try #$(file-append package "/sbin/updatedb")))))

Could you send an updated patch?

Thanks,
Ludo’.
  

Patch

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