summary refs log tree commit diff
path: root/pkgs/applications/networking/mailreaders/notmuch/default.nix
blob: f84a3367d52cf039bcf1840c86369ad7e9c85280 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
{ fetchurl, stdenv, bash, emacs, fixDarwinDylibNames
, gdb, glib, gmime, gnupg
, pkgconfig, talloc, xapian
, sphinx, python
}:

stdenv.mkDerivation rec {
  name = "notmuch-0.21";

  passthru = {
    pythonSourceRoot = "${name}/bindings/python";
  };

  src = fetchurl {
    url = "http://notmuchmail.org/releases/${name}.tar.gz";
    sha256 = "1cr53rbpkcy3pvrmhbg2gq7sjpwb0c8xd7a4zhzxbiv8s7z8yvyh";
  };

  buildInputs = [ bash emacs glib gmime gnupg pkgconfig talloc xapian sphinx python ]
    ++ stdenv.lib.optional stdenv.isDarwin fixDarwinDylibNames
    ++ stdenv.lib.optional (!stdenv.isDarwin) gdb;

  patchPhase = ''
    find test -type f -exec \
      sed -i \
        "1s_#!/usr/bin/env bash_#!${bash}/bin/bash_" \
        "{}" ";"

    for src in \
      crypto.c \
      notmuch-config.c \
      emacs/notmuch-crypto.el
    do
      substituteInPlace "$src" \
        --replace \"gpg\" \"${gnupg}/bin/gpg2\"
    done
  '';

  postInstall = ''
    make install-man
  '';

  preFixup = if stdenv.isDarwin then
    ''
      set -e

      die() {
        >&2 echo "$@"
        exit 1
      }

      prg="$out/bin/notmuch"
      lib="$(find "$out/lib" -name 'libnotmuch.?.dylib')"

      [[ -s "$prg" ]] || die "couldn't find notmuch binary"
      [[ -s "$lib" ]] || die "couldn't find libnotmuch"

      badname="$(otool -L "$prg" | awk '$1 ~ /libtalloc/ { print $1 }')"
      goodname="$(find "${talloc}/lib" -name 'libtalloc.?.?.?.dylib')"

      [[ -n "$badname" ]]  || die "couldn't find libtalloc reference in binary"
      [[ -n "$goodname" ]] || die "couldn't find libtalloc in nix store"

      echo "fixing libtalloc link in $lib"
      install_name_tool -change "$badname" "$goodname" "$lib"

      echo "fixing libtalloc link in $prg"
      install_name_tool -change "$badname" "$goodname" "$prg"
    ''
  else
    "";

  # XXX: emacs tests broken
  doCheck = false;
  checkTarget = "test";

  meta = {
    description = "Mail indexer";
    license = stdenv.lib.licenses.gpl3;
    maintainers = with stdenv.lib.maintainers; [ chaoflow garbas ];
    platforms = stdenv.lib.platforms.unix;
  };
}