[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] profiles: Generate database file for manpages
From: |
Ludovic Courtès |
Subject: |
Re: [PATCH] profiles: Generate database file for manpages |
Date: |
Thu, 30 Mar 2017 17:53:18 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) |
Hi Maxim,
Maxim Cournoyer <address@hidden> 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 <address@hidden>
> 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’.
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 <address@hidden>
;;; Copyright © 2016 Chris Marusich <address@hidden>
;;; Copyright © 2017 Huang Ying <address@hidden>
+;;; Copyright © 2017 Maxim Cournoyer <address@hidden>
;;;
;;; 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