{ config, pkgs, lib, ... }:
let
globals = import ../../config/globals.nix;
in {
  programs.msmtp = {
    enable = true;

    accounts.default = {
      host = globals.smtp.host;
      port = globals.smtp.port;
      auth = true;
      tls = true;
      tls_starttls = true;
      user = globals.smtp.user;
      passwordeval = "cat /run/secrets/proton_pass";
      from = globals.smtp.user;
    };
  };

  environment.systemPackages = [ pkgs.msmtp ];

# On place le lien symbolique dans /etc/alternatives, qui est modifiable
  systemd.tmpfiles.rules = [
    "L+ /etc/alternatives/sendmail - - - - ${pkgs.msmtp}/bin/msmtp"
      "L+ /usr/sbin/sendmail - - - - ${pkgs.msmtp}/bin/msmtp"
  ];

  environment.pathsToLink = [ "/etc/alternatives" "/usr/sbin" ];
}
