Subject: Re: [PATCH v2 3/3] gnu: Add emacs-notmuch.

From: Andrew Tropin <[email-masked]>
Date: Tue, 14 Sep 2021 10:22:52 +0300

On 2021-09-04 11:42, Xinglu Chen wrote:

> * gnu/packages/mail.scm (notmuch)[arguments]: Remove Emacs-related stuff.
> * gnu/packages/emacs-xyz.scm (emacs-consult-notmuch)[propagated-inputs]: Add
> ‘emacs-notmuch’.
> (emacs-counsel-notmuch)[propagated-inputs]: Use ‘emacs-notmuch’ instead of
> ‘notmuch’.
> (emacs-helm-notmuch): Likewise.
> (emacs-notmuch-maildir): Likewise.
> ---
>  gnu/packages/emacs-xyz.scm |  8 +++---
>  gnu/packages/mail.scm      | 52 +++++++++++++++++++++++---------------
>  2 files changed, 37 insertions(+), 23 deletions(-)
>
> diff --git a/gnu/packages/emacs-xyz.scm b/gnu/packages/emacs-xyz.scm
> index 030809f5ac..67ba8bf523 100644
> --- a/gnu/packages/emacs-xyz.scm
> +++ b/gnu/packages/emacs-xyz.scm
> @@ -8304,7 +8304,7 @@ list of candidates.")
>      (build-system emacs-build-system)
>      (propagated-inputs
>       `(("emacs-consult" ,emacs-consult)
> -       ("notmuch" ,notmuch)))
> +       ("emacs-notmuch" ,emacs-notmuch)))
>      (home-page "https://codeberg.org/jao/consult-notmuch")
>      (synopsis "Search and preview Notmuch emails using Consult")
>      (description
> @@ -9490,6 +9490,8 @@ queries using counsel.")
>         `(("emacs-counsel" ,emacs-counsel)
>           ("notmuch" ,notmuch)
>           ("emacs-s" ,emacs-s)))
> +      (propagated-inputs
> +       `(("emacs-notmuch" ,emacs-notmuch)))
>        (home-page "https://github.com/fuxialexander/counsel-notmuch")
>        (synopsis "Search emails in Notmuch asynchronously with Ivy")
>        (description
> @@ -23952,7 +23954,7 @@ workspaces with a LSP-compliant server running.")
>      (build-system emacs-build-system)
>      (propagated-inputs
>       `(("emacs-helm" ,emacs-helm)
> -       ("notmuch" ,notmuch)))
> +       ("emacs-notmuch" ,emacs-notmuch)))
>      (synopsis "Search emails with Emacs Notmuch and Helm")
>      (description
>       "This package can be used to search emails in Emacs, searching result
> @@ -23975,7 +23977,7 @@ real search.")
>                  "0pmikf1djkr07067nkgmdcxyn7l7ibswx6qlnai8v1v51f9h1g9q"))))
>      (build-system emacs-build-system)
>      (propagated-inputs
> -     `(("notmuch" ,notmuch)))
> +     `(("emacs-notmuch" ,emacs-notmuch)))
>      (home-page "https://git.sr.ht/~tarsius/notmuch-maildir")
>      (synopsis "Visualize maildirs as a tree")
>      (description
> diff --git a/gnu/packages/mail.scm b/gnu/packages/mail.scm
> index 173982cb12..729e47cb95 100644
> --- a/gnu/packages/mail.scm
> +++ b/gnu/packages/mail.scm
> @@ -167,6 +167,7 @@
>    #:use-module (guix build-system gnu)
>    #:use-module (guix build-system go)
>    #:use-module (guix build-system guile)
> +  #:use-module (guix build-system emacs)
>    #:use-module (guix build-system meson)
>    #:use-module (guix build-system perl)
>    #:use-module (guix build-system python)
> @@ -1342,31 +1343,18 @@ invoking @command{notifymuch} from the post-new hook.")
>                  "1myylb19hj5nb1vriqng252vfjwwkgbi3gxj93pi2q1fzyw7w2lf"))))
>      (build-system gnu-build-system)
>      (arguments
> -     `(#:modules ((guix build gnu-build-system)
> -                  ((guix build emacs-build-system) #:prefix emacs:)
> -                  (guix build utils))
> -       #:imported-modules (,@%gnu-build-system-modules
> -                           (guix build emacs-build-system)
> -                           (guix build emacs-utils))
> -       #:make-flags
> +     `(#:make-flags
>         (list "V=1"                      ; verbose test output
>               "NOTMUCH_TEST_TIMEOUT=1h") ; don't fail on slow machines
>         #:phases (modify-phases %standard-phases
> -                  (add-after 'unpack 'patch-notmuch-lib.el
> -                    (lambda _
> -                      (substitute* "emacs/notmuch-lib.el"
> -                        (("/bin/sh") (which "sh")))))
>                    (replace 'configure
>                      (lambda* (#:key outputs #:allow-other-keys)
>                        (setenv "CC" ,(cc-for-target))
>                        (setenv "CONFIG_SHELL" (which "sh"))
> -
> -                      (let* ((out (assoc-ref outputs "out"))
> -                             (elisp (emacs:elpa-directory out)))
> +                      (let* ((out (assoc-ref outputs "out")))
>                          (invoke "./configure"
>                                  (string-append "--prefix=" out)
> -                                (string-append "--emacslispdir=" elisp)
> -                                (string-append "--emacsetcdir=" elisp)))))
> +                                "--without-emacs"))))
>                    (add-before 'check 'disable-failing-tests
>                      ;; FIXME: Investigate why these tests are failing,
>                      ;; and try removing this for notmuch versions > 0.31.
> @@ -1378,12 +1366,9 @@ invoking @command{notifymuch} from the post-new hook.")
>                        (setenv "TEST_CC" ,(cc-for-target))
>                        ;; Patch various inline shell invocations.
>                        (substitute* (find-files "test" "\\.sh$")
> -                        (("/bin/sh") (which "sh")))))
> -                  (add-after 'install 'make-autoloads
> -                    (assoc-ref emacs:%standard-phases 'make-autoloads)))))
> +                        (("/bin/sh") (which "sh"))))))))
>      (native-inputs
>       `(("bash-completion" ,bash-completion)
> -       ("emacs" ,emacs-no-x)    ; -minimal lacks libxml, needed for some tests
>         ("pkg-config" ,pkg-config)
>         ("python" ,python)
>         ("python-docutils" ,python-docutils)
> @@ -1391,6 +1376,7 @@ invoking @command{notifymuch} from the post-new hook.")
>         ("texinfo" ,texinfo)
>  
>         ;; The following are required for tests only.
> +       ("emacs" ,emacs-no-x)    ; -minimal lacks libxml, needed for some tests
>         ("which" ,which)
>         ("dtach" ,dtach)
>         ("gnupg" ,gnupg)
> @@ -1409,6 +1395,32 @@ invoking @command{notifymuch} from the post-new hook.")
>  ing, and tagging large collections of email messages.")
>      (license license:gpl3+)))
>  
> +(define-public emacs-notmuch
> +  (package
> +    (inherit notmuch)
> +    (name "emacs-notmuch")
> +    (build-system emacs-build-system)
> +    (native-inputs '())
> +    (inputs
> +     `(("notmuch" ,notmuch)))
> +    (arguments
> +     `(#:exclude (cons* "make-deps.el" "rstdoc.el" %default-exclude)
> +       #:phases
> +       (modify-phases %standard-phases
> +         (add-after 'unpack 'chdir
> +           (lambda _
> +             (chdir "emacs")))
> +         (add-after 'chdir 'patch-paths
> +           (lambda* (#:key inputs #:allow-other-keys)
> +             (let ((notmuch (assoc-ref inputs "notmuch")))
> +               (substitute* "notmuch-lib.el"
> +                 (("\"notmuch\"")
> +                  (string-append "\"" notmuch "/bin/notmuch\"")))))))))

Not sure if we need to hardcode the path to notmuch binary (some people
can use guix for managing emacs packages, but not system), but I think
it's a rare case and this default is reasonable and easily fixable by
simple `(setq notmuch-command "notmuch")` in the cases, when notmuch
itslef provided by other package manager.

> +    (synopsis "Run Notmuch within Emacs")
> +    (description
> +     "This package provides an Emacs-based interface to the Notmuch mail
> +system.")))
> +
>  (define-public notmuch-addrlookup-c
>    (package
>      (name "notmuch-addrlookup-c")

Overall, LGTM.