]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - flakes/private/opendmarc/flake.nix
Refactor opendmarc/openarc flakes
[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 19 cfg = name': { config, lib, pkgs, name, ... }: {
910c2e9e
IB
20 imports = [
21 (my-lib.lib.withNarKey files-watcher "nixosModule")
22 (my-lib.lib.withNarKey opendmarc "nixosModule")
23 #FIXME:
24 #(my-lib.lib.withNarKey secrets "nixosModule")
25 ];
27dd65fc
IB
26 config = lib.mkIf (name == name') {
27 users.users."${config.services.opendmarc.user}".extraGroups = [ "keys" ];
28 systemd.services.opendmarc.serviceConfig.Slice = "mail.slice";
29 services.opendmarc = {
30 enable = true;
910c2e9e 31 socket = "/run/opendmarc/opendmarc.sock";
27dd65fc
IB
32 configFile = pkgs.writeText "opendmarc.conf" ''
33 AuthservID HOSTNAME
34 FailureReports false
35 FailureReportsBcc postmaster@immae.eu
36 FailureReportsOnNone true
37 FailureReportsSentBy postmaster@immae.eu
38 IgnoreAuthenticatedClients true
39 IgnoreHosts ${config.secrets.fullPaths."opendmarc/ignore.hosts"}
40 SoftwareHeader true
41 SPFIgnoreResults true
42 SPFSelfValidate true
43 UMask 002
44 '';
45 group = config.services.postfix.group;
46 };
47 services.filesWatcher.opendmarc = {
48 restart = true;
49 paths = [
50 config.secrets.fullPaths."opendmarc/ignore.hosts"
51 ];
52 };
53 secrets.keys = [
54 {
55 dest = "opendmarc/ignore.hosts";
56 user = config.services.opendmarc.user;
57 group = config.services.opendmarc.group;
58 permissions = "0400";
59 text = let
60 mxes = lib.attrsets.filterAttrs
61 (n: v: v.mx.enable)
62 config.myEnv.servers;
63 in
64 builtins.concatStringsSep "\n" ([
65 config.myEnv.mail.dmarc.ignore_hosts
66 ] ++ lib.mapAttrsToList (n: v: v.fqdn) mxes);
67 }
ef43c362
IB
68 ];
69 };
ef43c362
IB
70 };
71 in
72 opendmarc.outputs //
5e2ec9fb 73 { nixosModules = opendmarc.nixosModules or {} // nix-lib.lib.genAttrs ["eldiron" "backup-2"] cfg; };
ef43c362
IB
74}
75