Skip to content

Commit

Permalink
mdadm: allow sending mail when using opensmtpd
Browse files Browse the repository at this point in the history
OpenSMTPD does not require the setuid bit for its `sendmail`. This works
around it by wrapping the called `sendmail` so that the wrapper falls
back on either the setuid `sendmail` or the non-setuid `sendmail`
depending on what's available.

The solution of relying on `$PATH` to be set is unfortunately
unreliable, as `mdadm --monitor` will likely be executed from a
`systemd` unit, that runs with a clean `$PATH`.
  • Loading branch information
Ekleog authored and bjornfor committed Mar 30, 2018
1 parent 6547e61 commit ec9a51d
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions pkgs/os-specific/linux/mdadm/default.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
{ stdenv
{ stdenv, writeScript
, fetchurl, groff
, buildPlatform, hostPlatform
}:

assert stdenv.isLinux;

let
sendmail-script = writeScript "sendmail-script" ''
#!/bin/sh
if [ -x /run/wrappers/bin/sendmail ]; then
/run/wrappers/bin/sendmail "$@"
else
/run/current-system/sw/bin/sendmail "$@"
fi
'';
in
stdenv.mkDerivation rec {
name = "mdadm-4.0";

Expand All @@ -15,7 +26,7 @@ stdenv.mkDerivation rec {

# This is to avoid self-references, which causes the initrd to explode
# in size and in turn prevents mdraid systems from booting.
allowedReferences = [ stdenv.cc.libc.out ];
allowedReferences = [ stdenv.cc.libc.out sendmail-script ];

patches = [ ./no-self-references.patch ];

Expand All @@ -32,7 +43,7 @@ stdenv.mkDerivation rec {
preConfigure = ''
sed -e 's@/lib/udev@''${out}/lib/udev@' \
-e 's@ -Werror @ @' \
-e 's@/usr/sbin/sendmail@/run/wrappers/bin/sendmail@' -i Makefile
-e 's@/usr/sbin/sendmail@${sendmail-script}@' -i Makefile
'';

meta = {
Expand Down

0 comments on commit ec9a51d

Please sign in to comment.