nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 fetchpatch,
3 fetchurl,
4 lib,
5 stdenv,
6 makeWrapper,
7 buildEnv,
8 pkg-config,
9 gnupg,
10 xapian,
11 gmime3,
12 sfsexp,
13 talloc,
14 zlib,
15 doxygen,
16 perl,
17 texinfo,
18 pythonPackages,
19 emacs,
20 ruby,
21 testers,
22 gitUpdater,
23 which,
24 dtach,
25 openssl,
26 bash,
27 gdb,
28 man,
29 git,
30 withEmacs ? true,
31 withRuby ? true,
32 withSfsexp ? true, # also installs notmuch-git, which requires sexp-support
33 # TODO upstream: it takes too long ! 800 ms here
34 withVim ? true,
35}:
36
37stdenv.mkDerivation (finalAttrs: {
38 pname = "notmuch";
39 version = "0.39";
40
41 src = fetchurl {
42 url = "https://notmuchmail.org/releases/notmuch-${finalAttrs.version}.tar.xz";
43 hash = "sha256-uIuwKnbEa62NMT/Su0+OOSmLUfZvy+swTZ+Aw+73BOM=";
44 };
45
46 nativeBuildInputs = [
47 pkg-config
48 doxygen # (optional) api docs
49 pythonPackages.sphinx # (optional) documentation -> doc/INSTALL
50 texinfo # (optional) documentation -> doc/INSTALL
51 pythonPackages.cffi
52 ]
53 ++ lib.optional withEmacs emacs
54 ++ lib.optional withRuby ruby
55 ++ lib.optional withSfsexp makeWrapper;
56
57 buildInputs = [
58 gnupg # undefined dependencies
59 xapian
60 gmime3
61 talloc
62 zlib # dependencies described in INSTALL
63 perl
64 pythonPackages.python
65 ]
66 ++ lib.optional withRuby ruby
67 ++ lib.optional withSfsexp sfsexp;
68
69 postPatch = ''
70 patchShebangs configure test/
71
72 substituteInPlace lib/Makefile.local \
73 --replace '-install_name $(libdir)' "-install_name $out/lib"
74
75 # do not override CFLAGS of the Makefile created by mkmf
76 substituteInPlace bindings/Makefile.local \
77 --replace 'CFLAGS="$(CFLAGS) -pipe -fno-plt -fPIC"' ""
78 ''
79 + lib.optionalString withEmacs ''
80 substituteInPlace emacs/notmuch-emacs-mua \
81 --replace 'EMACS:-emacs' 'EMACS:-${emacs}/bin/emacs' \
82 --replace 'EMACSCLIENT:-emacsclient' 'EMACSCLIENT:-${emacs}/bin/emacsclient'
83 '';
84
85 configureFlags = [
86 "--zshcompletiondir=${placeholder "out"}/share/zsh/site-functions"
87 "--bashcompletiondir=${placeholder "out"}/share/bash-completion/completions"
88 "--infodir=${placeholder "info"}/share/info"
89 ]
90 ++ lib.optional (!withEmacs) "--without-emacs"
91 ++ lib.optional withEmacs "--emacslispdir=${placeholder "emacs"}/share/emacs/site-lisp"
92 ++ lib.optional (!withRuby) "--without-ruby";
93
94 # Notmuch doesn't use autoconf and consequently doesn't tag --bindir and
95 # friends
96 setOutputFlags = false;
97 enableParallelBuilding = true;
98 makeFlags = [ "V=1" ];
99
100 postConfigure = ''
101 mkdir ${placeholder "bindingconfig"}
102 cp bindings/python-cffi/_notmuch_config.py ${placeholder "bindingconfig"}/
103 '';
104
105 outputs = [
106 "out"
107 "man"
108 "info"
109 "bindingconfig"
110 ]
111 ++ lib.optional withEmacs "emacs"
112 ++ lib.optional withVim "vim";
113
114 # if notmuch is built with s-expression support, the testsuite (T-850.sh) only
115 # passes if notmuch-git can be executed, so we need to patch its shebang.
116 postBuild = lib.optionalString withSfsexp ''
117 patchShebangs notmuch-git
118 '';
119
120 preCheck =
121 let
122 test-database = fetchurl {
123 url = "https://notmuchmail.org/releases/test-databases/database-v1.tar.xz";
124 sha256 = "1lk91s00y4qy4pjh8638b5lfkgwyl282g1m27srsf7qfn58y16a2";
125 };
126 in
127 ''
128 mkdir -p test/test-databases
129 ln -s ${test-database} test/test-databases/database-v1.tar.xz
130 ''
131 + ''
132 # Issues since pbr 6.0.0 bump (ModuleNotFoundError: No module named 'notmuch2')
133 rm test/T055-path-config.sh
134 rm test/T610-message-property.sh
135 # Flaky, seems to get its paths wrong sometimes (?)
136 # *ERROR*: Opening output file: Permission denied, /nix/store/bzy21v2cd5sq1djzwa9b19q08wpp9mm0-emacs-29.1/bin/OUTPUT
137 rm test/T460-emacs-tree.sh
138 '';
139
140 doCheck = !stdenv.hostPlatform.isDarwin && (lib.versionAtLeast gmime3.version "3.0.3");
141 checkTarget = "test";
142 nativeCheckInputs = [
143 which
144 dtach
145 openssl
146 bash
147 gdb
148 man
149 ]
150 # for the test T-850.sh for notmuch-git, which is skipped when notmuch is
151 # built without sexp-support
152 ++ lib.optional withEmacs emacs
153 ++ lib.optional withSfsexp git;
154
155 installTargets = [
156 "install"
157 "install-man"
158 "install-info"
159 ];
160
161 postInstall =
162 lib.optionalString withEmacs ''
163 moveToOutput bin/notmuch-emacs-mua $emacs
164 ''
165 + lib.optionalString withRuby ''
166 make -C bindings/ruby install \
167 vendordir=$out/lib/ruby \
168 SHELL=$SHELL \
169 $makeFlags "''${makeFlagsArray[@]}" \
170 $installFlags "''${installFlagsArray[@]}"
171 ''
172 # notmuch-git (https://notmuchmail.org/doc/latest/man1/notmuch-git.html) does not work without
173 # sexp-support, so there is no point in installing if we're building without it.
174 + lib.optionalString withSfsexp ''
175 cp notmuch-git $out/bin/notmuch-git
176 wrapProgram $out/bin/notmuch-git --prefix PATH : $out/bin:${lib.getBin git}/bin
177 ''
178 + lib.optionalString withVim ''
179 make -C vim DESTDIR="$vim/share/vim-plugins/notmuch" prefix="" install
180 mkdir -p $vim/share/nvim
181 ln -s $vim/share/vim-plugins/notmuch $vim/share/nvim/site
182 ''
183 + lib.optionalString (withVim && withRuby) ''
184 PLUG=$vim/share/vim-plugins/notmuch/plugin/notmuch.vim
185 cat >> $PLUG << EOF
186 let \$GEM_PATH=\$GEM_PATH . ":${finalAttrs.passthru.gemEnv}/${ruby.gemPath}"
187 let \$RUBYLIB=\$RUBYLIB . ":$out/${ruby.libPath}/${ruby.system}"
188 if has('nvim')
189 EOF
190 for gem in ${finalAttrs.passthru.gemEnv}/${ruby.gemPath}/gems/*/lib; do
191 echo "ruby \$LOAD_PATH.unshift('$gem')" >> $PLUG
192 done
193 echo 'endif' >> $PLUG
194 '';
195
196 passthru = {
197 pythonSourceRoot = "notmuch-${finalAttrs.version}/contrib/python-legacy";
198 gemEnv = buildEnv {
199 name = "notmuch-vim-gems";
200 paths = with ruby.gems; [ mail ];
201 pathsToLink = [
202 "/lib"
203 "/nix-support"
204 ];
205 };
206 tests.version = testers.testVersion { package = finalAttrs.finalPackage; };
207
208 updateScript = gitUpdater {
209 url = "https://git.notmuchmail.org/git/notmuch";
210 ignoredVersions = "_(rc|pre).*";
211 };
212 };
213
214 meta = {
215 description = "Mail indexer";
216 homepage = "https://notmuchmail.org/";
217 changelog = "https://git.notmuchmail.org/git?p=notmuch;a=blob_plain;f=NEWS;hb=${finalAttrs.version}";
218 license = lib.licenses.gpl3Plus;
219 maintainers = with lib.maintainers; [
220 flokli
221 puckipedia
222 ];
223 platforms = lib.platforms.unix;
224 mainProgram = "notmuch";
225 };
226})