aboutsummaryrefslogtreecommitdiff
path: root/flakes/mypackages/lib/default.nix
blob: 972ace00daf6c07d4cc385368ad1467be3ab20f9 (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
{
  flakePartsAddPerSystem = import ./flake-parts-lib.nix;
  nodeEnv = import ./node-env.nix;
  postfixScript = pkgs: name: script: pkgs.writeScript name ''
    #! ${pkgs.stdenv.shell}
    mail=$(${pkgs.coreutils}/bin/cat -)
    output=$(echo "$mail" | ${script} 2>&1)
    ret=$?

    if [ "$ret" != "0" ]; then
      echo "$mail" \
        | ${pkgs.procmail}/bin/formail -i "X-Return-Code: $ret" \
        | /run/wrappers/bin/sendmail -i scripts_error+${name}@mail.immae.eu

    messageId=$(echo "$mail" | ${pkgs.procmail}/bin/formail -x "Message-Id:")
    repeat=$(echo "$mail" | ${pkgs.procmail}/bin/formail -X "From:" -X "Received:")

    ${pkgs.coreutils}/bin/cat <<EOF | /run/wrappers/bin/sendmail -i scripts_error+${name}@mail.immae.eu
    $repeat
    To: scripts_error+${name}@mail.immae.eu
    Subject: Log from script error
    Content-Type: text/plain; charset="UTF-8"
    Content-Transfer-Encoding: 8bit
    References:$messageId
    MIME-Version: 1.0
    X-Return-Code: $ret

    Error code: $ret
    Output of message:
    --------------
    $output
    --------------
    EOF
    fi
  '';

}