]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - flakes/private/opendmarc/flake.nix
Add filesWatcher flake
[perso/Immae/Config/Nix.git] / flakes / private / opendmarc / flake.nix
CommitLineData
ef43c362
IB
1{
2 inputs.opendmarc = {
ada96f10
IB
3 path = "../../opendmarc";
4 type = "path";
ef43c362 5 };
27dd65fc
IB
6 inputs.files-watcher = {
7 path = "../../files-watcher";
8 type = "path";
9 };
10 inputs.my-lib = {
11 path = "../../lib";
12 type = "path";
13 };
5e2ec9fb
IB
14 inputs.nix-lib.url = "github:NixOS/nixpkgs";
15
ef43c362 16 description = "Private configuration for opendmarc";
27dd65fc 17 outputs = { self, nix-lib, opendmarc, my-lib, files-watcher }:
ef43c362 18 let
27dd65fc
IB
19 cfg = name': { config, lib, pkgs, name, ... }: {
20 imports = [ (my-lib.lib.withNarKey files-watcher "nixosModule") ];
21 config = lib.mkIf (name == name') {
22 users.users."${config.services.opendmarc.user}".extraGroups = [ "keys" ];
23 systemd.services.opendmarc.serviceConfig.Slice = "mail.slice";
24 services.opendmarc = {
25 enable = true;
26 socket = "local:${config.myServices.mail.milters.sockets.opendmarc}";
27 configFile = pkgs.writeText "opendmarc.conf" ''
28 AuthservID HOSTNAME
29 FailureReports false
30 FailureReportsBcc postmaster@immae.eu
31 FailureReportsOnNone true
32 FailureReportsSentBy postmaster@immae.eu
33 IgnoreAuthenticatedClients true
34 IgnoreHosts ${config.secrets.fullPaths."opendmarc/ignore.hosts"}
35 SoftwareHeader true
36 SPFIgnoreResults true
37 SPFSelfValidate true
38 UMask 002
39 '';
40 group = config.services.postfix.group;
41 };
42 services.filesWatcher.opendmarc = {
43 restart = true;
44 paths = [
45 config.secrets.fullPaths."opendmarc/ignore.hosts"
46 ];
47 };
48 secrets.keys = [
49 {
50 dest = "opendmarc/ignore.hosts";
51 user = config.services.opendmarc.user;
52 group = config.services.opendmarc.group;
53 permissions = "0400";
54 text = let
55 mxes = lib.attrsets.filterAttrs
56 (n: v: v.mx.enable)
57 config.myEnv.servers;
58 in
59 builtins.concatStringsSep "\n" ([
60 config.myEnv.mail.dmarc.ignore_hosts
61 ] ++ lib.mapAttrsToList (n: v: v.fqdn) mxes);
62 }
ef43c362
IB
63 ];
64 };
ef43c362
IB
65 };
66 in
67 opendmarc.outputs //
5e2ec9fb 68 { nixosModules = opendmarc.nixosModules or {} // nix-lib.lib.genAttrs ["eldiron" "backup-2"] cfg; };
ef43c362
IB
69}
70