From: "Ludovic Courtès" <ludo@gnu.org>
To: 64471@debbugs.gnu.org
Cc: "Ludovic Courtès" <ludo@gnu.org>, "Bruno Victal" <mirai@makinata.eu>
Subject: [bug#64471] [PATCH v2 2/2] services: Add 'package-database' service.
Date: Thu, 20 Jul 2023 23:22:28 +0200 [thread overview]
Message-ID: <53bce8c28952116dc795d25f7c47e9360d0c9986.1689888002.git.ludo@gnu.org> (raw)
In-Reply-To: <87o7kanv9l.fsf_-_@gnu.org>
* gnu/services/admin.scm (%default-package-database-update-schedule):
New variable.
(<package-database-configuration>): New record type.
(package-database-mcron-jobs): New procedure.
(package-database-service-type): New variable.
* doc/guix.texi (File Search Services): Document it.
---
doc/guix.texi | 49 +++++++++++++++++++++++++++++++++++++-
gnu/services/admin.scm | 53 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 101 insertions(+), 1 deletion(-)
diff --git a/doc/guix.texi b/doc/guix.texi
index 1d5f7c6b47..833865f009 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -4481,7 +4481,9 @@ Invoking guix locate
exist or is too old, it falls back to the per-user database, by default
under @file{~/.cache/guix/locate}. On a multi-user system,
administrators may want to periodically update the system-wide database
-so that all users can benefit from it.
+so that all users can benefit from it, for instance by setting up
+@code{package-database-service-type} (@pxref{File Search Services,
+@code{package-database-service-type}}).
The general syntax is:
@@ -25000,6 +25002,51 @@ File Search Services
@end table
@end deftp
+The second service, @code{package-database-service-type}, builds the
+database used by @command{guix locate}, which lets you search for
+packages that contain a given file (@pxref{Invoking guix locate}). The
+service periodically updates a system-wide database, which will be
+readily available to anyone running @command{guix locate} on the system.
+To use this service with its default settings, add this snippet to your
+service list:
+
+@lisp
+(service package-database-service-type)
+@end lisp
+
+This will run @command{guix locate --update} once a week.
+
+@defvar package-database-service-type
+This is the service type for periodic @command{guix locate} updates
+(@pxref{Invoking guix locate}). Its value must be a
+@code{package-database-configuration} record, as shown below.
+@end defvar
+
+@deftp {Data Type} package-database-configuration
+Data type to configure periodic package database updates. It has the
+following fields:
+
+@table @asis
+@item @code{package} (default: @code{guix})
+The Guix package to use.
+
+@item @code{schedule} (default: @code{%default-package-database-update-schedule})
+String or G-exp denoting an mcron schedule for the periodic
+@command{guix locate --update} job (@pxref{Guile Syntax,,, mcron,
+GNU@tie{}mcron}).
+
+@item @code{method} (default: @code{'store})
+Indexing method for @command{guix locate}. The default value,
+@code{'store}, yields a more complete database but is relatively
+expensive in terms of CPU and input/output.
+
+@item @code{channels} (default: @code{#~%default-channels})
+G-exp denoting the channels to use when updating the database
+(@pxref{Channels}).
+@end table
+@end deftp
+
+
@node Database Services
@subsection Database Services
diff --git a/gnu/services/admin.scm b/gnu/services/admin.scm
index 636367a6f3..0c24cedd43 100644
--- a/gnu/services/admin.scm
+++ b/gnu/services/admin.scm
@@ -29,6 +29,8 @@ (define-module (gnu services admin)
#:use-module (gnu services configuration)
#:use-module (gnu services mcron)
#: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 gexp)
#:use-module (guix modules)
@@ -69,6 +71,14 @@ (define-module (gnu services admin)
%default-file-database-update-schedule
%default-file-database-excluded-directories
+ package-database-service-type
+ package-database-configuration
+ package-database-configuration?
+ package-database-configuration-package
+ package-database-configuration-schedule
+ package-database-configuration-method
+ package-database-configuration-channels
+
unattended-upgrade-service-type
unattended-upgrade-configuration
unattended-upgrade-configuration?
@@ -338,6 +348,49 @@ (define file-database-service-type
the @command{updatedb} command.")
(default-value (file-database-configuration))))
+(define %default-package-database-update-schedule
+ ;; Default mcron schedule for the periodic 'guix locate --update' job: once
+ ;; every Monday.
+ "10 23 * * 1")
+
+(define-configuration/no-serialization package-database-configuration
+ (package (file-like guix)
+ "The Guix package to use.")
+ (schedule (string-or-gexp
+ %default-package-database-update-schedule)
+ "String or G-exp denoting an mcron schedule for the periodic
+@command{guix locate --update} job (@pxref{Guile Syntax,,, mcron,
+GNU@tie{}mcron}).")
+ (method (symbol 'store)
+ "Indexing method for @command{guix locate}. The default value,
+@code{'store}, yields a more complete database but is relatively expensive in
+terms of CPU and input/output.")
+ (channels (gexp #~%default-channels)
+ "G-exp denoting the channels to use when updating the database
+(@pxref{Channels})."))
+
+(define (package-database-mcron-jobs configuration)
+ (match-record configuration <package-database-configuration>
+ (package schedule method channels)
+ (let ((channels (scheme-file "channels.scm" channels)))
+ (list #~(job #$schedule
+ ;; XXX: The whole thing's running as "root" just because it
+ ;; needs write access to /var/cache/guix/locate.
+ (string-append #$(file-append package "/bin/guix")
+ " time-machine -C " #$channels
+ " -- locate --update --method="
+ #$(symbol->string method)))))))
+
+(define package-database-service-type
+ (service-type
+ (name 'package-database)
+ (extensions (list (service-extension mcron-service-type
+ package-database-mcron-jobs)))
+ (description
+ "Periodically update the package database used by the @code{guix locate} command,
+which lets you search for packages that provide a given file.")
+ (default-value (package-database-configuration))))
+
\f
;;;
;;; Unattended upgrade.
--
2.41.0
next prev parent reply other threads:[~2023-07-20 21:24 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-05 9:59 [bug#64471] [PATCH 0/2] File database update services Ludovic Courtès
2023-07-05 10:16 ` [bug#64471] [PATCH 1/2] services: Add 'file-database' service Ludovic Courtès
2023-07-13 18:00 ` Bruno Victal
2023-07-17 20:22 ` [bug#64471] [PATCH 0/2] File database update services Ludovic Courtès
2023-07-20 21:22 ` [bug#64471] [PATCH v2 1/2] services: Add 'file-database' service Ludovic Courtès
2023-07-26 13:28 ` Bruno Victal
2023-07-20 21:22 ` Ludovic Courtès [this message]
2023-07-26 13:22 ` [bug#64471] [PATCH 0/2] File database update services Bruno Victal
2023-07-05 10:16 ` [bug#64471] [PATCH 2/2] services: Add 'package-database' service Ludovic Courtès
2023-08-07 14:39 ` bug#64471: [PATCH 0/2] File database update services Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=53bce8c28952116dc795d25f7c47e9360d0c9986.1689888002.git.ludo@gnu.org \
--to=ludo@gnu.org \
--cc=64471@debbugs.gnu.org \
--cc=mirai@makinata.eu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.