summary refs log tree commit diff
path: root/pkgs/servers/mail/system-sendmail/default.nix
blob: 76b92299409ecc2166df432f496a9e8e8e96f57d (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
{ lib, stdenv, writeText, runtimeShell }:

let script = writeText "script" ''
  #!${runtimeShell}

  if command -v sendmail > /dev/null 2>&1 && [ "$(command -v sendmail)" != "{{MYPATH}}" ]; then
    exec sendmail "$@"
  elif [ -x /run/wrappers/bin/sendmail ]; then
    exec /run/wrappers/bin/sendmail "$@"
  elif [ -x /run/current-system/sw/bin/sendmail ]; then
    exec /run/current-system/sw/bin/sendmail "$@"
  else
    echo "Unable to find system sendmail." >&2
    exit 1
  fi
''; in
stdenv.mkDerivation {
  pname = "system-sendmail";
  version = "1.0";

  src = script;

  dontUnpack = true;
  dontInstall = true;

  buildPhase = ''
    mkdir -p $out/bin
    < $src sed "s#{{MYPATH}}#$out/bin/sendmail#" > $out/bin/sendmail
    chmod +x $out/bin/sendmail
  '';

  meta = with lib; {
    description = ''
      A sendmail wrapper that calls the system sendmail. Do not install as system-wide sendmail!
    '';
    platforms = platforms.unix;
    maintainers = with maintainers; [ ekleog ];
  };
}