diff mbox

[2/3] profiles: Add fonts-dir-file hook.

Message ID 20160701092730.2265-3-alezost@gmail.com
State New
Headers show

Commit Message

Alex Kost July 1, 2016, 9:27 a.m. UTC
* guix/profiles.scm (fonts-dir-file): New procedure.
(%default-profile-hooks): Add it.
---
 guix/profiles.scm | 43 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)

Comments

Ludovic Courtès July 2, 2016, 2:34 p.m. UTC | #1
Alex Kost <alezost@gmail.com> skribis:

> * guix/profiles.scm (fonts-dir-file): New procedure.
> (%default-profile-hooks): Add it.

[...]

> +(define (fonts-dir-file manifest)
> +  "Return a derivation that builds the @file{fonts.dir} and @file{fonts.scale}
> +files for the truetype fonts of the @var{manifest} entries."
> +  (define mkfontscale
> +    (module-ref (resolve-interface '(gnu packages xorg)) 'mkfontscale))
> +
> +  (define mkfontdir
> +    (module-ref (resolve-interface '(gnu packages xorg)) 'mkfontdir))
> +
> +  (define build
> +    #~(begin
> +        (use-modules (srfi srfi-26)
> +                     (guix build utils)
> +                     (guix build union))
> +        (let ((ttf-dirs (filter file-exists?
> +                                (map (cut string-append <>
> +                                          "/share/fonts/truetype")
> +                                     '#$(manifest-inputs manifest)))))
> +          (mkdir #$output)
> +          (if (null? ttf-dirs)
> +              (exit #t)
> +              (let* ((fonts-dir   (string-append #$output "/share/fonts"))
> +                     (ttf-dir     (string-append fonts-dir "/truetype"))
> +                     (mkfontscale (string-append #+mkfontscale
> +                                                 "/bin/mkfontscale"))
> +                     (mkfontdir   (string-append #+mkfontdir
> +                                                 "/bin/mkfontdir")))
> +                (mkdir-p fonts-dir)
> +                (union-build ttf-dir ttf-dirs
> +                             #:log-port (%make-void-port "w"))
> +                (with-directory-excursion ttf-dir
> +                  (exit (and (zero? (system* mkfontscale))
> +                             (zero? (system* mkfontdir))))))))))
> +
> +  (gexp->derivation "fonts-dir-file" build
> +                    #:modules '((guix build utils)
> +                                (guix build union))
> +                    #:local-build? #t
> +                    #:substitutable? #f))

A potential problem with this hook is that it pulls mkfontscale and
mkfontdir regardless of whether they are needed; I can’t really think of
a way to avoid it though.

Also, how does it relate to this:

  commit bf9655f57d2442d56661594b80f6d0031ca0ae73
  Author: Eric Bavier <bavier@member.fsf.org>
  Date:   Mon Oct 19 06:44:23 2015 -0500

      font-alias: Install dummy fonts.dir files.

      * gnu/packages/xorg.scm (font-alias)[arguments]: New 'install-fonts-dir'
        phase.

?

Thanks,
Ludo’.
Alex Kost July 2, 2016, 7:19 p.m. UTC | #2
Ludovic Courtès (2016-07-02 17:34 +0300) wrote:

> Alex Kost <alezost@gmail.com> skribis:
>
>> * guix/profiles.scm (fonts-dir-file): New procedure.
>> (%default-profile-hooks): Add it.
>
> [...]
>
> A potential problem with this hook is that it pulls mkfontscale and
> mkfontdir regardless of whether they are needed; I can’t really think of
> a way to avoid it though.

Yes, I also don't like it.  We have the same problem with
'info-file-dir' hook: it always pulls texinfo and gzip, but not all
profiles include info manuals.

> Also, how does it relate to this:
>
>   commit bf9655f57d2442d56661594b80f6d0031ca0ae73
>   Author: Eric Bavier <bavier@member.fsf.org>
>   Date:   Mon Oct 19 06:44:23 2015 -0500
>
>       font-alias: Install dummy fonts.dir files.
>
>       * gnu/packages/xorg.scm (font-alias)[arguments]: New 'install-fonts-dir'
>         phase.
>
> ?

It doesn't relate at all.  This hook generates "fonts.dir" only for
"share/fonts/truetype" directory.  Directories with X fonts are not
touched, because all sub-directories of "share/fonts/X11" already
contain "fonts.dir" files (font-adobe75dpi, font-misc-misc and other X
font packages install "fonts.dir").

'font-alias' package does not contain fonts.dir file because it doesn't
make sense: this package does not provide any font.  It just installs
"fonts.alias" files inside "share/fonts/X11/{75dpi,100dpi,cyrillic,misc}"
directories.  Eric made this commit for one particular case: to make it
possible to use font aliases in the default X server configuration
('xorg-configuration-file' in (gnu services xorg) module).

Just to mention, I think we shouldn't modify 'font-alias' package as it
leads to a bug <http://bugs.gnu.org/22100>, and should do some other
workaround.  I have 2 ideas (not sure if they make any sense):

1) To add a special package (font-alias-with-fonts.dir) that will be used
in 'xorg-configuration-file'.

2) To do 'union-build' on packages with X fonts and aliases and to use it
in the X config.  With this, we can revert that Eric's commit, and
everything should just work (I mean the X config will work and the bug
will be fixed).
Ludovic Courtès July 5, 2016, 2:31 p.m. UTC | #3
Alex Kost <alezost@gmail.com> skribis:

> Ludovic Courtès (2016-07-02 17:34 +0300) wrote:
>
>> Alex Kost <alezost@gmail.com> skribis:
>>
>>> * guix/profiles.scm (fonts-dir-file): New procedure.
>>> (%default-profile-hooks): Add it.
>>
>> [...]
>>
>> A potential problem with this hook is that it pulls mkfontscale and
>> mkfontdir regardless of whether they are needed; I can’t really think of
>> a way to avoid it though.
>
> Yes, I also don't like it.  We have the same problem with
> 'info-file-dir' hook: it always pulls texinfo and gzip, but not all
> profiles include info manuals.

Yes, but I thought it was OK to make these mandatory dependencies.

The closure of mkfontscale + mkfontdir is small; it’s slightly annoying
for someone building from source because you have to build a few X11
libraries, but it’s not that much either (‘guix graph’ shows just a few
boxes.)

So this hook is probably fine, after all.

What do people think?

>> Also, how does it relate to this:
>>
>>   commit bf9655f57d2442d56661594b80f6d0031ca0ae73
>>   Author: Eric Bavier <bavier@member.fsf.org>
>>   Date:   Mon Oct 19 06:44:23 2015 -0500
>>
>>       font-alias: Install dummy fonts.dir files.
>>
>>       * gnu/packages/xorg.scm (font-alias)[arguments]: New 'install-fonts-dir'
>>         phase.
>>
>> ?
>
> It doesn't relate at all.

Good.  :-)

> This hook generates "fonts.dir" only for "share/fonts/truetype"
> directory.  Directories with X fonts are not touched, because all
> sub-directories of "share/fonts/X11" already contain "fonts.dir" files
> (font-adobe75dpi, font-misc-misc and other X font packages install
> "fonts.dir").
>
> 'font-alias' package does not contain fonts.dir file because it doesn't
> make sense: this package does not provide any font.  It just installs
> "fonts.alias" files inside "share/fonts/X11/{75dpi,100dpi,cyrillic,misc}"
> directories.  Eric made this commit for one particular case: to make it
> possible to use font aliases in the default X server configuration
> ('xorg-configuration-file' in (gnu services xorg) module).
>
> Just to mention, I think we shouldn't modify 'font-alias' package as it
> leads to a bug <http://bugs.gnu.org/22100>, and should do some other
> workaround.  I have 2 ideas (not sure if they make any sense):
>
> 1) To add a special package (font-alias-with-fonts.dir) that will be used
> in 'xorg-configuration-file'.
>
> 2) To do 'union-build' on packages with X fonts and aliases and to use it
> in the X config.  With this, we can revert that Eric's commit, and
> everything should just work (I mean the X config will work and the bug
> will be fixed).

Could you discuss it with 22100@debbugs.gnu.org and Cc: Eric?  I’m not
sure I’m competent enough to comment, so I’d rather let you and Eric
figure out what needs to be done.  :-)

Thanks!

Ludo’.
Alex Kost July 6, 2016, 7:41 p.m. UTC | #4
Ludovic Courtès (2016-07-05 17:31 +0300) wrote:

> Alex Kost <alezost@gmail.com> skribis:
[...]
>> This hook generates "fonts.dir" only for "share/fonts/truetype"
>> directory.  Directories with X fonts are not touched, because all
>> sub-directories of "share/fonts/X11" already contain "fonts.dir" files
>> (font-adobe75dpi, font-misc-misc and other X font packages install
>> "fonts.dir").
>>
>> 'font-alias' package does not contain fonts.dir file because it doesn't
>> make sense: this package does not provide any font.  It just installs
>> "fonts.alias" files inside "share/fonts/X11/{75dpi,100dpi,cyrillic,misc}"
>> directories.  Eric made this commit for one particular case: to make it
>> possible to use font aliases in the default X server configuration
>> ('xorg-configuration-file' in (gnu services xorg) module).
>>
>> Just to mention, I think we shouldn't modify 'font-alias' package as it
>> leads to a bug <http://bugs.gnu.org/22100>, and should do some other
>> workaround.  I have 2 ideas (not sure if they make any sense):
>>
>> 1) To add a special package (font-alias-with-fonts.dir) that will be used
>> in 'xorg-configuration-file'.
>>
>> 2) To do 'union-build' on packages with X fonts and aliases and to use it
>> in the X config.  With this, we can revert that Eric's commit, and
>> everything should just work (I mean the X config will work and the bug
>> will be fixed).
>
> Could you discuss it with 22100@debbugs.gnu.org and Cc: Eric?  I’m not
> sure I’m competent enough to comment, so I’d rather let you and Eric
> figure out what needs to be done.  :-)

OK, I think I should try to make a patch at first to show what I mean.
Alex Kost July 22, 2016, 6:59 a.m. UTC | #5
Ludovic Courtès (2016-07-05 17:31 +0300) wrote:

> Alex Kost <alezost@gmail.com> skribis:
>
>> Ludovic Courtès (2016-07-02 17:34 +0300) wrote:
>>
>>> Alex Kost <alezost@gmail.com> skribis:
>>>
>>>> * guix/profiles.scm (fonts-dir-file): New procedure.
>>>> (%default-profile-hooks): Add it.
>>>
>>> [...]
>>>
>>> A potential problem with this hook is that it pulls mkfontscale and
>>> mkfontdir regardless of whether they are needed; I can’t really think of
>>> a way to avoid it though.
>>
>> Yes, I also don't like it.  We have the same problem with
>> 'info-file-dir' hook: it always pulls texinfo and gzip, but not all
>> profiles include info manuals.
>
> Yes, but I thought it was OK to make these mandatory dependencies.
>
> The closure of mkfontscale + mkfontdir is small; it’s slightly annoying
> for someone building from source because you have to build a few X11
> libraries, but it’s not that much either (‘guix graph’ shows just a few
> boxes.)
>
> So this hook is probably fine, after all.
>
> What do people think?

Since there were no objections in 2 weeks, I think it's OK to commit
this 'fonts-dir-file' hook, right?
Ludovic Courtès July 24, 2016, 5:09 p.m. UTC | #6
Alex Kost <alezost@gmail.com> skribis:

> Ludovic Courtès (2016-07-05 17:31 +0300) wrote:
>
>> Alex Kost <alezost@gmail.com> skribis:
>>
>>> Ludovic Courtès (2016-07-02 17:34 +0300) wrote:
>>>
>>>> Alex Kost <alezost@gmail.com> skribis:
>>>>
>>>>> * guix/profiles.scm (fonts-dir-file): New procedure.
>>>>> (%default-profile-hooks): Add it.
>>>>
>>>> [...]
>>>>
>>>> A potential problem with this hook is that it pulls mkfontscale and
>>>> mkfontdir regardless of whether they are needed; I can’t really think of
>>>> a way to avoid it though.
>>>
>>> Yes, I also don't like it.  We have the same problem with
>>> 'info-file-dir' hook: it always pulls texinfo and gzip, but not all
>>> profiles include info manuals.
>>
>> Yes, but I thought it was OK to make these mandatory dependencies.
>>
>> The closure of mkfontscale + mkfontdir is small; it’s slightly annoying
>> for someone building from source because you have to build a few X11
>> libraries, but it’s not that much either (‘guix graph’ shows just a few
>> boxes.)
>>
>> So this hook is probably fine, after all.
>>
>> What do people think?
>
> Since there were no objections in 2 weeks, I think it's OK to commit
> this 'fonts-dir-file' hook, right?

I think so!

Ludo’.
Alex Kost July 25, 2016, 2:26 p.m. UTC | #7
Ludovic Courtès (2016-07-24 20:09 +0300) wrote:

> Alex Kost <alezost@gmail.com> skribis:
>
>> Ludovic Courtès (2016-07-05 17:31 +0300) wrote:
>>
>>> Alex Kost <alezost@gmail.com> skribis:
>>>
>>>> Ludovic Courtès (2016-07-02 17:34 +0300) wrote:
>>>>
>>>>> Alex Kost <alezost@gmail.com> skribis:
>>>>>
>>>>>> * guix/profiles.scm (fonts-dir-file): New procedure.
>>>>>> (%default-profile-hooks): Add it.
>>>>>
>>>>> [...]
>>>>>
>>>>> A potential problem with this hook is that it pulls mkfontscale and
>>>>> mkfontdir regardless of whether they are needed; I can’t really think of
>>>>> a way to avoid it though.
>>>>
>>>> Yes, I also don't like it.  We have the same problem with
>>>> 'info-file-dir' hook: it always pulls texinfo and gzip, but not all
>>>> profiles include info manuals.
>>>
>>> Yes, but I thought it was OK to make these mandatory dependencies.
>>>
>>> The closure of mkfontscale + mkfontdir is small; it’s slightly annoying
>>> for someone building from source because you have to build a few X11
>>> libraries, but it’s not that much either (‘guix graph’ shows just a few
>>> boxes.)
>>>
>>> So this hook is probably fine, after all.
>>>
>>> What do people think?
>>
>> Since there were no objections in 2 weeks, I think it's OK to commit
>> this 'fonts-dir-file' hook, right?
>
> I think so!

Committed, thanks!
diff mbox

Patch

diff --git a/guix/profiles.scm b/guix/profiles.scm
index 90c4332..945da62 100644
--- a/guix/profiles.scm
+++ b/guix/profiles.scm
@@ -1,7 +1,7 @@ 
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2013, 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
 ;;; Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org>
-;;; Copyright © 2014 Alex Kost <alezost@gmail.com>
+;;; Copyright © 2014, 2016 Alex Kost <alezost@gmail.com>
 ;;; Copyright © 2015 Mark H Weaver <mhw@netris.org>
 ;;; Copyright © 2015 Sou Bunnbu <iyzsong@gmail.com>
 ;;;
@@ -756,10 +756,51 @@  entries.  It's used to query the MIME type of a given file."
                           #:substitutable? #f)
         (return #f))))
 
+(define (fonts-dir-file manifest)
+  "Return a derivation that builds the @file{fonts.dir} and @file{fonts.scale}
+files for the truetype fonts of the @var{manifest} entries."
+  (define mkfontscale
+    (module-ref (resolve-interface '(gnu packages xorg)) 'mkfontscale))
+
+  (define mkfontdir
+    (module-ref (resolve-interface '(gnu packages xorg)) 'mkfontdir))
+
+  (define build
+    #~(begin
+        (use-modules (srfi srfi-26)
+                     (guix build utils)
+                     (guix build union))
+        (let ((ttf-dirs (filter file-exists?
+                                (map (cut string-append <>
+                                          "/share/fonts/truetype")
+                                     '#$(manifest-inputs manifest)))))
+          (mkdir #$output)
+          (if (null? ttf-dirs)
+              (exit #t)
+              (let* ((fonts-dir   (string-append #$output "/share/fonts"))
+                     (ttf-dir     (string-append fonts-dir "/truetype"))
+                     (mkfontscale (string-append #+mkfontscale
+                                                 "/bin/mkfontscale"))
+                     (mkfontdir   (string-append #+mkfontdir
+                                                 "/bin/mkfontdir")))
+                (mkdir-p fonts-dir)
+                (union-build ttf-dir ttf-dirs
+                             #:log-port (%make-void-port "w"))
+                (with-directory-excursion ttf-dir
+                  (exit (and (zero? (system* mkfontscale))
+                             (zero? (system* mkfontdir))))))))))
+
+  (gexp->derivation "fonts-dir-file" build
+                    #:modules '((guix build utils)
+                                (guix build union))
+                    #:local-build? #t
+                    #:substitutable? #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
+        fonts-dir-file
         ghc-package-cache-file
         ca-certificate-bundle
         gtk-icon-themes