+ extraAliases = let
+ toScript = 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
+ '';
+ scripts = lib.attrsets.mapAttrs (n: v:
+ toScript n (
+ (builtins.getFlake "git+${v.src.url}?rev=${v.src.rev}"
+ #(builtins.fetchGit { url = v.src.url; ref = "master"; rev = v.src.rev; })
+ ).outputs.envToScript.x86_64-linux
+ config.secrets.fullPaths."postfix/scripts/${n}-env"
+ )
+ ) config.myEnv.mail.scripts // {
+ testmail = pkgs.writeScript "testmail" ''
+ #! ${pkgs.stdenv.shell}
+ ${pkgs.coreutils}/bin/touch \
+ "/var/lib/naemon/checks/email/$(${pkgs.procmail}/bin/formail -x To: | ${pkgs.coreutils}/bin/tr -d ' <>')"
+ '';
+ };
+ in builtins.concatStringsSep "\n" (lib.attrsets.mapAttrsToList (n: v: ''${n}: "|${v}"'') scripts);