unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] profiles: Add 'hicolor' and 'HighContrast' icon theme hooks.
@ 2015-05-09  4:55 宋文武
  2015-05-09  5:11 ` 宋文武
  0 siblings, 1 reply; 6+ messages in thread
From: 宋文武 @ 2015-05-09  4:55 UTC (permalink / raw)
  To: guix-devel

* guix/profiles.scm (gtk-icon-theme-hook): New function.
  (%default-profile-hooks): Add `(gtk-icon-theme-hook "hicolor")' and
  `(gtk-icon-theme-hook "HighContrast")'.
---
 guix/profiles.scm | 36 +++++++++++++++++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/guix/profiles.scm b/guix/profiles.scm
index 11d9bf0..9756685 100644
--- a/guix/profiles.scm
+++ b/guix/profiles.scm
@@ -573,12 +573,46 @@ MANIFEST.  Single-file bundles are required by programs such as Git and Lynx."
                     #:modules '((guix build utils))
                     #:local-build? #t))
 
+(define (gtk-icon-theme-hook name)
+  "Return a profile hook that unions all NAME icons from manifest entries and
+rebuilds the 'icon-theme.cache' file for the NAME icon theme."
+  (define gtk+
+    (module-ref (resolve-interface '(gnu packages gtk)) 'gtk+))
+
+  (lambda (manifest)
+    (define build
+      #~(begin
+          (use-modules (guix build utils)
+                       (guix build union))
+          (let* ((icon-dir (lambda (base)
+                             (string-append base "/share/icons/" #$name)))
+                 (destdir  (icon-dir #$output))
+                 (icons    (filter
+                            file-exists?
+                            (map icon-dir '#$(manifest-inputs manifest))))
+                 (update-icon-cache (string-append
+                                     #+gtk+ "/bin/gtk-update-icon-cache")))
+            ;; mkdir -p $out/share/icons
+            (mkdir-p destdir)
+            (rmdir destdir)
+            ;; Unions all the icons and update the 'icon-theme.cache'.
+            (union-build destdir icons)
+            (system* update-icon-cache "-t" destdir))))
+
+    (gexp->derivation (string-append (string-downcase name) "-icon-theme")
+                      build
+                      #:modules '((guix build utils)
+                                  (guix build union))
+                      #:local-build? #t)))
+
 (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))
+        ca-certificate-bundle
+        (gtk-icon-theme-hook "hicolor")
+        (gtk-icon-theme-hook "HighContrast")))
 
 (define* (profile-derivation manifest
                              #:key
-- 
2.2.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] profiles: Add 'hicolor' and 'HighContrast' icon theme hooks.
  2015-05-09  4:55 [PATCH] profiles: Add 'hicolor' and 'HighContrast' icon theme hooks 宋文武
@ 2015-05-09  5:11 ` 宋文武
  2015-05-09 14:10   ` Ludovic Courtès
  0 siblings, 1 reply; 6+ messages in thread
From: 宋文武 @ 2015-05-09  5:11 UTC (permalink / raw)
  To: guix-devel


This is WIP.
> * guix/profiles.scm (gtk-icon-theme-hook): New function.
>   (%default-profile-hooks): Add `(gtk-icon-theme-hook "hicolor")' and
>   `(gtk-icon-theme-hook "HighContrast")'.
> ---
>  guix/profiles.scm | 36 +++++++++++++++++++++++++++++++++++-
>  1 file changed, 35 insertions(+), 1 deletion(-)
>
> diff --git a/guix/profiles.scm b/guix/profiles.scm
> index 11d9bf0..9756685 100644
> --- a/guix/profiles.scm
> +++ b/guix/profiles.scm
> @@ -573,12 +573,46 @@ MANIFEST.  Single-file bundles are required by programs such as Git and Lynx."
>                      #:modules '((guix build utils))
>                      #:local-build? #t))
>  
> +(define (gtk-icon-theme-hook name)
> +  "Return a profile hook that unions all NAME icons from manifest entries and
> +rebuilds the 'icon-theme.cache' file for the NAME icon theme."
> +  (define gtk+
> +    (module-ref (resolve-interface '(gnu packages gtk)) 'gtk+))
> +
> +  (lambda (manifest)
> +    (define build
> +      #~(begin
> +          (use-modules (guix build utils)
> +                       (guix build union))
> +          (let* ((icon-dir (lambda (base)
> +                             (string-append base "/share/icons/" #$name)))
> +                 (destdir  (icon-dir #$output))
> +                 (icons    (filter
> +                            file-exists?
> +                            (map icon-dir '#$(manifest-inputs manifest))))
> +                 (update-icon-cache (string-append
> +                                     #+gtk+ "/bin/gtk-update-icon-cache")))
> +            ;; mkdir -p $out/share/icons
> +            (mkdir-p destdir)
> +            (rmdir destdir)
> +            ;; Unions all the icons and update the 'icon-theme.cache'.
> +            (union-build destdir icons)
> +            (system* update-icon-cache "-t" destdir))))
> +
> +    (gexp->derivation (string-append (string-downcase name) "-icon-theme")
> +                      build
> +                      #:modules '((guix build utils)
> +                                  (guix build union))
> +                      #:local-build? #t)))
When to exclude this derivation?

1. the best would be whether icon dir exists or not
   but is this posibble to implement? and how?

2. whether we have a gtk+ package in profile

And any better way?
> +
>  (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))
> +        ca-certificate-bundle
> +        (gtk-icon-theme-hook "hicolor")
> +        (gtk-icon-theme-hook "HighContrast")))
Does these 2 enough?  I think in practical, it does.
Or (better) as Federico Beffa said in:

  http://lists.gnu.org/archive/html/guix-devel/2015-01/msg00108.html

We should rebuilds all the icon themes?
If so, I think the code will be more complex...
>  
>  (define* (profile-derivation manifest
>                               #:key
> -- 
> 2.2.1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] profiles: Add 'hicolor' and 'HighContrast' icon theme hooks.
  2015-05-09  5:11 ` 宋文武
@ 2015-05-09 14:10   ` Ludovic Courtès
  2015-05-10  4:55     ` 宋文武
  0 siblings, 1 reply; 6+ messages in thread
From: Ludovic Courtès @ 2015-05-09 14:10 UTC (permalink / raw)
  To: 宋文武; +Cc: guix-devel

宋文武 <iyzsong@gmail.com> skribis:

> This is WIP.
>> * guix/profiles.scm (gtk-icon-theme-hook): New function.
>>   (%default-profile-hooks): Add `(gtk-icon-theme-hook "hicolor")' and
>>   `(gtk-icon-theme-hook "HighContrast")'.

Looks nice!

>> +(define (gtk-icon-theme-hook name)
>> +  "Return a profile hook that unions all NAME icons from manifest entries and
>> +rebuilds the 'icon-theme.cache' file for the NAME icon theme."
>> +  (define gtk+
>> +    (module-ref (resolve-interface '(gnu packages gtk)) 'gtk+))
>> +
>> +  (lambda (manifest)
>> +    (define build
>> +      #~(begin
>> +          (use-modules (guix build utils)
>> +                       (guix build union))
>> +          (let* ((icon-dir (lambda (base)
>> +                             (string-append base "/share/icons/" #$name)))
>> +                 (destdir  (icon-dir #$output))
>> +                 (icons    (filter
>> +                            file-exists?
>> +                            (map icon-dir '#$(manifest-inputs manifest))))
>> +                 (update-icon-cache (string-append
>> +                                     #+gtk+ "/bin/gtk-update-icon-cache")))
>> +            ;; mkdir -p $out/share/icons
>> +            (mkdir-p destdir)
>> +            (rmdir destdir)
>> +            ;; Unions all the icons and update the 'icon-theme.cache'.
>> +            (union-build destdir icons)
>> +            (system* update-icon-cache "-t" destdir))))
>> +
>> +    (gexp->derivation (string-append (string-downcase name) "-icon-theme")
>> +                      build
>> +                      #:modules '((guix build utils)
>> +                                  (guix build union))
>> +                      #:local-build? #t)))
> When to exclude this derivation?
>
> 1. the best would be whether icon dir exists or not
>    but is this posibble to implement? and how?

Currently this is not possible.  The builder could depend on all the
manifest entries and scan them for share/icons directory, but at this
point it’s already too later because the build has to depend on GTK+.

> 2. whether we have a gtk+ package in profile

That’s no usually the case.  For instance, I have Evince and GIMP in my
profile, but not GTK+.

What could be done is to check whether GTK+ appears and an direct or
indirect dependency of the packages being installed.

Currently manifest entries can contain either a package object or a
store path.  In the former case, one has to use package->bag and then
look for GTK+ in the bag’s transitive inputs.  In the latter, case, one
needs to call ‘references’ to check whether the store item, which is
already built, depends on GTK+.

When none of the manifest’s packages depends on GTK+, then the hook can
just return #f, like ghc-package-cache-file does.

Does that make sense?

>>  (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))
>> +        ca-certificate-bundle
>> +        (gtk-icon-theme-hook "hicolor")
>> +        (gtk-icon-theme-hook "HighContrast")))
> Does these 2 enough?  I think in practical, it does.
> Or (better) as Federico Beffa said in:
>
>   http://lists.gnu.org/archive/html/guix-devel/2015-01/msg00108.html
>
> We should rebuilds all the icon themes?
> If so, I think the code will be more complex...

Let’s have an incremental approach and start with the simple yet helpful
approach that you propose.  We can improve later.

Thoughts?

Thanks,
Ludo’.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] profiles: Add 'hicolor' and 'HighContrast' icon theme hooks.
  2015-05-09 14:10   ` Ludovic Courtès
@ 2015-05-10  4:55     ` 宋文武
  2015-05-10 19:57       ` Ludovic Courtès
  0 siblings, 1 reply; 6+ messages in thread
From: 宋文武 @ 2015-05-10  4:55 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel

Ludovic Courtès <ludo@gnu.org> writes:

> 宋文武 <iyzsong@gmail.com> skribis:
>
>> This is WIP.
>>> * guix/profiles.scm (gtk-icon-theme-hook): New function.
>>>   (%default-profile-hooks): Add `(gtk-icon-theme-hook "hicolor")' and
>>>   `(gtk-icon-theme-hook "HighContrast")'.
>
> Looks nice!
>
>>> +(define (gtk-icon-theme-hook name)
>>> +  "Return a profile hook that unions all NAME icons from manifest entries and
>>> +rebuilds the 'icon-theme.cache' file for the NAME icon theme."
>>> +  (define gtk+
>>> +    (module-ref (resolve-interface '(gnu packages gtk)) 'gtk+))
>>> +
>>> +  (lambda (manifest)
>>> +    (define build
>>> +      #~(begin
>>> +          (use-modules (guix build utils)
>>> +                       (guix build union))
>>> +          (let* ((icon-dir (lambda (base)
>>> +                             (string-append base "/share/icons/" #$name)))
>>> +                 (destdir  (icon-dir #$output))
>>> +                 (icons    (filter
>>> +                            file-exists?
>>> +                            (map icon-dir '#$(manifest-inputs manifest))))
>>> +                 (update-icon-cache (string-append
>>> +                                     #+gtk+ "/bin/gtk-update-icon-cache")))
>>> +            ;; mkdir -p $out/share/icons
>>> +            (mkdir-p destdir)
>>> +            (rmdir destdir)
>>> +            ;; Unions all the icons and update the 'icon-theme.cache'.
>>> +            (union-build destdir icons)
>>> +            (system* update-icon-cache "-t" destdir))))
>>> +
>>> +    (gexp->derivation (string-append (string-downcase name) "-icon-theme")
>>> +                      build
>>> +                      #:modules '((guix build utils)
>>> +                                  (guix build union))
>>> +                      #:local-build? #t)))
>> When to exclude this derivation?
>>
>> 1. the best would be whether icon dir exists or not
>>    but is this posibble to implement? and how?
>
> Currently this is not possible.  The builder could depend on all the
> manifest entries and scan them for share/icons directory, but at this
> point it’s already too later because the build has to depend on GTK+.
Does it mean we can't scan them (manifest-inputs) out of the builder,
because they may haven't be realized?
>
>> 2. whether we have a gtk+ package in profile
>
> That’s no usually the case.  For instance, I have Evince and GIMP in my
> profile, but not GTK+.
>
> What could be done is to check whether GTK+ appears and an direct or
> indirect dependency of the packages being installed.
>
> Currently manifest entries can contain either a package object or a
> store path.  In the former case, one has to use package->bag and then
> look for GTK+ in the bag’s transitive inputs.  In the latter, case, one
> needs to call ‘references’ to check whether the store item, which is
> already built, depends on GTK+.
>
> When none of the manifest’s packages depends on GTK+, then the hook can
> just return #f, like ghc-package-cache-file does.
>
> Does that make sense?
OK, I'll try this way.

And, which GTK+ we should use to do the icon update?
How about choose the one referenced by manifest entries
(either gtk+-2 or gtk+-3) instead of the latest gtk+-3 deployed?

So, we can avoid downloading the new GTK+.
(IMO, this is useful for GHC too)
>
>>>  (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))
>>> +        ca-certificate-bundle
>>> +        (gtk-icon-theme-hook "hicolor")
>>> +        (gtk-icon-theme-hook "HighContrast")))
>> Does these 2 enough?  I think in practical, it does.
>> Or (better) as Federico Beffa said in:
>>
>>   http://lists.gnu.org/archive/html/guix-devel/2015-01/msg00108.html
>>
>> We should rebuilds all the icon themes?
>> If so, I think the code will be more complex...
>
> Let’s have an incremental approach and start with the simple yet helpful
> approach that you propose.  We can improve later.
>
> Thoughts?
Sure, thanks your review!
>
> Thanks,
> Ludo’.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] profiles: Add 'hicolor' and 'HighContrast' icon theme hooks.
  2015-05-10  4:55     ` 宋文武
@ 2015-05-10 19:57       ` Ludovic Courtès
  2015-05-11  7:55         ` 宋文武
  0 siblings, 1 reply; 6+ messages in thread
From: Ludovic Courtès @ 2015-05-10 19:57 UTC (permalink / raw)
  To: 宋文武; +Cc: guix-devel

宋文武 <iyzsong@gmail.com> skribis:

> Ludovic Courtès <ludo@gnu.org> writes:
>
>> 宋文武 <iyzsong@gmail.com> skribis:

[...]

>>>> +    (gexp->derivation (string-append (string-downcase name) "-icon-theme")
>>>> +                      build
>>>> +                      #:modules '((guix build utils)
>>>> +                                  (guix build union))
>>>> +                      #:local-build? #t)))
>>> When to exclude this derivation?
>>>
>>> 1. the best would be whether icon dir exists or not
>>>    but is this posibble to implement? and how?
>>
>> Currently this is not possible.  The builder could depend on all the
>> manifest entries and scan them for share/icons directory, but at this
>> point it’s already too later because the build has to depend on GTK+.
> Does it mean we can't scan them (manifest-inputs) out of the builder,
> because they may haven't be realized?

Exactly.

>>> 2. whether we have a gtk+ package in profile
>>
>> That’s no usually the case.  For instance, I have Evince and GIMP in my
>> profile, but not GTK+.
>>
>> What could be done is to check whether GTK+ appears and an direct or
>> indirect dependency of the packages being installed.
>>
>> Currently manifest entries can contain either a package object or a
>> store path.  In the former case, one has to use package->bag and then
>> look for GTK+ in the bag’s transitive inputs.  In the latter, case, one
>> needs to call ‘references’ to check whether the store item, which is
>> already built, depends on GTK+.
>>
>> When none of the manifest’s packages depends on GTK+, then the hook can
>> just return #f, like ghc-package-cache-file does.
>>
>> Does that make sense?
> OK, I'll try this way.
>
> And, which GTK+ we should use to do the icon update?
> How about choose the one referenced by manifest entries
> (either gtk+-2 or gtk+-3) instead of the latest gtk+-3 deployed?

That makes sense.  I guess we’re in trouble if there are both GTK+2 and
GTK+3 packages in use, no?

Thanks,
Ludo’.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] profiles: Add 'hicolor' and 'HighContrast' icon theme hooks.
  2015-05-10 19:57       ` Ludovic Courtès
@ 2015-05-11  7:55         ` 宋文武
  0 siblings, 0 replies; 6+ messages in thread
From: 宋文武 @ 2015-05-11  7:55 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel

[-- Attachment #1: Type: text/plain, Size: 359 bytes --]

Ludovic Courtès <ludo@gnu.org> writes:

[...]

> That makes sense.  I guess we’re in trouble if there are both GTK+2 and
> GTK+3 packages in use, no?
Well, the 'icon-theme.cache' file compitable.
AFAIK, the code for `gtk-update-icon-cache' is same between GTK+2 and
GTK+3, and it only depends on glib and gdk-pixbuf.

And, here the new patch:


[-- Attachment #2: 0001-profiles-Add-hicolor-and-HighContrast-icon-theme-hoo.patch --]
[-- Type: text/x-patch, Size: 4297 bytes --]

From 94065c2b415b0b52a5617d381e1b7fac19ee9f45 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=AE=8B=E6=96=87=E6=AD=A6?= <iyzsong@gmail.com>
Date: Sat, 9 May 2015 12:45:39 +0800
Subject: [PATCH] profiles: Add 'hicolor' and 'HighContrast' icon theme hooks.

* guix/profiles.scm (gtk-icon-theme-hook): New function.
  (%default-profile-hooks): Add `(gtk-icon-theme-hook "hicolor")' and
  `(gtk-icon-theme-hook "HighContrast")'.
---
 guix/profiles.scm | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 68 insertions(+), 1 deletion(-)

diff --git a/guix/profiles.scm b/guix/profiles.scm
index 11d9bf0..08f05a6 100644
--- a/guix/profiles.scm
+++ b/guix/profiles.scm
@@ -3,6 +3,7 @@
 ;;; Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org>
 ;;; Copyright © 2014 Alex Kost <alezost@gmail.com>
 ;;; Copyright © 2015 Mark H Weaver <mhw@netris.org>
+;;; Copyright © 2015 Sou Bunnbu <iyzsong@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -573,12 +574,78 @@ MANIFEST.  Single-file bundles are required by programs such as Git and Lynx."
                     #:modules '((guix build utils))
                     #:local-build? #t))
 
+(define (gtk-icon-theme-hook name)
+  "Return a profile hook that unions all NAME icons from manifest entries and
+rebuilds the 'icon-theme.cache' file for the NAME icon theme."
+
+  (define (entry-lookup-gtk+ store entry)
+    "Return the GTK+ package or store path referenced by the manifest ENTRY, or
+#f if not referenced."
+    ;; Find GTK+ in a list of packages.
+    (define (by-packages packages)
+      (find (lambda (package)
+              (equal? "gtk+" (package-name package)))
+            packages))
+
+    ;; Find GTK+ in a list of store paths.
+    (define (by-paths paths)
+      (find (lambda (path)
+              (equal? "gtk+"
+                      (package-name->name+version
+                       (store-path-package-name path))))
+            paths))
+
+    (match (manifest-entry-item entry)
+      ((? package? package)
+       (by-packages (delete-duplicates
+                     (map cadr (package-transitive-inputs package)))))
+      ((? string? path)
+       (by-paths (references store path)))))
+
+  (define (manifest-lookup-gtk+ store manifest)
+    "Return the first GTK+ package or store path referenced by MANIFEST entries,
+or #f if not referenced by any entry."
+    (any (cut entry-lookup-gtk+ store <>) (manifest-entries manifest)))
+
+  (lambda (manifest)
+    (define gtk+
+      (with-store store
+        (manifest-lookup-gtk+ store manifest)))
+
+    (define build
+      #~(begin
+          (use-modules (guix build utils)
+                       (guix build union))
+          (let* ((icon-dir (lambda (base)
+                             (string-append base "/share/icons/" #$name)))
+                 (destdir  (icon-dir #$output))
+                 (icons    (filter
+                            file-exists?
+                            (map icon-dir '#$(manifest-inputs manifest))))
+                 (update-icon-cache (string-append
+                                     #+gtk+ "/bin/gtk-update-icon-cache")))
+            (mkdir-p (string-append #$output "/share/icons"))
+            ;; Unions all the icons and update the 'icon-theme.cache'.
+            (union-build destdir icons)
+            (system* update-icon-cache "-t" destdir))))
+
+    ;; Don't run the hook when there's nothing to do.
+    (if gtk+
+        (gexp->derivation (string-append (string-downcase name) "-icon-theme")
+                          build
+                          #:modules '((guix build utils)
+                                      (guix build union))
+                          #:local-build? #t)
+        #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))
+        ca-certificate-bundle
+        (gtk-icon-theme-hook "hicolor")
+        (gtk-icon-theme-hook "HighContrast")))
 
 (define* (profile-derivation manifest
                              #:key
-- 
2.2.1


[-- Attachment #3: Type: text/plain, Size: 41 bytes --]


Please give comments and feedback, TIA!

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-05-11  7:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-09  4:55 [PATCH] profiles: Add 'hicolor' and 'HighContrast' icon theme hooks 宋文武
2015-05-09  5:11 ` 宋文武
2015-05-09 14:10   ` Ludovic Courtès
2015-05-10  4:55     ` 宋文武
2015-05-10 19:57       ` Ludovic Courtès
2015-05-11  7:55         ` 宋文武

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).