From mboxrd@z Thu Jan 1 00:00:00 1970 From: iyzsong@member.fsf.org (=?utf-8?B?5a6L5paH5q2m?=) Subject: Re: [PATCH 1/2] profiles: Add xdg-desktop-database hook. Date: Thu, 04 Feb 2016 15:54:11 +0800 Message-ID: <874mdo7vx8.fsf@member.fsf.org> References: <1454241798-14243-1-git-send-email-iyzsong@gmail.com> <87twlrgsx3.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:49338) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aREkM-0007hN-KC for guix-devel@gnu.org; Thu, 04 Feb 2016 02:54:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aREkJ-0005Sg-CS for guix-devel@gnu.org; Thu, 04 Feb 2016 02:54:34 -0500 In-Reply-To: <87twlrgsx3.fsf@gnu.org> ("Ludovic =?utf-8?Q?Court=C3=A8s=22'?= =?utf-8?Q?s?= message of "Tue, 02 Feb 2016 14:09:44 +0100") List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org To: Ludovic =?utf-8?Q?Court=C3=A8s?= Cc: guix-devel@gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable ludo@gnu.org (Ludovic Court=C3=A8s) writes: > =E5=AE=8B=E6=96=87=E6=AD=A6 skribis: > >> * guix/profiles (xdg-desktop-database): New function. >> (%default-profile-hooks): Add it. > > Nice! > >> + (update-desktop-database (string-append >> + #+desktop-file-utils >> + "/bin/update-desktop-database"= ))) > > This is a small dependency, but it still depends on GLib; my > understanding is that building any profile would end up pulling in GLib > because of this hook. Yes. > > Should we have some heuristic as for the GTK+ and GHC hooks to avoid > pulling it in? > > For instance, we could check whether GLib is already an indirect > dependency of at least one of the packages. WDYT? Sure, but I think check on GLib is not sufficient and necessary, when the hook run, it will use latest desktop-file-utils which may use a different version of glib. Unless I use the desktop-file-utils package installed from profile, but not like the gtk-icon-themes hook, where gtk+ is the runtime dependency, desktop-file-utils is only used to validate the desktop file during build phase, I can't get it from manifest using the same (and IMO, heavy and ugly) method. So, I end up using a simple 'manifest-lookup', which require the desktop-file-utils and shared-mime-info to be installed explicitly. Updated patches: --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-profiles-Add-xdg-desktop-database-hook.patch >From 9fe7aa4f368def46ddab54bd1347d6cf2ef5832f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=8B=E6=96=87=E6=AD=A6?= Date: Thu, 4 Feb 2016 15:33:07 +0800 Subject: [PATCH 1/2] profiles: Add xdg-desktop-database hook. * guix/profiles.scm (xdg-desktop-database): New function. (%default-profile-hooks): Add it. --- guix/profiles.scm | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/guix/profiles.scm b/guix/profiles.scm index ce86ff8..a9375e6 100644 --- a/guix/profiles.scm +++ b/guix/profiles.scm @@ -684,13 +684,49 @@ creates the GTK+ 'icon-theme.cache' file for each theme." #:substitutable? #f) (return #f)))) +(define (xdg-desktop-database manifest) + "Return a derivation that builds the @file{mimeinfo.cache} database from +desktop files. It's used to query what applications can handle a given +MIME type." + (define desktop-file-utils + (module-ref (resolve-interface '(gnu packages gnome)) + 'desktop-file-utils)) + + (define build + #~(begin + (use-modules (srfi srfi-26) + (guix build utils) + (guix build union)) + (let* ((destdir (string-append #$output "/share/applications")) + (appdirs (filter file-exists? + (map (cut string-append <> + "/share/applications") + '#$(manifest-inputs manifest)))) + (update-desktop-database (string-append + #+desktop-file-utils + "/bin/update-desktop-database"))) + (mkdir-p (string-append #$output "/share")) + (union-build destdir appdirs + #:log-port (%make-void-port "w")) + (zero? (system* update-desktop-database destdir))))) + + ;; Don't run the hook when 'desktop-file-utils' is not installed. + (if (manifest-lookup manifest (manifest-pattern (name "desktop-file-utils"))) + (gexp->derivation "xdg-desktop-database" build + #:modules '((guix build utils) + (guix build union)) + #:local-build? #t + #:substitutable? #f) + (with-monad %store-monad (return #f)))) + (define %default-profile-hooks ;; This is the list of derivation-returning procedures that are called by ;; default when making a non-empty profile. (list info-dir-file ghc-package-cache-file ca-certificate-bundle - gtk-icon-themes)) + gtk-icon-themes + xdg-desktop-database)) (define* (profile-derivation manifest #:key -- 2.5.0 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0002-profiles-Add-xdg-mime-database-hook.patch >From 5e39f976de2ee6854b530a011e036b6ec2018810 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=8B=E6=96=87=E6=AD=A6?= Date: Thu, 4 Feb 2016 15:35:03 +0800 Subject: [PATCH 2/2] profiles: Add xdg-mime-database hook. * guix/profiles.scm (xdg-mime-database): New function. (%default-profile-hooks): Add it. --- guix/profiles.scm | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/guix/profiles.scm b/guix/profiles.scm index a9375e6..8f9d617 100644 --- a/guix/profiles.scm +++ b/guix/profiles.scm @@ -719,6 +719,42 @@ MIME type." #:substitutable? #f) (with-monad %store-monad (return #f)))) +(define (xdg-mime-database manifest) + "Return a derivation that builds the @file{mime.cache} database from manifest +entries. It's used to query the MIME type of a given file." + (define shared-mime-info + (module-ref (resolve-interface '(gnu packages gnome)) + 'shared-mime-info)) + + (define build + #~(begin + (use-modules (srfi srfi-26) + (guix build utils) + (guix build union)) + (let* ((datadir (string-append #$output "/share")) + (destdir (string-append datadir "/mime")) + (mimedirs (filter file-exists? + (map (cut string-append <> + "/share/mime") + '#$(manifest-inputs manifest)))) + (update-mime-database (string-append + #+shared-mime-info + "/bin/update-mime-database"))) + (mkdir-p datadir) + (union-build destdir mimedirs + #:log-port (%make-void-port "w")) + (setenv "XDG_DATA_HOME" datadir) + (zero? (system* update-mime-database destdir))))) + + ;; Don't run the hook when 'shared-mime-info' is not installed. + (if (manifest-lookup manifest (manifest-pattern (name "shared-mime-info"))) + (gexp->derivation "xdg-mime-database" build + #:modules '((guix build utils) + (guix build union)) + #:local-build? #t + #:substitutable? #f) + (with-monad %store-monad (return #f)))) + (define %default-profile-hooks ;; This is the list of derivation-returning procedures that are called by ;; default when making a non-empty profile. @@ -726,7 +762,8 @@ MIME type." ghc-package-cache-file ca-certificate-bundle gtk-icon-themes - xdg-desktop-database)) + xdg-desktop-database + xdg-mime-database)) (define* (profile-derivation manifest #:key -- 2.5.0 --=-=-=--