From patchwork Thu Jul 20 21:22:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 51882 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id BE01427BBE9; Thu, 20 Jul 2023 22:23:36 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 16EAA27BBE2 for ; Thu, 20 Jul 2023 22:23:34 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qMb74-0007rC-5y; Thu, 20 Jul 2023 17:23:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qMb71-0007qM-Hv for guix-patches@gnu.org; Thu, 20 Jul 2023 17:23:03 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qMb71-0002HN-9p for guix-patches@gnu.org; Thu, 20 Jul 2023 17:23:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qMb71-0001hz-5V for guix-patches@gnu.org; Thu, 20 Jul 2023 17:23:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#64471] [PATCH v2 1/2] services: Add 'file-database' service. Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 20 Jul 2023 21:23:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 64471 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 64471@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= , Bruno Victal Received: via spool by 64471-submit@debbugs.gnu.org id=B64471.16898881826538 (code B ref 64471); Thu, 20 Jul 2023 21:23:03 +0000 Received: (at 64471) by debbugs.gnu.org; 20 Jul 2023 21:23:02 +0000 Received: from localhost ([127.0.0.1]:60108 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qMb6z-0001hH-7E for submit@debbugs.gnu.org; Thu, 20 Jul 2023 17:23:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46436) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qMb6u-0001gu-Tt for 64471@debbugs.gnu.org; Thu, 20 Jul 2023 17:23:00 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qMb6o-0002FU-CD; Thu, 20 Jul 2023 17:22:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=JbiY8AXqsmk9Yt/5HGY5XTwxIDGzMJDKSPHRBnp44vA=; b=bEkC+KQuAhzmm/m54NOb de3J5WiDqu9G2v7aZJ0i5ick36kU9PIxvzEgL5Dcs0SboqAdRdvjlUBhMkxZaeBIYEMNa6XR+rTz8 IO+pALbjH37LK3vojNRPdTD2aNHgie/uj39st7lQ6N7q2rTSORrIBz8aWNlLO4seIGGYH6X5GDo6N M1r6tB+vDOdPCLzjx5d5BvxjPxjf0YepLbA4XPBdrJZc5Pz2WqeF8mnsFElXhWhZDo+/41uwR1z7m aJBM8qASRpmTAHP/oPtJdYVk270MecHJdzUWBtKuqsn97Vc0Z3SIhvLFoKQEQiCY1JP3J3kDXHiOU RR5X/oj8ki0tKw==; Received: from [78.199.208.147] (helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qMb6o-0006EZ-03; Thu, 20 Jul 2023 17:22:50 -0400 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Thu, 20 Jul 2023 23:22:27 +0200 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: <87o7kanv9l.fsf_-_@gnu.org> References: <87o7kanv9l.fsf_-_@gnu.org> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * gnu/services/admin.scm (%default-file-database-update-schedule) (%default-file-database-excluded-directories): New variables. (): New record type. (file-database-mcron-jobs): New procedure. (file-database-service-type): New variable. * doc/guix.texi (File Search Services): New node. --- doc/guix.texi | 62 +++++++++++++++++++++++++++++++ gnu/services/admin.scm | 83 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 145 insertions(+) Change since v1: use of 'define-configuration' instead of 'define-record-type*'. However, I am not using the generated documentation due to . (Overall I'm not fully satisfied with 'define-configuration'.) Thoughts? Ludo'. base-commit: 283969d0c527aa41e65bb4f5c2a7fa3baf86c49a diff --git a/doc/guix.texi b/doc/guix.texi index 1d8ebcd72f..1d5f7c6b47 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -388,6 +388,7 @@ Top * Printing Services:: Local and remote printer support. * Desktop Services:: D-Bus and desktop services. * Sound Services:: ALSA and Pulseaudio services. +* File Search Services:: Tools to search for files. * Database Services:: SQL databases, key-value stores, etc. * Mail Services:: IMAP, POP3, SMTP, and all that. * Messaging Services:: Messaging services. @@ -18428,6 +18429,7 @@ Services * Printing Services:: Local and remote printer support. * Desktop Services:: D-Bus and desktop services. * Sound Services:: ALSA and Pulseaudio services. +* File Search Services:: Tools to search for files. * Database Services:: SQL databases, key-value stores, etc. * Mail Services:: IMAP, POP3, SMTP, and all that. * Messaging Services:: Messaging services. @@ -24938,6 +24940,66 @@ Sound Services @end defvar +@node File Search Services +@subsection File Search Services + +@cindex file search +@cindex searching for a file +The services in this section populate @dfn{file databases} that let you +search for files on your machine. These services are provided by the +@code{(gnu services admin)} module. + +The first one, @code{file-database-service-type}, periodically runs the +venerable @command{updatedb} command (@pxref{Invoking updatedb,,, find, +GNU Findutils}). That command populates a database of file names that +you can then search with the @command{locate} command (@pxref{Invoing +locate,,, find, GNU Findutils}), as in this example: + +@example +locate important-notes.txt +@end example + +You can enable this service with its default settings by adding this +snippet to your operating system services: + +@lisp +(service file-database-service-type) +@end lisp + +This updates the database once a week, excluding files from +@file{/gnu/store}---these are more usefully handled by @command{guix +locate} (@pxref{Invoking guix locate}). You can of course provide a +custom configuration, as described below. + +@defvar file-database-service-type +This is the type of the file database service, which runs +@command{updatedb} periodically. Its associated value must be a +@code{file-database-configuration} record, as described below. +@end defvar + +@deftp {Data Type} file-database-configuration +Record type for the @code{file-database-service-type} configuration, +with the following fields: + +@table @asis +@item @code{package} (default: @code{findutils}) +The GNU@tie{}Findutils package from which the @command{updatedb} command +is taken. + +@item @code{schedule} (default: @code{%default-file-database-update-schedule}) +String or G-exp denoting an mcron schedule for the periodic +@command{updatedb} job (@pxref{Guile Syntax,,, mcron, GNU@tie{}mcron}). + +@item @code{excluded-directories} (default @code{%default-file-database-excluded-directories}) +List of directories to ignore when building the file database. By +default, this includes @file{/tmp} and @file{/gnu/store}, which should +instead be indexed by @command{guix locate} (@pxref{Invoking guix +locate}). This list is passed to the @option{--prunepaths} option of +@command{updatedb} (@pxref{Invoking updatedb,,, find, +GNU@tie{}Findutils}). +@end table +@end deftp + @node Database Services @subsection Database Services diff --git a/gnu/services/admin.scm b/gnu/services/admin.scm index 1c10cfb1f6..636367a6f3 100644 --- a/gnu/services/admin.scm +++ b/gnu/services/admin.scm @@ -21,16 +21,21 @@ (define-module (gnu services admin) #:use-module (gnu packages admin) + #:use-module ((gnu packages base) + #:select (canonical-package findutils)) #:use-module (gnu packages certs) #:use-module (gnu packages package-management) #:use-module (gnu services) + #:use-module (gnu services configuration) #:use-module (gnu services mcron) #:use-module (gnu services shepherd) + #:use-module ((guix store) #:select (%store-prefix)) #:use-module (guix gexp) #:use-module (guix modules) #:use-module (guix packages) #:use-module (guix records) #:use-module (srfi srfi-1) + #:use-module (ice-9 match) #:use-module (ice-9 vlist) #:export (%default-rotations %rotated-files @@ -55,6 +60,15 @@ (define-module (gnu services admin) log-cleanup-configuration-expiry log-cleanup-configuration-schedule + file-database-service-type + file-database-configuration + file-database-configuration? + file-database-configuration-package + file-database-configuration-schedule + file-database-configuration-excluded-directories + %default-file-database-update-schedule + %default-file-database-excluded-directories + unattended-upgrade-service-type unattended-upgrade-configuration unattended-upgrade-configuration? @@ -255,6 +269,75 @@ (define log-cleanup-service-type (description "Periodically delete old log files."))) + +;;; +;;; File databases. +;;; + +(define %default-file-database-update-schedule + ;; Default mcron schedule for the periodic 'updatedb' job: once every + ;; Sunday. + "10 23 * * 0") + +(define %default-file-database-excluded-directories + ;; Directories excluded from the 'locate' database. + (list (%store-prefix) + "/tmp" "/var/tmp" "/var/cache" ".*/\\.cache" + "/run/udev")) + +(define (string-or-gexp? obj) + (or (string? obj) (gexp? obj))) + +(define string-list? + (match-lambda + (((? string) ...) #t) + (_ #f))) + +(define-configuration/no-serialization file-database-configuration + (package + (file-like (let-system (system target) + ;; Unless we're cross-compiling, avoid pulling a second copy + ;; of findutils. + (if target + findutils + (canonical-package findutils)))) + "The GNU@tie{}Findutils package from which the @command{updatedb} command +is taken.") + (schedule + (string-or-gexp %default-file-database-update-schedule) + "String or G-exp denoting an mcron schedule for the periodic +@command{updatedb} job (@pxref{Guile Syntax,,, mcron, GNU@tie{}mcron}).") + (excluded-directories + (string-list %default-file-database-excluded-directories) + "List of directories to ignore when building the file database. By +default, this includes @file{/tmp} and @file{/gnu/store}, which should instead +be indexed by @command{guix locate} (@pxref{Invoking guix locate}). This list +is passed to the @option{--prunepaths} option of +@command{updatedb} (@pxref{Invoking updatedb,,, find, GNU@tie{}Findutils}).")) + +(define (file-database-mcron-jobs configuration) + (match-record configuration + (package schedule excluded-directories) + (let ((updatedb (program-file + "updatedb" + #~(execl #$(file-append package "/bin/updatedb") + "updatedb" + #$(string-append "--prunepaths=" + (string-join + excluded-directories)))))) + (list #~(job #$schedule #$updatedb))))) + +(define file-database-service-type + (service-type + (name 'file-database) + (extensions (list (service-extension mcron-service-type + file-database-mcron-jobs))) + (description + "Periodically update the file database used by the @command{locate} command, +which lets you search for files by name. The database is created by running +the @command{updatedb} command.") + (default-value (file-database-configuration)))) + ;;; ;;; Unattended upgrade.