Merge pull request #49792 from griff/rspamd-multifile-enable

nixos/rspamd: Fix enable for locals and overrides
This commit is contained in:
Franz Pletz 2018-11-06 18:25:47 +00:00 committed by GitHub
commit 159a5f31bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 12 deletions

View File

@ -153,9 +153,10 @@ let
${cfg.extraConfig} ${cfg.extraConfig}
''; '';
filterFiles = files: filterAttrs (n: v: v.enable) files;
rspamdDir = pkgs.linkFarm "etc-rspamd-dir" ( rspamdDir = pkgs.linkFarm "etc-rspamd-dir" (
(mapAttrsToList (name: file: { name = "local.d/${name}"; path = file.source; }) cfg.locals) ++ (mapAttrsToList (name: file: { name = "local.d/${name}"; path = file.source; }) (filterFiles cfg.locals)) ++
(mapAttrsToList (name: file: { name = "override.d/${name}"; path = file.source; }) cfg.overrides) ++ (mapAttrsToList (name: file: { name = "override.d/${name}"; path = file.source; }) (filterFiles cfg.overrides)) ++
(optional (cfg.localLuaRules != null) { name = "rspamd.local.lua"; path = cfg.localLuaRules; }) ++ (optional (cfg.localLuaRules != null) { name = "rspamd.local.lua"; path = cfg.localLuaRules; }) ++
[ { name = "rspamd.conf"; path = rspamdConfFile; } ] [ { name = "rspamd.conf"; path = rspamdConfFile; } ]
); );
@ -207,7 +208,7 @@ in
}; };
locals = mkOption { locals = mkOption {
type = with types; loaOf (submodule (configFileModule "locals")); type = with types; attrsOf (submodule (configFileModule "locals"));
default = {}; default = {};
description = '' description = ''
Local configuration files, written into <filename>/etc/rspamd/local.d/{name}</filename>. Local configuration files, written into <filename>/etc/rspamd/local.d/{name}</filename>.
@ -220,7 +221,7 @@ in
}; };
overrides = mkOption { overrides = mkOption {
type = with types; loaOf (submodule (configFileModule "overrides")); type = with types; attrsOf (submodule (configFileModule "overrides"));
default = {}; default = {};
description = '' description = ''
Overridden configuration files, written into <filename>/etc/rspamd/override.d/{name}</filename>. Overridden configuration files, written into <filename>/etc/rspamd/override.d/{name}</filename>.

View File

@ -110,16 +110,33 @@ in
''; '';
services.rspamd = { services.rspamd = {
enable = true; enable = true;
locals."groups.conf".text = '' locals = {
group "cows" { "antivirus.conf" = mkIf false { text = ''
symbol { clamav {
NO_MUH = { action = "reject";
weight = 1.0; symbol = "CLAM_VIRUS";
description = "Mails should not muh"; type = "clamav";
log_clean = true;
servers = "/run/clamav/clamd.ctl";
}
'';};
"redis.conf" = {
enable = false;
text = ''
servers = "127.0.0.1";
'';
};
"groups.conf".text = ''
group "cows" {
symbol {
NO_MUH = {
weight = 1.0;
description = "Mails should not muh";
}
} }
} }
} '';
''; };
localLuaRules = pkgs.writeText "rspamd.local.lua" '' localLuaRules = pkgs.writeText "rspamd.local.lua" ''
local rspamd_logger = require "rspamd_logger" local rspamd_logger = require "rspamd_logger"
rspamd_config.NO_MUH = { rspamd_config.NO_MUH = {
@ -152,6 +169,10 @@ in
$machine->log($machine->succeed("cat /etc/rspamd/rspamd.conf")); $machine->log($machine->succeed("cat /etc/rspamd/rspamd.conf"));
$machine->log($machine->succeed("cat /etc/rspamd/rspamd.local.lua")); $machine->log($machine->succeed("cat /etc/rspamd/rspamd.local.lua"));
$machine->log($machine->succeed("cat /etc/rspamd/local.d/groups.conf")); $machine->log($machine->succeed("cat /etc/rspamd/local.d/groups.conf"));
# Verify that redis.conf was not written
$machine->fail("cat /etc/rspamd/local.d/redis.conf >&2");
# Verify that antivirus.conf was not written
$machine->fail("cat /etc/rspamd/local.d/antivirus.conf >&2");
${checkSocket "/run/rspamd/rspamd.sock" "rspamd" "rspamd" "660" } ${checkSocket "/run/rspamd/rspamd.sock" "rspamd" "rspamd" "660" }
$machine->log($machine->succeed("curl --unix-socket /run/rspamd/rspamd.sock http://localhost/ping")); $machine->log($machine->succeed("curl --unix-socket /run/rspamd/rspamd.sock http://localhost/ping"));
$machine->log($machine->succeed("rspamc -h 127.0.0.1:11334 stat")); $machine->log($machine->succeed("rspamc -h 127.0.0.1:11334 stat"));