ctucx.git: nixfiles

ctucx' nixfiles

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 
{ pkgs, lib, config, ... }:

{

  options.services.email-notify.enable = lib.mkEnableOption "Enable a service which can be used to send emails";

  config = lib.mkIf config.services.email-notify.enable {
    age.secrets.password-leah-at-f2k1-de.file = ../../secrets/passwords/leah-at-f2k1-de.age;

    programs.msmtp = {
      enable      = true;
      setSendmail = false;
      accounts    = {
        default = {
          auth         = true;
          tls          = true;
          host         = "rx300.kunbox.net";
          port         = 587;
          user         = "leah@f2k1.de";
          from         = "${config.networking.fqdn} <leah@f2k1.de>";
          passwordeval = "cat ${config.age.secrets.password-leah-at-f2k1-de.path}";
        };
      };
    };

    systemd.services."email-notify@" = {
      serviceConfig = {
        ExecStart = ''
          ${pkgs.runtimeShell} -c "{ echo -n 'Subject:[${config.networking.fqdn}] Service failed: %i\n\n' &  ${pkgs.systemd}/bin/systemctl status %i;} | ${pkgs.msmtp}/bin/msmtp -v notify@ctu.cx"
        '';
      };
    };
  };

}