aboutsummaryrefslogtreecommitdiff
path: root/flakes/private/opendmarc/flake.nix
blob: 7e9e8eb4d5ea117eee2710c0ba94e502ea67af6b (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
{
  inputs.opendmarc.url = "path:../../opendmarc";
  inputs.environment.url = "path:../environment";
  inputs.secrets.url = "path:../../secrets";
  inputs.files-watcher.url = "path:../../files-watcher";

  description = "Private configuration for opendmarc";
  outputs = { self, environment, opendmarc, files-watcher, secrets }: {
    nixosModule = self.nixosModules.opendmarc;
    nixosModules.opendmarc = { config, lib, pkgs, ... }: {
      imports = [
        environment.nixosModule
        files-watcher.nixosModule
        opendmarc.nixosModule
        secrets.nixosModule
      ];
      config = {
        users.users."${config.services.opendmarc.user}".extraGroups = [ "keys" ];
        systemd.services.opendmarc.serviceConfig.Slice = "mail.slice";
        services.opendmarc = {
          enable = true;
          socket = "/run/opendmarc/opendmarc.sock";
          configFile = pkgs.writeText "opendmarc.conf" ''
            AuthservID                  HOSTNAME
            FailureReports              false
            FailureReportsBcc           postmaster@immae.eu
            FailureReportsOnNone        true
            FailureReportsSentBy        postmaster@immae.eu
            IgnoreAuthenticatedClients  true
            IgnoreHosts                 ${config.secrets.fullPaths."opendmarc/ignore.hosts"}
            SoftwareHeader              true
            SPFIgnoreResults            true
            SPFSelfValidate             true
            UMask                       002
            '';
          group = config.services.postfix.group;
        };
        services.filesWatcher.opendmarc = {
          restart = true;
          paths = [
            config.secrets.fullPaths."opendmarc/ignore.hosts"
          ];
        };
        secrets.keys = {
          "opendmarc/ignore.hosts" = {
            user = config.services.opendmarc.user;
            group = config.services.opendmarc.group;
            permissions = "0400";
            text = let
              mxes = lib.attrsets.filterAttrs
                (n: v: v.mx.enable)
                config.myEnv.servers;
              in
                builtins.concatStringsSep "\n" ([
                  config.myEnv.mail.dmarc.ignore_hosts
                ] ++ lib.mapAttrsToList (n: v: v.fqdn) mxes);
          };
        };
      };
    };
  };
}