unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] profiles: Generate database file for manpages
@ 2017-03-30  8:35 Maxim Cournoyer
  2017-03-30 15:53 ` Ludovic Courtès
  0 siblings, 1 reply; 13+ messages in thread
From: Maxim Cournoyer @ 2017-03-30  8:35 UTC (permalink / raw)
  To: guix-devel


[-- Attachment #1.1: Type: text/plain, Size: 945 bytes --]

Hello Guix!

I've managed to finalize a profile hooks which takes care of generating
the manpages database file. This file is used by apropos or man -k to
provide results.

Thanks to Ludovic for providing me with a patch I could start from, this
greetly speeded things up!

I've tested and found it to be working for the regular user profile. To
try it, apply the patch and use a guix command that causes a new profile
generation.

For example: guix package -r git -i git
Then: "apropos git" should return plenty of results.

It requires extra processing time to do the work since the complete
database (on my system, there are thousands or manpages being indexed)
is recreated everytime a new profile is generated.

For now it doesn't work for guix environments (yet), but this should be
easy to fix (it seems the $GUIX_ENVIRONMENT/share/man should be merged
with $HOME/.guix-profile/share/man, but I need to look at it more
carefully).

Maxim

[-- Attachment #1.2: 0001-profiles-Generate-database-file-for-manpages.patch --]
[-- Type: text/x-patch, Size: 4887 bytes --]

From dbbe6894919164cd34572a28bfbbf6d4d681e35b Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Date: Tue, 28 Mar 2017 09:25:21 -0700
Subject: [PATCH] profiles: Generate database file for manpages
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The mandb database file (index.db) is used by the "apropos" (whatis) or
"man -k" commands. This change introduces a profile hook to generate
such database file.

Co-authored by Ludovic Courtès

* guix/profiles.scm (manual-database): New procedure.
(%default-profile-hooks): Add it.
---
 guix/profiles.scm | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 76 insertions(+)

diff --git a/guix/profiles.scm b/guix/profiles.scm
index 795c9447fe..eb746c125a 100644
--- a/guix/profiles.scm
+++ b/guix/profiles.scm
@@ -7,6 +7,7 @@
 ;;; Copyright © 2016 Ricardo Wurmus <rekado@elephly.net>
 ;;; Copyright © 2016 Chris Marusich <cmmarusich@gmail.com>
 ;;; Copyright © 2017 Huang Ying <huang.ying.caritas@gmail.com>
+;;; Copyright © 2017 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -946,10 +947,85 @@ files for the fonts of the @var{manifest} entries."
                     #:local-build? #t
                     #:substitutable? #f))
 
+(define (manual-database manifest)
+  (define man-db                        ;lazy reference
+    (module-ref (resolve-interface '(gnu packages man)) 'man-db))
+
+  (define build
+    #~(begin
+        (use-modules (guix build utils)
+                     (srfi srfi-1))
+
+        (define entries
+          (filter-map (lambda (directory)
+                        (let ((man (string-append directory "/share/man")))
+                          (and (directory-exists? man)
+                               man)))
+                      '#$(manifest-inputs manifest)))
+
+        (define manpages-collection-dir
+          (string-append (getenv "PWD") "/manpages-collection"))
+
+        (define man-directory
+          (string-append #$output "/share/man"))
+
+        (define man-db-config-orig
+          (string-append #+man-db "/etc/man_db.conf"))
+
+        (define man-db-config
+          (string-append (getenv "PWD") "/man_db.conf"))
+
+        (define (get-manpage-tail-path manpage-path)
+          (let ((index (string-contains manpage-path "/share/man/")))
+            (substring manpage-path (+ index (string-length "/share/man/")))))
+
+        (define (populate-manpages-collection-dir entries)
+          (let ((manpages (append-map (lambda (manpath)
+                                        (find-files manpath))
+                                      entries)))
+            (for-each (lambda (manpage)
+                        (let* ((dest-path (string-append
+                                           manpages-collection-dir "/"
+                                           (get-manpage-tail-path manpage)))
+                               (dest-dir (dirname dest-path)))
+                          (unless (file-exists? dest-dir)
+                            (mkdir-p dest-dir))
+                          (catch 'system-error
+                            (lambda ()
+                              (symlink manpage dest-path))
+                            (lambda args
+                              ;; Different packages may contain the same
+                              ;; manpage. Simply ignore the symlink error.
+                              #t))))
+                      manpages)))
+
+        (mkdir-p manpages-collection-dir)
+        (populate-manpages-collection-dir entries)
+
+        ;; Create a mandb config file which contains a custom made
+        ;; manpath. The associated catpath is the location where the database
+        ;; gets generated.
+        (copy-file man-db-config-orig man-db-config)
+        (substitute* man-db-config
+          (("MANDB_MAP	/usr/man		/var/cache/man/fsstnd")
+           (string-append "MANDB_MAP " manpages-collection-dir " "
+                          man-directory)))
+
+        (mkdir-p man-directory)
+        (setenv "MANPATH" (string-join entries ":"))
+        (zero? (system* (string-append #+man-db "/bin/mandb")
+                        "--quiet" "--create"
+                        "-C" man-db-config))))
+
+  (gexp->derivation "manual-database" build
+                    #:modules '((guix build utils))
+                    #: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
+        manual-database
         fonts-dir-file
         ghc-package-cache-file
         ca-certificate-bundle
-- 
2.12.0


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

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

* Re: [PATCH] profiles: Generate database file for manpages
  2017-03-30  8:35 [PATCH] profiles: Generate database file for manpages Maxim Cournoyer
@ 2017-03-30 15:53 ` Ludovic Courtès
  2017-03-31  7:12   ` Maxim Cournoyer
  0 siblings, 1 reply; 13+ messages in thread
From: Ludovic Courtès @ 2017-03-30 15:53 UTC (permalink / raw)
  To: Maxim Cournoyer; +Cc: guix-devel

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

Hi Maxim,

Maxim Cournoyer <maxim.cournoyer@gmail.com> skribis:

> I've managed to finalize a profile hooks which takes care of generating
> the manpages database file. This file is used by apropos or man -k to
> provide results.

Awesome!  I’ve been willing to have this for some time.

> I've tested and found it to be working for the regular user profile. To
> try it, apply the patch and use a guix command that causes a new profile
> generation.
>
> For example: guix package -r git -i git
> Then: "apropos git" should return plenty of results.

For some reason I have to use “man -K” (capital):

--8<---------------cut here---------------start------------->8---
~$ apropos guile
guile: nothing appropriate.
~$ man -k guile
guile: nothing appropriate.
~$ man -K guile
--Man-- next: skribilo(1) [ view (return) | skip (Ctrl-D) | quit (Ctrl-C) ]
--Man-- next: guile(1) [ view (return) | skip (Ctrl-D) | quit (Ctrl-C) ]
--Man-- next: guix-pull(1) [ view (return) | skip (Ctrl-D) | quit (Ctrl-C) ]
--Man-- next: guix-package(1) [ view (return) | skip (Ctrl-D) | quit (Ctrl-C) ]
--Man-- next: gv(3guile) [ view (return) | skip (Ctrl-D) | quit (Ctrl-C) ]
~$ env | grep MANPATH
MANPATH=/home/ludo/.guix-profile/share/man:/run/current-system/profile/share/man:/home/ludo/.guix-profile/share/man:/run/current-system/profile/share/man:/home/ludo/.opam/system/man
--8<---------------cut here---------------end--------------->8---

Any idea why?

> It requires extra processing time to do the work since the complete
> database (on my system, there are thousands or manpages being indexed)
> is recreated everytime a new profile is generated.

On my laptop (with an SSD), I found it to be reasonable:

--8<---------------cut here---------------start------------->8---
$ time guix build /gnu/store/rkri628apz2a2i2jvav11ylv2736fvv3-manual-database.drv --check
@ build-started /gnu/store/rkri628apz2a2i2jvav11ylv2736fvv3-manual-database.drv - x86_64-linux /var/log/guix/drvs/rk//ri628apz2a2i2jvav11ylv2736fvv3-manual-database.drv.bz2
/gnu/store/g7qxdk1cn7fwkamkaisi4428k6ijg0w2-manual-database

real	0m2.647s
user	0m0.116s
sys	0m0.004s
$ guix package -I |wc -l
229
--8<---------------cut here---------------end--------------->8---

> For now it doesn't work for guix environments (yet), but this should be
> easy to fix (it seems the $GUIX_ENVIRONMENT/share/man should be merged
> with $HOME/.guix-profile/share/man, but I need to look at it more
> carefully).

It seems to work but only with capital -K:

--8<---------------cut here---------------start------------->8---
$ ./pre-inst-env guix environment --ad-hoc guile man-db --pure -- man -K guile
man: can't execute cat: No such file or directory
man: command exited with status 255: sed -e '/^[[:space:]]*$/{ N; /^[[:space:]]*\n[[:space:]]*$/D; }' | (cd <fd 3> && LESS=-ix8RmPm Manual page guile(1) ?ltline %lt?L/%L.:byte %bB?s/%s..?e (END):?pB %pB\%.. (press h for help or q to quit)$PM Manual page guile(1) ?ltline %lt?L/%L.:byte %bB?s/%s..?e (END):?pB %pB\%.. (press h for help or q to quit)$ MAN_PN=guile(1) cat)
--8<---------------cut here---------------end--------------->8---

(And we should hard-code the file name of ‘cat’ in ‘man’…)

> From dbbe6894919164cd34572a28bfbbf6d4d681e35b Mon Sep 17 00:00:00 2001
> From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
> Date: Tue, 28 Mar 2017 09:25:21 -0700
> Subject: [PATCH] profiles: Generate database file for manpages
> MIME-Version: 1.0
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: 8bit
>
> The mandb database file (index.db) is used by the "apropos" (whatis) or
> "man -k" commands. This change introduces a profile hook to generate
> such database file.
>
> Co-authored by Ludovic Courtès
>
> * guix/profiles.scm (manual-database): New procedure.
> (%default-profile-hooks): Add it.

I made some simplifications to the patch.  WDYT?

Thanks,
Ludo’.


[-- Attachment #2: Type: text/x-patch, Size: 3541 bytes --]

diff --git a/guix/profiles.scm b/guix/profiles.scm
index 795c9447f..f565f358b 100644
--- a/guix/profiles.scm
+++ b/guix/profiles.scm
@@ -7,6 +7,7 @@
 ;;; Copyright © 2016 Ricardo Wurmus <rekado@elephly.net>
 ;;; Copyright © 2016 Chris Marusich <cmmarusich@gmail.com>
 ;;; Copyright © 2017 Huang Ying <huang.ying.caritas@gmail.com>
+;;; Copyright © 2017 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -946,10 +947,73 @@ files for the fonts of the @var{manifest} entries."
                     #:local-build? #t
                     #:substitutable? #f))
 
+(define (manual-database manifest)
+  (define man-db                                  ;lazy reference
+    (module-ref (resolve-interface '(gnu packages man)) 'man-db))
+
+  (define build
+    #~(begin
+        (use-modules (guix build utils)
+                     (srfi srfi-1))
+
+        (define entries
+          (filter-map (lambda (directory)
+                        (let ((man (string-append directory "/share/man")))
+                          (and (directory-exists? man)
+                               man)))
+                      '#$(manifest-inputs manifest)))
+
+        (define manpages-collection-dir
+          (string-append (getenv "PWD") "/manpages-collection"))
+
+        (define man-directory
+          (string-append #$output "/share/man"))
+
+        (define (populate-manpages-collection-dir entries)
+          (let ((manpages (append-map find-files entries)))
+            (for-each (lambda (manpage)
+                        (let* ((dest-file (string-append
+                                           manpages-collection-dir "/"
+                                           (strip-store-file-name manpage))))
+                          (mkdir-p (dirname dest-file))
+                          (catch 'system-error
+                            (lambda ()
+                              (symlink manpage dest-file))
+                            (lambda args
+                              ;; Different packages may contain the same
+                              ;; manpage.  Simply ignore the symlink error.
+                              #t))))
+                      manpages)))
+
+        (mkdir-p manpages-collection-dir)
+        (populate-manpages-collection-dir entries)
+
+        ;; Create a mandb config file which contains a custom made
+        ;; manpath. The associated catpath is the location where the database
+        ;; gets generated.
+        (copy-file #+(file-append man-db "/etc/man_db.conf")
+                   "man_db.conf")
+
+        (substitute* "man_db.conf"
+          (("MANDB_MAP\\>.*$")
+           (string-append "MANDB_MAP " manpages-collection-dir " "
+                          man-directory "\n")))
+
+        (mkdir-p man-directory)
+        (setenv "MANPATH" (string-join entries ":"))
+        (zero? (system* #+(file-append man-db "/bin/mandb")
+                        "--quiet" "--create"
+                        "-C" "man_db.conf"))))
+
+  (gexp->derivation "manual-database" build
+                    #:modules '((guix build utils))
+                    #: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
+        manual-database
         fonts-dir-file
         ghc-package-cache-file
         ca-certificate-bundle

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

* Re: [PATCH] profiles: Generate database file for manpages
  2017-03-30 15:53 ` Ludovic Courtès
@ 2017-03-31  7:12   ` Maxim Cournoyer
  2017-03-31 22:44     ` Ludovic Courtès
  0 siblings, 1 reply; 13+ messages in thread
From: Maxim Cournoyer @ 2017-03-31  7:12 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel


[-- Attachment #1.1: Type: text/plain, Size: 9327 bytes --]

Hi Ludovic,

ludo@gnu.org (Ludovic Courtès) writes:

> Hi Maxim,
>
> Maxim Cournoyer <maxim.cournoyer@gmail.com> skribis:
>
>> I've managed to finalize a profile hooks which takes care of generating
>> the manpages database file. This file is used by apropos or man -k to
>> provide results.
>
> Awesome!  I’ve been willing to have this for some time.
>

Thanks for providing feedback on this so quickly!

>> I've tested and found it to be working for the regular user profile. To
>> try it, apply the patch and use a guix command that causes a new profile
>> generation.
>>
>> For example: guix package -r git -i git
>> Then: "apropos git" should return plenty of results.
>
> For some reason I have to use “man -K” (capital):
>
> ~$ apropos guile
> guile: nothing appropriate.
> ~$ man -k guile
> guile: nothing appropriate.
> ~$ man -K guile
> --Man-- next: skribilo(1) [ view (return) | skip (Ctrl-D) | quit (Ctrl-C) ]
> --Man-- next: guile(1) [ view (return) | skip (Ctrl-D) | quit (Ctrl-C) ]
> --Man-- next: guix-pull(1) [ view (return) | skip (Ctrl-D) | quit (Ctrl-C) ]
> --Man-- next: guix-package(1) [ view (return) | skip (Ctrl-D) | quit (Ctrl-C) ]
> --Man-- next: gv(3guile) [ view (return) | skip (Ctrl-D) | quit (Ctrl-C) ]
> ~$ env | grep MANPATH
> MANPATH=/home/ludo/.guix-profile/share/man:/run/current-system/profile/share/man:/home/ludo/.guix-profile/share/man:/run/current-system/profile/share/man:/home/ludo/.opam/system/man
>
>
> Any idea why?
>

Unfortunately some of the simplifications you made appear to break it
:). I've tried your reworked patch and got the same result as you (no
result found except when using man -K). When I use the original patch it
works as I originally described.

>> It requires extra processing time to do the work since the complete
>> database (on my system, there are thousands or manpages being indexed)
>> is recreated everytime a new profile is generated.
>
> On my laptop (with an SSD), I found it to be reasonable:
>
> $ time guix build /gnu/store/rkri628apz2a2i2jvav11ylv2736fvv3-manual-database.drv --check
> @ build-started /gnu/store/rkri628apz2a2i2jvav11ylv2736fvv3-manual-database.drv - x86_64-linux /var/log/guix/drvs/rk//ri628apz2a2i2jvav11ylv2736fvv3-manual-database.drv.bz2
> /gnu/store/g7qxdk1cn7fwkamkaisi4428k6ijg0w2-manual-database
>
> real	0m2.647s
> user	0m0.116s
> sys	0m0.004s
> $ guix package -I |wc -l
> 229
>
>
>> For now it doesn't work for guix environments (yet), but this should be
>> easy to fix (it seems the $GUIX_ENVIRONMENT/share/man should be merged
>> with $HOME/.guix-profile/share/man, but I need to look at it more
>> carefully).
>
> It seems to work but only with capital -K:
>
> $ ./pre-inst-env guix environment --ad-hoc guile man-db --pure -- man -K guile
> man: can't execute cat: No such file or directory
> man: command exited with status 255: sed -e '/^[[:space:]]*$/{ N; /^[[:space:]]*\n[[:space:]]*$/D; }' | (cd <fd 3> && LESS=-ix8RmPm Manual page guile(1) ?ltline %lt?L/%L.:byte %bB?s/%s..?e (END):?pB %pB\%.. (press h for help or q to quit)$PM Manual page guile(1) ?ltline %lt?L/%L.:byte %bB?s/%s..?e (END):?pB %pB\%.. (press h for help or q to quit)$ MAN_PN=guile(1) cat)
>
> (And we should hard-code the file name of ‘cat’ in ‘man’…)
>
>>
>> The mandb database file (index.db) is used by the "apropos" (whatis) or
>> "man -k" commands. This change introduces a profile hook to generate
>> such database file.
>>
>> Co-authored by Ludovic Courtès
>>
>> * guix/profiles.scm (manual-database): New procedure.
>> (%default-profile-hooks): Add it.
>
> I made some simplifications to the patch.  WDYT?
>

Looks good, except for the 2 problematic changes in the reworked patch
identified below.

> Thanks,
> Ludo’.
>
> diff --git a/guix/profiles.scm b/guix/profiles.scm
> index 795c9447f..f565f358b 100644
> --- a/guix/profiles.scm
> +++ b/guix/profiles.scm
> @@ -7,6 +7,7 @@
>  ;;; Copyright © 2016 Ricardo Wurmus <rekado@elephly.net>
>  ;;; Copyright © 2016 Chris Marusich <cmmarusich@gmail.com>
>  ;;; Copyright © 2017 Huang Ying <huang.ying.caritas@gmail.com>
> +;;; Copyright © 2017 Maxim Cournoyer <maxim.cournoyer@gmail.com>
>  ;;;
>  ;;; This file is part of GNU Guix.
>  ;;;
> @@ -946,10 +947,73 @@ files for the fonts of the @var{manifest} entries."
>                      #:local-build? #t
>                      #:substitutable? #f))
>  
> +(define (manual-database manifest)
> +  (define man-db                                  ;lazy reference
> +    (module-ref (resolve-interface '(gnu packages man)) 'man-db))
> +
> +  (define build
> +    #~(begin
> +        (use-modules (guix build utils)
> +                     (srfi srfi-1))
> +
> +        (define entries
> +          (filter-map (lambda (directory)
> +                        (let ((man (string-append directory "/share/man")))
> +                          (and (directory-exists? man)
> +                               man)))
> +                      '#$(manifest-inputs manifest)))
> +
> +        (define manpages-collection-dir
> +          (string-append (getenv "PWD") "/manpages-collection"))
> +
> +        (define man-directory
> +          (string-append #$output "/share/man"))
> +
> +        (define (populate-manpages-collection-dir entries)
> +          (let ((manpages (append-map find-files entries)))
> +            (for-each (lambda (manpage)
> +                        (let* ((dest-file (string-append
> +                                           manpages-collection-dir "/"
> +                                           (strip-store-file-name manpage))))

Unfortunately we cannot simply use strip-store-file-name, since what
mandb expects to find in our manpages-collection-dir is a collection of
subdirectories such as man1, man3, man7, etc. such as would be found
under "/usr/share/man" on a traditional distro. This change instead
makes it look like:

bazaar-2.7.0/          gdbm-1.12/              libxau-1.0.8/  ...

I guess this is what broke it.

> +                          (mkdir-p (dirname dest-file))
> +                          (catch 'system-error
> +                            (lambda ()
> +                              (symlink manpage dest-file))
> +                            (lambda args
> +                              ;; Different packages may contain the same
> +                              ;; manpage.  Simply ignore the symlink error.
> +                              #t))))
> +                      manpages)))
> +
> +        (mkdir-p manpages-collection-dir)
> +        (populate-manpages-collection-dir entries)
> +
> +        ;; Create a mandb config file which contains a custom made
> +        ;; manpath. The associated catpath is the location where the database
> +        ;; gets generated.
> +        (copy-file #+(file-append man-db "/etc/man_db.conf")
> +                   "man_db.conf")
> +
> +        (substitute* "man_db.conf"
> +          (("MANDB_MAP\\>.*$")
> +           (string-append "MANDB_MAP " manpages-collection-dir " "
> +                          man-directory "\n")))

This change here will replace every MANDB_MAP entries with duplicated
information:

MANDB_MAP /tmp/guix-build-manual-database.drv-0/manpages-collection /gnu/store/6w3gq10pgi8qmyq9i989glxs8md4miyk-manual-database/share/man
MANDB_MAP /tmp/guix-build-manual-database.drv-0/manpages-collection /gnu/store/6w3gq10pgi8qmyq9i989glxs8md4miyk-manual-database/share/man
MANDB_MAP /tmp/guix-build-manual-database.drv-0/manpages-collection /gnu/store/6w3gq10pgi8qmyq9i989glxs8md4miyk-manual-database/share/man
MANDB_MAP /tmp/guix-build-manual-database.drv-0/manpages-collection /gnu/store/6w3gq10pgi8qmyq9i989glxs8md4miyk-manual-database/share/man
MANDB_MAP /tmp/guix-build-manual-database.drv-0/manpages-collection /gnu/store/6w3gq10pgi8qmyq9i989glxs8md4miyk-manual-database/share/man
MANDB_MAP /tmp/guix-build-manual-database.drv-0/manpages-collection
/gnu/store/6w3gq10pgi8qmyq9i989glxs8md4miyk-manual-database/share/man

I don't think this is desirable. At first I was removing
all the MANDB_MAP entries and then adding only our, but there's nothing
to gain from doing this since the original man_db.conf file (bundled
with mandb) is still somehow read and contains those entries anyway
(which are harmless).

> +
> +        (mkdir-p man-directory)
> +        (setenv "MANPATH" (string-join entries ":"))
> +        (zero? (system* #+(file-append man-db "/bin/mandb")
> +                        "--quiet" "--create"
> +                        "-C" "man_db.conf"))))
> +
> +  (gexp->derivation "manual-database" build
> +                    #:modules '((guix build utils))
> +                    #: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
> +        manual-database
>          fonts-dir-file
>          ghc-package-cache-file
>          ca-certificate-bundle


I have reverted these two problematic changes and attached a new patch. Please
try it out and let me know how it works :)

Thanks,

Maxim

[-- Attachment #1.2: 0001-profiles-Generate-database-file-for-manpages.patch --]
[-- Type: text/x-patch, Size: 4522 bytes --]

From c81fc96da953c867749b56b96324f500ba428f03 Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Date: Tue, 28 Mar 2017 09:25:21 -0700
Subject: [PATCH] profiles: Generate database file for manpages
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The mandb database file (index.db) is used by the "apropos" (whatis) or
"man -k" commands. This change introduces a profile hook to generate
such database file.

Co-authored by Ludovic Courtès

* guix/profiles.scm (manual-database): New procedure.
(%default-profile-hooks): Add it.
---
 guix/profiles.scm | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 67 insertions(+)

diff --git a/guix/profiles.scm b/guix/profiles.scm
index 795c9447fe..0c719987b8 100644
--- a/guix/profiles.scm
+++ b/guix/profiles.scm
@@ -7,6 +7,7 @@
 ;;; Copyright © 2016 Ricardo Wurmus <rekado@elephly.net>
 ;;; Copyright © 2016 Chris Marusich <cmmarusich@gmail.com>
 ;;; Copyright © 2017 Huang Ying <huang.ying.caritas@gmail.com>
+;;; Copyright © 2017 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -946,10 +947,76 @@ files for the fonts of the @var{manifest} entries."
                     #:local-build? #t
                     #:substitutable? #f))
 
+(define (manual-database manifest)
+  (define man-db                                  ;lazy reference
+    (module-ref (resolve-interface '(gnu packages man)) 'man-db))
+
+  (define build
+    #~(begin
+        (use-modules (guix build utils)
+                     (srfi srfi-1))
+
+        (define entries
+          (filter-map (lambda (directory)
+                        (let ((man (string-append directory "/share/man")))
+                          (and (directory-exists? man)
+                               man)))
+                      '#$(manifest-inputs manifest)))
+
+        (define manpages-collection-dir
+          (string-append (getenv "PWD") "/manpages-collection"))
+
+        (define man-directory
+          (string-append #$output "/share/man"))
+
+        (define (get-manpage-tail-path manpage-path)
+          (let ((index (string-contains manpage-path "/share/man/")))
+            (substring manpage-path (+ index (string-length "/share/man/")))))
+
+        (define (populate-manpages-collection-dir entries)
+          (let ((manpages (append-map find-files entries)))
+            (for-each (lambda (manpage)
+                        (let* ((dest-file (string-append
+                                           manpages-collection-dir "/"
+                                           (get-manpage-tail-path manpage))))
+                          (mkdir-p (dirname dest-file))
+                          (catch 'system-error
+                            (lambda ()
+                              (symlink manpage dest-file))
+                            (lambda args
+                              ;; Different packages may contain the same
+                              ;; manpage.  Simply ignore the symlink error.
+                              #t))))
+                      manpages)))
+
+        (mkdir-p manpages-collection-dir)
+        (populate-manpages-collection-dir entries)
+
+        ;; Create a mandb config file which contains a custom made
+        ;; manpath. The associated catpath is the location where the database
+        ;; gets generated.
+        (copy-file #+(file-append man-db "/etc/man_db.conf")
+                   "man_db.conf")
+        (substitute* "man_db.conf"
+          (("MANDB_MAP	/usr/man		/var/cache/man/fsstnd")
+           (string-append "MANDB_MAP " manpages-collection-dir " "
+                          man-directory)))
+
+        (mkdir-p man-directory)
+        (setenv "MANPATH" (string-join entries ":"))
+        (zero? (system* #+(file-append man-db "/bin/mandb")
+                        "--quiet" "--create"
+                        "-C" "man_db.conf"))))
+
+  (gexp->derivation "manual-database" build
+                    #:modules '((guix build utils))
+                    #: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
+        manual-database
         fonts-dir-file
         ghc-package-cache-file
         ca-certificate-bundle
-- 
2.12.0


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

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

* Re: [PATCH] profiles: Generate database file for manpages
  2017-03-31  7:12   ` Maxim Cournoyer
@ 2017-03-31 22:44     ` Ludovic Courtès
  2017-04-03 15:29       ` Maxim Cournoyer
  0 siblings, 1 reply; 13+ messages in thread
From: Ludovic Courtès @ 2017-03-31 22:44 UTC (permalink / raw)
  To: Maxim Cournoyer; +Cc: guix-devel

Hi Maxim,

Maxim Cournoyer <maxim.cournoyer@gmail.com> skribis:

> Unfortunately some of the simplifications you made appear to break it
> :). I've tried your reworked patch and got the same result as you (no
> result found except when using man -K). When I use the original patch it
> works as I originally described.

Oops.

>> +        (define (populate-manpages-collection-dir entries)
>> +          (let ((manpages (append-map find-files entries)))
>> +            (for-each (lambda (manpage)
>> +                        (let* ((dest-file (string-append
>> +                                           manpages-collection-dir "/"
>> +                                           (strip-store-file-name manpage))))
>
> Unfortunately we cannot simply use strip-store-file-name, since what
> mandb expects to find in our manpages-collection-dir is a collection of
> subdirectories such as man1, man3, man7, etc. such as would be found
> under "/usr/share/man" on a traditional distro. This change instead
> makes it look like:
>
> bazaar-2.7.0/          gdbm-1.12/              libxau-1.0.8/  ...
>
> I guess this is what broke it.

Oh, got it.

However, with this version of the patch, I get:

--8<---------------cut here---------------start------------->8---
   ?: 0 [+ #f 11]

ERROR: In procedure +:
ERROR: In procedure +: Wrong type argument in position 1: #f
builder for `/gnu/store/y754cn7f468yc1b0pc13cxk99fmnwwx1-manual-database.drv' failed with exit code 1
--8<---------------cut here---------------end--------------->8---

which I think is because (string-contains manpage-path "/share/man/")
returns #f.

Could you look into it?

(BTW, I find it slightly clearer to use ‘string-drop’ etc. instead of
‘substring’.)

Other than that it should be fine.

Thank you!

Ludo’.

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

* Re: [PATCH] profiles: Generate database file for manpages
  2017-03-31 22:44     ` Ludovic Courtès
@ 2017-04-03 15:29       ` Maxim Cournoyer
  2017-04-04 12:29         ` Ludovic Courtès
  0 siblings, 1 reply; 13+ messages in thread
From: Maxim Cournoyer @ 2017-04-03 15:29 UTC (permalink / raw)
  To: Ludovic Courtès, guix-devel


[-- Attachment #1.1: Type: text/plain, Size: 2948 bytes --]

Hi Ludovic!

Sorry I couldn't reply before!

ludo@gnu.org (Ludovic Courtès) writes:

> Hi Maxim,
>
> Maxim Cournoyer <maxim.cournoyer@gmail.com> skribis:
>
>> Unfortunately some of the simplifications you made appear to break it
>> :). I've tried your reworked patch and got the same result as you (no
>> result found except when using man -K). When I use the original patch it
>> works as I originally described.
>
> Oops.
>
>>> +        (define (populate-manpages-collection-dir entries)
>>> +          (let ((manpages (append-map find-files entries)))
>>> +            (for-each (lambda (manpage)
>>> +                        (let* ((dest-file (string-append
>>> +                                           manpages-collection-dir "/"
>>> +                                           (strip-store-file-name manpage))))
>>
>> Unfortunately we cannot simply use strip-store-file-name, since what
>> mandb expects to find in our manpages-collection-dir is a collection of
>> subdirectories such as man1, man3, man7, etc. such as would be found
>> under "/usr/share/man" on a traditional distro. This change instead
>> makes it look like:
>>
>> bazaar-2.7.0/          gdbm-1.12/              libxau-1.0.8/  ...
>>
>> I guess this is what broke it.
>
> Oh, got it.
>
> However, with this version of the patch, I get:
>
>    ?: 0 [+ #f 11]
>
> ERROR: In procedure +:
> ERROR: In procedure +: Wrong type argument in position 1: #f
> builder for `/gnu/store/y754cn7f468yc1b0pc13cxk99fmnwwx1-manual-database.drv' failed with exit code 1
>
> which I think is because (string-contains manpage-path "/share/man/")
> returns #f.
>
> Could you look into it?
>
> (BTW, I find it slightly clearer to use ‘string-drop’ etc. instead of
> ‘substring’.)
>

Done.

> Other than that it should be fine.

Unfortunately I cannot reproduce the problem on my side, although you seem to be
right that this is caused by the `string-contains` not matching
"/share/man/" in the manpage-path and returning #f...

The only reason I'd suspect this could happen was if the `find-files`
method (used io list all the files contained under
"$manifest-inputs/share/man/") somehow returned bogus paths (I saw that
this function has a "fail-on-error?" argument which is disabled by default).

To help further troubleshoot this, could you please use the provided
patch instead, where I inserted:

 
         (define (get-manpage-tail-path manpage-path)
           (let ((index (string-contains manpage-path "/share/man/")))
+            (unless index
+              (error "Manual path doesn't contain \"/share/man/\":"
+                     manpage-path))
             (substring manpage-path (+ index (string-length "/share/man/")))))
 
         (define (populate-manpages-collection-dir entries)

to print the unexpectedly formed manpage-path.

Thanks! I hope we can sort this out.

Maxim


[-- Attachment #1.2: ~/src/guix/0001-profiles-Generate-database-file-for-manpages.patch --]
[-- Type: message/external-body, Size: 102 bytes --]

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

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

* Re: [PATCH] profiles: Generate database file for manpages
  2017-04-03 15:29       ` Maxim Cournoyer
@ 2017-04-04 12:29         ` Ludovic Courtès
  2017-04-04 14:20           ` Maxim Cournoyer
  0 siblings, 1 reply; 13+ messages in thread
From: Ludovic Courtès @ 2017-04-04 12:29 UTC (permalink / raw)
  To: Maxim Cournoyer; +Cc: guix-devel

Hi Maxim,

Maxim Cournoyer <maxim.cournoyer@gmail.com> skribis:

> Unfortunately I cannot reproduce the problem on my side, although you seem to be
> right that this is caused by the `string-contains` not matching
> "/share/man/" in the manpage-path and returning #f...
>
> The only reason I'd suspect this could happen was if the `find-files`
> method (used io list all the files contained under
> "$manifest-inputs/share/man/") somehow returned bogus paths (I saw that
> this function has a "fail-on-error?" argument which is disabled by default).
>
> To help further troubleshoot this, could you please use the provided
> patch instead, where I inserted:
>
>  
>          (define (get-manpage-tail-path manpage-path)
>            (let ((index (string-contains manpage-path "/share/man/")))
> +            (unless index
> +              (error "Manual path doesn't contain \"/share/man/\":"
> +                     manpage-path))
>              (substring manpage-path (+ index (string-length "/share/man/")))))
>  
>          (define (populate-manpages-collection-dir entries)
>
> to print the unexpectedly formed manpage-path.

The problem happens with "/gnu/store/rn3vri602z3jpwqnha0r5nwxi6v0qpnx-texlive-2016/share/man" (no
trailing slash):

--8<---------------cut here---------------start------------->8---
$ ls -l "/gnu/store/rn3vri602z3jpwqnha0r5nwxi6v0qpnx-texlive-2016/share/man"
lrwxrwxrwx 2 root root 70 Jan  1  1970 /gnu/store/rn3vri602z3jpwqnha0r5nwxi6v0qpnx-texlive-2016/share/man -> /gnu/store/8mhqravbd3pv7x1y2qfjlv0bdjchszn0-texlive-bin-2016/share/man
--8<---------------cut here---------------end--------------->8---

‘find-files’ uses ‘lstat’ by default, which means it does not follow
symlinks, and I guess that’s what’s happening here.  Perhaps
‘find-files’ needs to be called with #:stat stat to use ‘stat’ instead
of ‘lstat’?

Thanks,
Ludo’.

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

* Re: [PATCH] profiles: Generate database file for manpages
  2017-04-04 12:29         ` Ludovic Courtès
@ 2017-04-04 14:20           ` Maxim Cournoyer
  2017-04-05  0:59             ` Maxim Cournoyer
  2017-04-05  7:47             ` Ludovic Courtès
  0 siblings, 2 replies; 13+ messages in thread
From: Maxim Cournoyer @ 2017-04-04 14:20 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel


[-- Attachment #1.1: Type: text/plain, Size: 2024 bytes --]

Hi Ludovic,

ludo@gnu.org (Ludovic Courtès) writes:

> Hi Maxim,
>
> Maxim Cournoyer <maxim.cournoyer@gmail.com> skribis:
>
>> Unfortunately I cannot reproduce the problem on my side, although you seem to be
>> right that this is caused by the `string-contains` not matching
>> "/share/man/" in the manpage-path and returning #f...
>>
>> The only reason I'd suspect this could happen was if the `find-files`
>> method (used io list all the files contained under
>> "$manifest-inputs/share/man/") somehow returned bogus paths (I saw that
>> this function has a "fail-on-error?" argument which is disabled by default).
>>
>> To help further troubleshoot this, could you please use the provided
>> patch instead, where I inserted:
>>
>>  
>>          (define (get-manpage-tail-path manpage-path)
>>            (let ((index (string-contains manpage-path "/share/man/")))
>> +            (unless index
>> +              (error "Manual path doesn't contain \"/share/man/\":"
>> +                     manpage-path))
>>              (substring manpage-path (+ index (string-length "/share/man/")))))
>>  
>>          (define (populate-manpages-collection-dir entries)
>>
>> to print the unexpectedly formed manpage-path.
>
> The problem happens with "/gnu/store/rn3vri602z3jpwqnha0r5nwxi6v0qpnx-texlive-2016/share/man" (no
> trailing slash):
>
> $ ls -l "/gnu/store/rn3vri602z3jpwqnha0r5nwxi6v0qpnx-texlive-2016/share/man"
> lrwxrwxrwx 2 root root 70 Jan  1  1970 /gnu/store/rn3vri602z3jpwqnha0r5nwxi6v0qpnx-texlive-2016/share/man -> /gnu/store/8mhqravbd3pv7x1y2qfjlv0bdjchszn0-texlive-bin-2016/share/man
>
> ‘find-files’ uses ‘lstat’ by default, which means it does not follow
> symlinks, and I guess that’s what’s happening here.  Perhaps
> ‘find-files’ needs to be called with #:stat stat to use ‘stat’ instead
> of ‘lstat’?
>
> Thanks,
> Ludo’.

That's a good idea! Could you please try again with the new included
patch? Here are the latest changes:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: Type: text/x-patch, Size: 1282 bytes --]

@@ -954,7 +954,8 @@ files for the fonts of the @var{manifest} entries."
   (define build
     #~(begin
         (use-modules (guix build utils)
-                     (srfi srfi-1))
+                     (srfi srfi-1)
+                     (srfi srfi-26))
 
         (define entries
           (filter-map (lambda (directory)
@@ -977,7 +978,7 @@ files for the fonts of the @var{manifest} entries."
             (string-drop manpage-path (+ index (string-length "/share/man/")))))
 
         (define (populate-manpages-collection-dir entries)
-          (let ((manpages (append-map find-files entries)))
+          (let ((manpages (append-map (cut find-files <> #:stat stat) entries)))
             (for-each (lambda (manpage)
                         (let* ((dest-file (string-append
                                            manpages-collection-dir "/"
@@ -1012,7 +1013,8 @@ files for the fonts of the @var{manifest} entries."
                         "-C" "man_db.conf"))))
 
   (gexp->derivation "manual-database" build
-                    #:modules '((guix build utils))
+                    #:modules '((guix build utils)
+                                (srfi srfi-26))
                     #:local-build? #t))
 
 (define %default-profile-hooks

[-- Attachment #1.3: Type: text/plain, Size: 40 bytes --]


I think we're closing in... :)

Maxim


[-- Attachment #1.4: ~/src/guix/0001-profiles-Generate-database-file-for-manpages.patch --]
[-- Type: message/external-body, Size: 102 bytes --]

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

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

* Re: [PATCH] profiles: Generate database file for manpages
  2017-04-04 14:20           ` Maxim Cournoyer
@ 2017-04-05  0:59             ` Maxim Cournoyer
  2017-04-05  7:45               ` Ludovic Courtès
  2017-04-05  7:47             ` Ludovic Courtès
  1 sibling, 1 reply; 13+ messages in thread
From: Maxim Cournoyer @ 2017-04-05  0:59 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel


[-- Attachment #1.1: Type: text/plain, Size: 131 bytes --]

Another thought/experiment:

It could be interesting to use find-files with the  #:fail-on-error?
flag set to #t. When trying it:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: Type: text/x-patch, Size: 610 bytes --]

modified   guix/profiles.scm
@@ -978,7 +978,7 @@ files for the fonts of the @var{manifest} entries."
             (string-drop manpage-path (+ index (string-length "/share/man/")))))
 
         (define (populate-manpages-collection-dir entries)
-          (let ((manpages (append-map (cut find-files <> #:stat stat) entries)))
+          (let ((manpages (append-map (cut find-files <> #:stat stat #:fail-on-error? #t) entries)))
             (for-each (lambda (manpage)
                         (let* ((dest-file (string-append
                                            manpages-collection-dir "/"

[-- Attachment #1.3: Type: text/plain, Size: 491 bytes --]

                                            
It found a broken link for one of the manpages shipped with our gimp package.

find-files: /gnu/store/wh2bryjss0pnrv9ss4jbbkwfbj2ql22i-gimp-2.8.18/share/man/man1/gimp-console.1: No such file or directory

file /gnu/store/wh2bryjss0pnrv9ss4jbbkwfbj2ql22i-gimp-2.8.18/share/man/man1/gimp-console.1 
/gnu/store/wh2bryjss0pnrv9ss4jbbkwfbj2ql22i-gimp-2.8.18/share/man/man1/gimp-console.1: broken symbolic link to gimp-console-2.8.1.gz

Maxim

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

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

* Re: [PATCH] profiles: Generate database file for manpages
  2017-04-05  0:59             ` Maxim Cournoyer
@ 2017-04-05  7:45               ` Ludovic Courtès
  0 siblings, 0 replies; 13+ messages in thread
From: Ludovic Courtès @ 2017-04-05  7:45 UTC (permalink / raw)
  To: Maxim Cournoyer; +Cc: guix-devel

Hello!

Maxim Cournoyer <maxim.cournoyer@gmail.com> skribis:

> Another thought/experiment:
>
> It could be interesting to use find-files with the  #:fail-on-error?
> flag set to #t. When trying it:
>
> modified   guix/profiles.scm
> @@ -978,7 +978,7 @@ files for the fonts of the @var{manifest} entries."
>              (string-drop manpage-path (+ index (string-length "/share/man/")))))
>  
>          (define (populate-manpages-collection-dir entries)
> -          (let ((manpages (append-map (cut find-files <> #:stat stat) entries)))
> +          (let ((manpages (append-map (cut find-files <> #:stat stat #:fail-on-error? #t) entries)))
>              (for-each (lambda (manpage)
>                          (let* ((dest-file (string-append
>                                             manpages-collection-dir "/"
>
>                                             
> It found a broken link for one of the manpages shipped with our gimp package.

I think we should rather do this check for instance in a new build
phase, rather than have the profile hook fail.

WDYT?

> file /gnu/store/wh2bryjss0pnrv9ss4jbbkwfbj2ql22i-gimp-2.8.18/share/man/man1/gimp-console.1 
> /gnu/store/wh2bryjss0pnrv9ss4jbbkwfbj2ql22i-gimp-2.8.18/share/man/man1/gimp-console.1: broken symbolic link to gimp-console-2.8.1.gz

I wonder why this happens…

Thanks,
Ludo’.

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

* Re: [PATCH] profiles: Generate database file for manpages
  2017-04-04 14:20           ` Maxim Cournoyer
  2017-04-05  0:59             ` Maxim Cournoyer
@ 2017-04-05  7:47             ` Ludovic Courtès
  2017-04-05  8:09               ` Maxim Cournoyer
  1 sibling, 1 reply; 13+ messages in thread
From: Ludovic Courtès @ 2017-04-05  7:47 UTC (permalink / raw)
  To: Maxim Cournoyer; +Cc: guix-devel

Hi Maxim,

Maxim Cournoyer <maxim.cournoyer@gmail.com> skribis:

> ludo@gnu.org (Ludovic Courtès) writes:
>
>> Hi Maxim,
>>
>> Maxim Cournoyer <maxim.cournoyer@gmail.com> skribis:
>>
>>> Unfortunately I cannot reproduce the problem on my side, although you seem to be
>>> right that this is caused by the `string-contains` not matching
>>> "/share/man/" in the manpage-path and returning #f...
>>>
>>> The only reason I'd suspect this could happen was if the `find-files`
>>> method (used io list all the files contained under
>>> "$manifest-inputs/share/man/") somehow returned bogus paths (I saw that
>>> this function has a "fail-on-error?" argument which is disabled by default).
>>>
>>> To help further troubleshoot this, could you please use the provided
>>> patch instead, where I inserted:
>>>
>>>  
>>>          (define (get-manpage-tail-path manpage-path)
>>>            (let ((index (string-contains manpage-path "/share/man/")))
>>> +            (unless index
>>> +              (error "Manual path doesn't contain \"/share/man/\":"
>>> +                     manpage-path))
>>>              (substring manpage-path (+ index (string-length "/share/man/")))))
>>>  
>>>          (define (populate-manpages-collection-dir entries)
>>>
>>> to print the unexpectedly formed manpage-path.
>>
>> The problem happens with "/gnu/store/rn3vri602z3jpwqnha0r5nwxi6v0qpnx-texlive-2016/share/man" (no
>> trailing slash):
>>
>> $ ls -l "/gnu/store/rn3vri602z3jpwqnha0r5nwxi6v0qpnx-texlive-2016/share/man"
>> lrwxrwxrwx 2 root root 70 Jan  1  1970 /gnu/store/rn3vri602z3jpwqnha0r5nwxi6v0qpnx-texlive-2016/share/man -> /gnu/store/8mhqravbd3pv7x1y2qfjlv0bdjchszn0-texlive-bin-2016/share/man
>>
>> ‘find-files’ uses ‘lstat’ by default, which means it does not follow
>> symlinks, and I guess that’s what’s happening here.  Perhaps
>> ‘find-files’ needs to be called with #:stat stat to use ‘stat’ instead
>> of ‘lstat’?
>>
>> Thanks,
>> Ludo’.
>
> That's a good idea! Could you please try again with the new included
> patch? Here are the latest changes:
>
> @@ -954,7 +954,8 @@ files for the fonts of the @var{manifest} entries."
>    (define build
>      #~(begin
>          (use-modules (guix build utils)
> -                     (srfi srfi-1))
> +                     (srfi srfi-1)
> +                     (srfi srfi-26))
>  
>          (define entries
>            (filter-map (lambda (directory)
> @@ -977,7 +978,7 @@ files for the fonts of the @var{manifest} entries."
>              (string-drop manpage-path (+ index (string-length "/share/man/")))))
>  
>          (define (populate-manpages-collection-dir entries)
> -          (let ((manpages (append-map find-files entries)))
> +          (let ((manpages (append-map (cut find-files <> #:stat stat) entries)))
>              (for-each (lambda (manpage)
>                          (let* ((dest-file (string-append
>                                             manpages-collection-dir "/"
> @@ -1012,7 +1013,8 @@ files for the fonts of the @var{manifest} entries."
>                          "-C" "man_db.conf"))))
>  
>    (gexp->derivation "manual-database" build
> -                    #:modules '((guix build utils))
> +                    #:modules '((guix build utils)
> +                                (srfi srfi-26))
>                      #:local-build? #t))
>  
>  (define %default-profile-hooks
>
>
> I think we're closing in... :)
>
> Maxim

The attachment is missing from your message (it’s marked as
“message/external-body”, which AIUI means that it would just look for a
same-named file on the recipient’s machine.)  Could you resend it?  :-)

Thanks,
Ludo’.

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

* Re: [PATCH] profiles: Generate database file for manpages
  2017-04-05  7:47             ` Ludovic Courtès
@ 2017-04-05  8:09               ` Maxim Cournoyer
  2017-04-05 21:00                 ` Ludovic Courtès
  0 siblings, 1 reply; 13+ messages in thread
From: Maxim Cournoyer @ 2017-04-05  8:09 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel


[-- Attachment #1.1: Type: text/plain, Size: 326 bytes --]

Hi Ludovic!

ludo@gnu.org (Ludovic Courtès) writes:

[...]

> The attachment is missing from your message (it’s marked as
> “message/external-body”, which AIUI means that it would just look for a
> same-named file on the recipient’s machine.)  Could you resend it?  :-)

Sorry about that! Resending now.


[-- Attachment #1.2: 0001-profiles-Generate-database-file-for-manpages.patch --]
[-- Type: text/x-patch, Size: 4768 bytes --]

From b6aff9b364f09e77e07109578128f3be383231e0 Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Date: Tue, 28 Mar 2017 09:25:21 -0700
Subject: [PATCH] profiles: Generate database file for manpages
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The mandb database file (index.db) is used by the "apropos" (whatis) or
"man -k" commands. This change introduces a profile hook to generate
such database file.

Co-authored by Ludovic Courtès

* guix/profiles.scm (manual-database): New procedure.
(%default-profile-hooks): Add it.
---
 guix/profiles.scm | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 72 insertions(+)

diff --git a/guix/profiles.scm b/guix/profiles.scm
index 795c9447fe..097d684438 100644
--- a/guix/profiles.scm
+++ b/guix/profiles.scm
@@ -7,6 +7,7 @@
 ;;; Copyright © 2016 Ricardo Wurmus <rekado@elephly.net>
 ;;; Copyright © 2016 Chris Marusich <cmmarusich@gmail.com>
 ;;; Copyright © 2017 Huang Ying <huang.ying.caritas@gmail.com>
+;;; Copyright © 2017 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -946,10 +947,81 @@ files for the fonts of the @var{manifest} entries."
                     #:local-build? #t
                     #:substitutable? #f))
 
+(define (manual-database manifest)
+  (define man-db                                  ;lazy reference
+    (module-ref (resolve-interface '(gnu packages man)) 'man-db))
+
+  (define build
+    #~(begin
+        (use-modules (guix build utils)
+                     (srfi srfi-1)
+                     (srfi srfi-26))
+
+        (define entries
+          (filter-map (lambda (directory)
+                        (let ((man (string-append directory "/share/man")))
+                          (and (directory-exists? man)
+                               man)))
+                      '#$(manifest-inputs manifest)))
+
+        (define manpages-collection-dir
+          (string-append (getenv "PWD") "/manpages-collection"))
+
+        (define man-directory
+          (string-append #$output "/share/man"))
+
+        (define (get-manpage-tail-path manpage-path)
+          (let ((index (string-contains manpage-path "/share/man/")))
+            (unless index
+              (error "Manual path doesn't contain \"/share/man/\":"
+                     manpage-path))
+            (string-drop manpage-path (+ index (string-length "/share/man/")))))
+
+        (define (populate-manpages-collection-dir entries)
+          (let ((manpages (append-map (cut find-files <> #:stat stat) entries)))
+            (for-each (lambda (manpage)
+                        (let* ((dest-file (string-append
+                                           manpages-collection-dir "/"
+                                           (get-manpage-tail-path manpage))))
+                          (mkdir-p (dirname dest-file))
+                          (catch 'system-error
+                            (lambda ()
+                              (symlink manpage dest-file))
+                            (lambda args
+                              ;; Different packages may contain the same
+                              ;; manpage.  Simply ignore the symlink error.
+                              #t))))
+                      manpages)))
+
+        (mkdir-p manpages-collection-dir)
+        (populate-manpages-collection-dir entries)
+
+        ;; Create a mandb config file which contains a custom made
+        ;; manpath. The associated catpath is the location where the database
+        ;; gets generated.
+        (copy-file #+(file-append man-db "/etc/man_db.conf")
+                   "man_db.conf")
+        (substitute* "man_db.conf"
+          (("MANDB_MAP	/usr/man		/var/cache/man/fsstnd")
+           (string-append "MANDB_MAP " manpages-collection-dir " "
+                          man-directory)))
+
+        (mkdir-p man-directory)
+        (setenv "MANPATH" (string-join entries ":"))
+        (zero? (system* #+(file-append man-db "/bin/mandb")
+                        "--quiet" "--create"
+                        "-C" "man_db.conf"))))
+
+  (gexp->derivation "manual-database" build
+                    #:modules '((guix build utils)
+                                (srfi srfi-26))
+                    #: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
+        manual-database
         fonts-dir-file
         ghc-package-cache-file
         ca-certificate-bundle
-- 
2.12.0


[-- Attachment #1.3: Type: text/plain, Size: 7 bytes --]


Maxim

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

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

* Re: [PATCH] profiles: Generate database file for manpages
  2017-04-05  8:09               ` Maxim Cournoyer
@ 2017-04-05 21:00                 ` Ludovic Courtès
  2017-04-06  6:32                   ` Maxim Cournoyer
  0 siblings, 1 reply; 13+ messages in thread
From: Ludovic Courtès @ 2017-04-05 21:00 UTC (permalink / raw)
  To: Maxim Cournoyer; +Cc: guix-devel

Maxim Cournoyer <maxim.cournoyer@gmail.com> skribis:

> From b6aff9b364f09e77e07109578128f3be383231e0 Mon Sep 17 00:00:00 2001
> From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
> Date: Tue, 28 Mar 2017 09:25:21 -0700
> Subject: [PATCH] profiles: Generate database file for manpages
> MIME-Version: 1.0
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: 8bit
>
> The mandb database file (index.db) is used by the "apropos" (whatis) or
> "man -k" commands. This change introduces a profile hook to generate
> such database file.
>
> Co-authored by Ludovic Courtès
>
> * guix/profiles.scm (manual-database): New procedure.
> (%default-profile-hooks): Add it.

Finally applied as a0b87ef8ec7735aa42cf35d380e9cff04f3236f3!  \o/
I added a ‘format’ call in the hook itself so that people understand
what’s going on if it takes too long, and tweaked the commit log.

While at it, I added in commit 31f1f593fb835978085566e50d3d8c576d55fe99
a section on searching for and reading Info and man documentation.
Something that may be obvious for some of us but less so for other
(notably younger) users.  Feel free to extend it!

Thanks,
Ludo’.

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

* Re: [PATCH] profiles: Generate database file for manpages
  2017-04-05 21:00                 ` Ludovic Courtès
@ 2017-04-06  6:32                   ` Maxim Cournoyer
  0 siblings, 0 replies; 13+ messages in thread
From: Maxim Cournoyer @ 2017-04-06  6:32 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel

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

Hi Ludovic!

ludo@gnu.org (Ludovic Courtès) writes:

> Maxim Cournoyer <maxim.cournoyer@gmail.com> skribis:
>
>> From b6aff9b364f09e77e07109578128f3be383231e0 Mon Sep 17 00:00:00 2001
>> From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
>> Date: Tue, 28 Mar 2017 09:25:21 -0700
>> Subject: [PATCH] profiles: Generate database file for manpages
>> MIME-Version: 1.0
>> Content-Type: text/plain; charset=UTF-8
>> Content-Transfer-Encoding: 8bit
>>
>> The mandb database file (index.db) is used by the "apropos" (whatis) or
>> "man -k" commands. This change introduces a profile hook to generate
>> such database file.
>>
>> Co-authored by Ludovic Courtès
>>
>> * guix/profiles.scm (manual-database): New procedure.
>> (%default-profile-hooks): Add it.
>
> Finally applied as a0b87ef8ec7735aa42cf35d380e9cff04f3236f3!  \o/
> I added a ‘format’ call in the hook itself so that people understand
> what’s going on if it takes too long, and tweaked the commit log.
>
> While at it, I added in commit 31f1f593fb835978085566e50d3d8c576d55fe99
> a section on searching for and reading Info and man documentation.
> Something that may be obvious for some of us but less so for other
> (notably younger) users.  Feel free to extend it!
>

Thanks for your collaboration on this! I think the Documentation section
you added be of  great help to Guix newcomers; I reviewed it and it
looks great!

> Thanks,
> Ludo’.

Thanks!

Maxim

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

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

end of thread, other threads:[~2017-04-06  6:32 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-30  8:35 [PATCH] profiles: Generate database file for manpages Maxim Cournoyer
2017-03-30 15:53 ` Ludovic Courtès
2017-03-31  7:12   ` Maxim Cournoyer
2017-03-31 22:44     ` Ludovic Courtès
2017-04-03 15:29       ` Maxim Cournoyer
2017-04-04 12:29         ` Ludovic Courtès
2017-04-04 14:20           ` Maxim Cournoyer
2017-04-05  0:59             ` Maxim Cournoyer
2017-04-05  7:45               ` Ludovic Courtès
2017-04-05  7:47             ` Ludovic Courtès
2017-04-05  8:09               ` Maxim Cournoyer
2017-04-05 21:00                 ` Ludovic Courtès
2017-04-06  6:32                   ` Maxim Cournoyer

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).