1{
2 resholve,
3 stdenv,
4 symlinkJoin,
5 lib,
6 fetchFromGitHub,
7 autoreconfHook,
8 pkg-config,
9 bash,
10 coreutils,
11 gnugrep,
12 gnused,
13 gnutls,
14 gsasl,
15 libidn2,
16 netcat-gnu,
17 texinfo,
18 which,
19 withKeyring ? true,
20 libsecret,
21 withSystemd ? lib.meta.availableOn stdenv.hostPlatform systemd,
22 systemd,
23 withScripts ? true,
24 withLibnotify ? true,
25 libnotify,
26 gitUpdater,
27 binlore,
28 msmtp,
29}:
30
31let
32 inherit (lib) getBin getExe optionals;
33
34 version = "1.8.30";
35
36 src = fetchFromGitHub {
37 owner = "marlam";
38 repo = "msmtp";
39 rev = "msmtp-${version}";
40 hash = "sha256-aM2qId08zvT9LbncCQYHsklbvHVtcZJgr91JTjwpQ/0=";
41 };
42
43 meta = with lib; {
44 description = "Simple and easy to use SMTP client with excellent sendmail compatibility";
45 homepage = "https://marlam.de/msmtp/";
46 license = licenses.gpl3Plus;
47 maintainers = with maintainers; [ peterhoeg ];
48 platforms = platforms.unix;
49 mainProgram = "msmtp";
50 };
51
52 binaries = stdenv.mkDerivation {
53 pname = "msmtp-binaries";
54 inherit version src meta;
55
56 configureFlags = [
57 "--sysconfdir=/etc"
58 "--with-libgsasl"
59 ]
60 ++ optionals stdenv.hostPlatform.isDarwin [ "--with-macosx-keyring" ];
61
62 buildInputs = [
63 gnutls
64 gsasl
65 libidn2
66 ]
67 ++ optionals withKeyring [ libsecret ];
68
69 nativeBuildInputs = [
70 autoreconfHook
71 pkg-config
72 texinfo
73 ];
74
75 enableParallelBuilding = true;
76
77 postInstall = ''
78 install -Dm444 -t $out/share/doc/msmtp doc/*.example
79 ln -s msmtp $out/bin/sendmail
80 '';
81 };
82
83 scripts = resholve.mkDerivation {
84 pname = "msmtp-scripts";
85 inherit version src meta;
86
87 patches = [
88 ./msmtpq-remove-binary-check.patch
89 ./msmtpq-systemd-logging.patch
90 ];
91
92 postPatch = ''
93 substituteInPlace scripts/msmtpq/msmtpq \
94 --replace @journal@ ${if withSystemd then "Y" else "N"}
95 '';
96
97 dontConfigure = true;
98 dontBuild = true;
99
100 installPhase = ''
101 runHook preInstall
102
103 install -Dm555 -t $out/bin scripts/msmtpq/msmtp*
104 install -Dm444 -t $out/share/doc/msmtp/scripts scripts/msmtpq/README*
105 install -Dm444 -t $out/share/doc/msmtp/scripts scripts/{find_alias,msmtpqueue,set_sendmail}/*
106
107 if grep --quiet -E '@.+@' $out/bin/*; then
108 echo "Unsubstituted variables found. Aborting!"
109 grep -E '@.+@' $out/bin/*
110 exit 1
111 fi
112
113 runHook postInstall
114 '';
115
116 solutions = {
117 msmtpq = {
118 scripts = [ "bin/msmtpq" ];
119 interpreter = getExe bash;
120 inputs = [
121 binaries
122 coreutils
123 gnugrep
124 gnused
125 netcat-gnu
126 which
127 ]
128 ++ optionals withSystemd [ systemd ]
129 ++ optionals withLibnotify [ libnotify ];
130 execer = [
131 "cannot:${getBin binaries}/bin/msmtp"
132 "cannot:${getBin netcat-gnu}/bin/nc"
133 ]
134 ++ optionals withSystemd [
135 "cannot:${getBin systemd}/bin/systemd-cat"
136 ]
137 ++ optionals withLibnotify [
138 "cannot:${getBin libnotify}/bin/notify-send"
139 ];
140 fix."$MSMTP" = [ "msmtp" ];
141 fake.external = [
142 "ping"
143 ]
144 ++ optionals (!withSystemd) [ "systemd-cat" ]
145 ++ optionals (!withLibnotify) [ "notify-send" ];
146 keep.source = [ "~/.msmtpqrc" ];
147 };
148
149 msmtp-queue = {
150 scripts = [ "bin/msmtp-queue" ];
151 interpreter = getExe bash;
152 inputs = [ "${placeholder "out"}/bin" ];
153 execer = [ "cannot:${placeholder "out"}/bin/msmtpq" ];
154 };
155 };
156 };
157
158in
159if withScripts then
160 symlinkJoin {
161 name = "msmtp-${version}";
162 inherit version meta;
163 paths = [
164 binaries
165 scripts
166 ];
167 passthru = {
168 inherit binaries scripts src;
169 # msmtpq forwards most of its arguments to msmtp [1].
170 #
171 # [1]: <https://github.com/marlam/msmtp/blob/msmtp-1.8.26/scripts/msmtpq/msmtpq#L301>
172 binlore.out = binlore.synthesize msmtp ''
173 wrapper bin/msmtpq bin/msmtp
174 '';
175 updateScript = gitUpdater { rev-prefix = "msmtp-"; };
176 };
177 }
178else
179 binaries