all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: guix-devel <guix-devel@gnu.org>
Subject: Re: [PATCH] profiles: Generate database file for manpages
Date: Wed, 05 Apr 2017 01:09:22 -0700	[thread overview]
Message-ID: <87vaqje0nh.fsf@gmail.com> (raw)
In-Reply-To: <87lgrfmh3e.fsf@gnu.org> ("Ludovic \=\?utf-8\?Q\?Court\=C3\=A8s\=22'\?\= \=\?utf-8\?Q\?s\?\= message of "Wed, 05 Apr 2017 09:47:01 +0200")


[-- 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 --]

  reply	other threads:[~2017-04-05  8:09 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2017-04-05 21:00                 ` Ludovic Courtès
2017-04-06  6:32                   ` Maxim Cournoyer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87vaqje0nh.fsf@gmail.com \
    --to=maxim.cournoyer@gmail.com \
    --cc=guix-devel@gnu.org \
    --cc=ludo@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.