From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:470:142:3::10]:42352) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHrq2-0003Qg-46 for guix-patches@gnu.org; Fri, 27 Mar 2020 12:28:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jHrq0-0007Ae-FU for guix-patches@gnu.org; Fri, 27 Mar 2020 12:28:06 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:55550) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jHrq0-00078A-CH for guix-patches@gnu.org; Fri, 27 Mar 2020 12:28:04 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jHrpz-0000X4-9G for guix-patches@gnu.org; Fri, 27 Mar 2020 12:28:03 -0400 Subject: [bug#39258] [PATCH v3 1/3] guix: Generate package metadata cache. Resent-Message-ID: From: Arun Isaac Date: Fri, 27 Mar 2020 21:56:52 +0530 Message-Id: <20200327162654.18785-2-arunisaac@systemreboot.net> In-Reply-To: <20200327162654.18785-1-arunisaac@systemreboot.net> References: <20200327162654.18785-1-arunisaac@systemreboot.net> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: 39258@debbugs.gnu.org Cc: Arun Isaac , mail@ambrevar.xyz, ludo@gnu.org, zimon.toutoune@gmail.com * gnu/packages.scm (%package-metadata-cache-file): New variable. (generate-package-metadata-cache): New function. * guix/channels.scm (package-metadata-cache-file): New function. (%channel-profile-hooks): Add package-metadata-cache-file. --- gnu/packages.scm | 50 ++++++++++++++++++++++++++++++++++++++++++++++- guix/channels.scm | 34 +++++++++++++++++++++++++++++++- 2 files changed, 82 insertions(+), 2 deletions(-) diff --git a/gnu/packages.scm b/gnu/packages.scm index d22c992bb1..c0b527acf0 100644 --- a/gnu/packages.scm +++ b/gnu/packages.scm @@ -4,6 +4,7 @@ ;;; Copyright © 2014 Eric Bavier ;;; Copyright © 2016, 2017 Alex Kost ;;; Copyright © 2016 Mathieu Lirzin +;;; Copyright © 2020 Arun Isaac ;;; ;;; This file is part of GNU Guix. ;;; @@ -64,7 +65,8 @@ specification->location specifications->manifest - generate-package-cache)) + generate-package-cache + generate-package-metadata-cache)) ;;; Commentary: ;;; @@ -426,6 +428,52 @@ reducing the memory footprint." #:opts '(#:to-file? #t))))) cache-file) +(define %package-metadata-cache-file + ;; Location of the package metadata cache. + "/lib/guix/package-metadata.cache") + +(define (generate-package-metadata-cache directory) + "Generate under DIRECTORY a cache of the metadata of all available packages. + +The primary purpose of this cache is to speed up package metadata lookup +during package search so that we don't have to traverse and load all the +package modules." + (define cache-file + (string-append directory %package-metadata-cache-file)) + + (define (package ;;; Copyright © 2018 Ricardo Wurmus ;;; Copyright © 2019 Jan (janneke) Nieuwenhuizen +;;; Copyright © 2020 Arun Isaac ;;; ;;; This file is part of GNU Guix. ;;; @@ -581,9 +582,40 @@ be used as a profile hook." (hook . package-cache)) #:local-build? #t))) +(define (package-metadata-cache-file manifest) + "Build a package metadata cache file for the instance in MANIFEST. This is +meant to be used as a profile hook." + (mlet %store-monad ((profile (profile-derivation manifest + #:hooks '()))) + + (define build + #~(begin + (use-modules (gnu packages)) + + (if (defined? 'generate-package-metadata-cache) + (begin + ;; Delegate package cache generation to the inferior. + (format (current-error-port) + "Generating package metadata cache for '~a'...~%" + #$profile) + (generate-package-metadata-cache #$output)) + (mkdir #$output)))) + + (gexp->derivation-in-inferior "guix-package-metadata-cache" build + profile + + ;; If the Guix in PROFILE is too old and + ;; lacks 'guix repl', don't build the cache + ;; instead of failing. + #:silent-failure? #t + + #:properties '((type . profile-hook) + (hook . package-cache)) + #:local-build? #t))) + (define %channel-profile-hooks ;; The default channel profile hooks. - (cons package-cache-file %default-profile-hooks)) + (cons* package-cache-file package-metadata-cache-file %default-profile-hooks)) (define (channel-instances->derivation instances) "Return the derivation of the profile containing INSTANCES, a list of -- 2.25.1