From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id sO7hBmRDpWTPhAAASxT56A (envelope-from ) for ; Wed, 05 Jul 2023 12:18:12 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id SO7WBmRDpWSAcAEA9RJhRA (envelope-from ) for ; Wed, 05 Jul 2023 12:18:12 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 6CBC0255DC for ; Wed, 5 Jul 2023 12:18:11 +0200 (CEST) Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gnu.org header.s=fencepost-gnu-org header.b=VprdfViC; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Seal: i=1; s=key1; d=yhetil.org; t=1688552291; a=rsa-sha256; cv=none; b=Tw/AZWWHgd3tgxZt5M6RpodzAFGvHykv97Y8NJS5D9TmnL2v4xIWxlcff4C3ruAc3XCmCr vPl7lLQl0L09p1Dn3E4r5Xs/rmOFrT/kaFv2nrQt9zFvpta1pHBBp6ZfOFdiToKs1tx7km R+RUdOoA9apmXhdmCQXhGdf3yWnab4Z8yVtyIHE2hXt+4z14o0ubjt7Z1dFPShjmYY6cE5 jlW8uETTNQ4uI7DFkbUBpJuHw5MI30/wFygIwHyioYtDVcEbYAKFQzZyQyRYYfa73kJcgd r/KlZivMXw2YX98fhxAaFwq4T3BAbfcO6TEJr/7lPSYFtiEmupY9+jmnCtJooQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gnu.org header.s=fencepost-gnu-org header.b=VprdfViC; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1688552291; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=xpZOswsoW4fVugZasxtvynnMY5hQ0/CHIrkskyifgRw=; b=DrTpNLMwBxJlsdqRgkD43HWaDcWQFiCplLVep5gJopfM57Hal1ktW6oL3uR+Xvl4UJ1TIT TwOP9YfLj3xDKzb3jPsSwHIzRWamrBlVomn7M0cwifMAeKFvR89lSNoj1hik1LOq2EZZNt XBixJLi5YMpmrKHV/tzR0zM7/KKtEcZhmIp7qR7RJOT4Mk33PJIzwzqyciH4DLX/DoIqrh by9a94g7rro2wrTy5mZmnNvCP0hpDrt68QhraaXDe5ibYcCVSvu2LYJs299SiI5HnRCu7d Ak1cklgFr5yu4FCBqxIPQcNfT83SYdMSaz1ioPE0CGGDjVCFnxO256vaBBSEfA== Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qGzaH-0006ZB-8w; Wed, 05 Jul 2023 06:18:05 -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 1qGzaE-0006Yd-P8 for guix-patches@gnu.org; Wed, 05 Jul 2023 06:18:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qGzaE-0007pH-5V for guix-patches@gnu.org; Wed, 05 Jul 2023 06:18:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qGzaE-0006jM-12 for guix-patches@gnu.org; Wed, 05 Jul 2023 06:18:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#64471] [PATCH 2/2] services: Add 'package-database' service. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 05 Jul 2023 10:18:01 +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?= Received: via spool by 64471-submit@debbugs.gnu.org id=B64471.168855222525800 (code B ref 64471); Wed, 05 Jul 2023 10:18:01 +0000 Received: (at 64471) by debbugs.gnu.org; 5 Jul 2023 10:17:05 +0000 Received: from localhost ([127.0.0.1]:37139 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qGzZI-0006i3-GA for submit@debbugs.gnu.org; Wed, 05 Jul 2023 06:17:04 -0400 Received: from eggs.gnu.org ([209.51.188.92]:35310) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qGzZF-0006hA-6m for 64471@debbugs.gnu.org; Wed, 05 Jul 2023 06:17:04 -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 1qGzZ9-0007a8-PZ; Wed, 05 Jul 2023 06:16:55 -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=pOifxbrOgadiizlL4obmUKdtp1sQM3jW5yBflukXerA=; b=VprdfViCAiDM2rD4sZSE rLA70zlfIpZpMt5h16NIxEj+A04kffBOvb3n69Axvomg17vtm9ImHEEwxpD1blyWxoQgCw2/raC0n zKBMd21RL8urN1soU2+5iEyjoOD7U7sylM1o6eP3goO8jNu6QwM4gAgfFABor5CSNhQ8bscoz1jPr 9lxANODUK4JNTtilvARe/s67Lqs+WHmAy7/Axp+fro1XxTiSEG+PDNPs08MgK0PkJtIXDQhsGvTXc JboF0TjIJbi+1DNT3wAgCZaFznYmVLyni5gGNeBznkD+vTVWiDXYDcGlCRwT1O7sXr9Gf5bMGjiEA gQKJ9rXI/qIeqQ==; Received: from vpn-0-27.aquilenet.fr ([185.233.101.27] 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 1qGzZ7-0008Gw-Cp; Wed, 05 Jul 2023 06:16:55 -0400 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Wed, 5 Jul 2023 12:16:36 +0200 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Scanner: scn1.migadu.com X-Migadu-Spam-Score: -2.66 X-Migadu-Queue-Id: 6CBC0255DC X-Spam-Score: -2.66 X-TUID: volqTBcS9PGZ * gnu/services/admin.scm (%default-package-database-update-schedule): New variable. (): 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 | 49 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 1 deletion(-) diff --git a/doc/guix.texi b/doc/guix.texi index 21ff15ccbc..05cfdb9bc7 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: @@ -24986,6 +24988,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 57fdfc35c0..f16880029f 100644 --- a/gnu/services/admin.scm +++ b/gnu/services/admin.scm @@ -28,6 +28,8 @@ (define-module (gnu services admin) #:use-module (gnu services) #: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) @@ -67,6 +69,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? @@ -322,6 +332,45 @@ (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-record-type* + package-database-configuration make-package-database-configuration + package-database-configuration? + (package package-database-configuration-package + (default guix)) + (schedule package-database-configuration-schedule + (default %default-package-database-update-schedule)) + (method package-database-configuration-method + (default 'store)) + (channels package-database-configuration-channels + (default #~%default-channels))) + +(define (package-database-mcron-jobs configuration) + (match-record 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)))) + ;;; ;;; Unattended upgrade. -- 2.40.1