summaryrefslogtreecommitdiffstats
path: root/krebs
diff options
context:
space:
mode:
Diffstat (limited to 'krebs')
-rw-r--r--krebs/3modules/exim-retiolum.nix92
-rw-r--r--krebs/3modules/exim-smarthost.nix6
-rw-r--r--krebs/3modules/exim.nix2
-rw-r--r--krebs/3modules/syncthing.nix80
4 files changed, 141 insertions, 39 deletions
diff --git a/krebs/3modules/exim-retiolum.nix b/krebs/3modules/exim-retiolum.nix
index e08024977..118a8b2d5 100644
--- a/krebs/3modules/exim-retiolum.nix
+++ b/krebs/3modules/exim-retiolum.nix
@@ -1,15 +1,17 @@
-{ config, pkgs, lib, ... }:
-
with import <stockholm/lib>;
-let
+{ config, pkgs, lib, ... }: let
cfg = config.krebs.exim-retiolum;
- out = {
- options.krebs.exim-retiolum = api;
- config = lib.mkIf cfg.enable imp;
- };
+ # Due to improvements to the JSON notation, braces around top-level objects
+ # are not necessary^Wsupported by rspamd's parser when including files:
+ # https://github.com/rspamd/rspamd/issues/2674
+ toMostlyJSON = value:
+ assert typeOf value == "set";
+ (s: substring 1 (stringLength s - 2) s)
+ (toJSON value);
- api = {
+in {
+ options.krebs.exim-retiolum = {
enable = mkEnableOption "krebs.exim-retiolum";
local_domains = mkOption {
type = with types; listOf hostname;
@@ -28,22 +30,70 @@ let
"*.r"
];
};
+ rspamd = {
+ enable = mkEnableOption "krebs.exim-retiolum.rspamd" // {
+ default = false;
+ };
+ locals = {
+ logging = {
+ level = mkOption {
+ type = types.enum [
+ "error"
+ "warning"
+ "notice"
+ "info"
+ "debug"
+ "silent"
+ ];
+ default = "notice";
+ };
+ };
+ options = {
+ local_networks = mkOption {
+ type = types.listOf types.cidr;
+ default = [
+ config.krebs.build.host.nets.retiolum.ip4.prefix
+ config.krebs.build.host.nets.retiolum.ip6.prefix
+ ];
+ };
+ };
+ };
+ };
};
-
- imp = {
+ imports = [
+ {
+ config = lib.mkIf cfg.rspamd.enable {
+ services.rspamd.enable = true;
+ services.rspamd.locals =
+ mapAttrs'
+ (name: value: nameValuePair "${name}.inc" {
+ text = toMostlyJSON value;
+ })
+ cfg.rspamd.locals;
+ users.users.${config.krebs.exim.user.name}.extraGroups = [
+ config.services.rspamd.group
+ ];
+ };
+ }
+ ];
+ config = lib.mkIf cfg.enable {
krebs.exim = {
enable = true;
config =
# This configuration makes only sense for retiolum-enabled hosts.
# TODO modular configuration
assert config.krebs.tinc.retiolum.enable;
- ''
+ /* exim */ ''
keep_environment =
primary_hostname = ${cfg.primary_hostname}
domainlist local_domains = ${concatStringsSep ":" cfg.local_domains}
domainlist relay_to_domains = ${concatStringsSep ":" cfg.relay_to_domains}
+ ${optionalString cfg.rspamd.enable /* exim */ ''
+ spamd_address = /run/rspamd/rspamd.sock variant=rspamd
+ ''}
+
acl_smtp_rcpt = acl_check_rcpt
acl_smtp_data = acl_check_data
@@ -72,6 +122,24 @@ let
acl_check_data:
+ ${optionalString cfg.rspamd.enable /* exim */ ''
+ accept condition = ''${if eq{$interface_port}{587}}
+
+ warn remove_header = ${concatStringsSep " : " [
+ "x-spam"
+ "x-spam-report"
+ "x-spam-score"
+ ]}
+
+ warn
+ spam = nobody:true
+
+ warn
+ condition = ''${if !eq{$spam_action}{no action}}
+ add_header = X-Spam: Yes
+ add_header = X-Spam-Report: $spam_report
+ add_header = X-Spam-Score: $spam_score
+ ''}
accept
@@ -118,4 +186,4 @@ let
'';
};
};
-in out
+}
diff --git a/krebs/3modules/exim-smarthost.nix b/krebs/3modules/exim-smarthost.nix
index 5f93ae937..e988fb563 100644
--- a/krebs/3modules/exim-smarthost.nix
+++ b/krebs/3modules/exim-smarthost.nix
@@ -121,7 +121,7 @@ let
};
krebs.exim = {
enable = true;
- config = ''
+ config = /* exim */ ''
keep_environment =
primary_hostname = ${cfg.primary_hostname}
@@ -233,7 +233,7 @@ let
remote_smtp:
driver = smtp
- ${optionalString (cfg.dkim != []) (indent ''
+ ${optionalString (cfg.dkim != []) (indent /* exim */ ''
dkim_canon = relaxed
dkim_domain = $sender_address_domain
dkim_private_key = ''${lookup{$sender_address_domain}lsearch{${lsearch.dkim_private_key}}}
@@ -262,7 +262,7 @@ let
begin rewrite
begin authenticators
- ${concatStringsSep "\n" (mapAttrsToList (name: text: ''
+ ${concatStringsSep "\n" (mapAttrsToList (name: text: /* exim */ ''
${name}:
${indent text}
'') cfg.authenticators)}
diff --git a/krebs/3modules/exim.nix b/krebs/3modules/exim.nix
index cfcbbc438..83d88cb0d 100644
--- a/krebs/3modules/exim.nix
+++ b/krebs/3modules/exim.nix
@@ -37,7 +37,7 @@ in {
};
config = lib.mkIf cfg.enable {
environment = {
- etc."exim.conf".source = pkgs.writeEximConfig "exim.conf" ''
+ etc."exim.conf".source = pkgs.writeEximConfig "exim.conf" /* exim */ ''
exim_user = ${cfg.user.name}
exim_group = ${cfg.group.name}
exim_path = /run/wrappers/bin/exim
diff --git a/krebs/3modules/syncthing.nix b/krebs/3modules/syncthing.nix
index 9c6acfb0c..939c8fddf 100644
--- a/krebs/3modules/syncthing.nix
+++ b/krebs/3modules/syncthing.nix
@@ -2,40 +2,69 @@
let
- cfg = config.krebs.syncthing;
+ kcfg = config.krebs.syncthing;
+ scfg = config.services.syncthing;
devices = mapAttrsToList (name: peer: {
name = name;
deviceID = peer.id;
addresses = peer.addresses;
- }) cfg.peers;
+ }) kcfg.peers;
folders = mapAttrsToList ( _: folder: {
inherit (folder) path id type;
- devices = map (peer: { deviceId = cfg.peers.${peer}.id; }) folder.peers;
+ devices = map (peer: { deviceId = kcfg.peers.${peer}.id; }) folder.peers;
rescanIntervalS = folder.rescanInterval;
fsWatcherEnabled = folder.watch;
fsWatcherDelayS = folder.watchDelay;
+ ignoreDelete = folder.ignoreDelete;
ignorePerms = folder.ignorePerms;
- }) cfg.folders;
+ }) kcfg.folders;
getApiKey = pkgs.writeDash "getAPIKey" ''
${pkgs.libxml2}/bin/xmllint \
--xpath 'string(configuration/gui/apikey)'\
- ${config.services.syncthing.configDir}/config.xml
+ ${scfg.configDir}/config.xml
'';
updateConfig = pkgs.writeDash "merge-syncthing-config" ''
set -efu
+
+ # XXX this assumes the GUI address to be "IPv4 address and port"
+ host=${shell.escape (elemAt (splitString ":" scfg.guiAddress) 0)}
+ port=${shell.escape (elemAt (splitString ":" scfg.guiAddress) 1)}
+
# wait for service to restart
- ${pkgs.untilport}/bin/untilport localhost 8384
+ ${pkgs.untilport}/bin/untilport "$host" "$port"
+
API_KEY=$(${getApiKey})
- CFG=$(${pkgs.curl}/bin/curl -Ss -H "X-API-Key: $API_KEY" localhost:8384/rest/system/config)
- echo "$CFG" | ${pkgs.jq}/bin/jq -s '.[] as $in | $in * {
- "devices": (${builtins.toJSON devices}${optionalString (! cfg.overridePeers) " + $in.devices"}),
- "folders": (${builtins.toJSON folders}${optionalString (! cfg.overrideFolders) " + $in.folders"})
- }' | ${pkgs.curl}/bin/curl -Ss -H "X-API-Key: $API_KEY" localhost:8384/rest/system/config -d @-
- ${pkgs.curl}/bin/curl -Ss -H "X-API-Key: $API_KEY" localhost:8384/rest/system/restart -X POST
+
+ _curl() {
+ ${pkgs.curl}/bin/curl \
+ -Ss \
+ -H "X-API-Key: $API_KEY" \
+ "http://$host:$port/rest""$@"
+ }
+
+ old_config=$(_curl /system/config)
+ new_config=${shell.escape (toJSON {
+ inherit devices folders;
+ })}
+ new_config=$(${pkgs.jq}/bin/jq -en \
+ --argjson old_config "$old_config" \
+ --argjson new_config "$new_config" \
+ '
+ $old_config * $new_config
+ ${optionalString (!kcfg.overridePeers) ''
+ * { devices: $old_config.devices }
+ ''}
+ ${optionalString (!kcfg.overrideFolders) ''
+ * { folders: $old_config.folders }
+ ''}
+ '
+ )
+ echo $new_config | _curl /system/config -d @-
+ _curl /system/restart -X POST
'';
in
@@ -129,6 +158,11 @@ in
default = 10;
};
+ ignoreDelete = mkOption {
+ type = types.bool;
+ default = false;
+ };
+
ignorePerms = mkOption {
type = types.bool;
default = true;
@@ -139,19 +173,19 @@ in
};
};
- config = (mkIf cfg.enable) {
+ config = mkIf kcfg.enable {
- systemd.services.syncthing = mkIf (cfg.cert != null || cfg.key != null) {
+ systemd.services.syncthing = mkIf (kcfg.cert != null || kcfg.key != null) {
preStart = ''
- ${optionalString (cfg.cert != null) ''
- cp ${toString cfg.cert} ${config.services.syncthing.configDir}/cert.pem
- chown ${config.services.syncthing.user}:${config.services.syncthing.group} ${config.services.syncthing.configDir}/cert.pem
- chmod 400 ${config.services.syncthing.configDir}/cert.pem
+ ${optionalString (kcfg.cert != null) ''
+ cp ${toString kcfg.cert} ${scfg.configDir}/cert.pem
+ chown ${scfg.user}:${scfg.group} ${scfg.configDir}/cert.pem
+ chmod 400 ${scfg.configDir}/cert.pem
''}
- ${optionalString (cfg.key != null) ''
- cp ${toString cfg.key} ${config.services.syncthing.configDir}/key.pem
- chown ${config.services.syncthing.user}:${config.services.syncthing.group} ${config.services.syncthing.configDir}/key.pem
- chmod 400 ${config.services.syncthing.configDir}/key.pem
+ ${optionalString (kcfg.key != null) ''
+ cp ${toString kcfg.key} ${scfg.configDir}/key.pem
+ chown ${scfg.user}:${scfg.group} ${scfg.configDir}/key.pem
+ chmod 400 ${scfg.configDir}/key.pem
''}
'';
};
@@ -161,7 +195,7 @@ in
wantedBy = [ "multi-user.target" ];
serviceConfig = {
- User = config.services.syncthing.user;
+ User = scfg.user;
RemainAfterExit = true;
Type = "oneshot";
ExecStart = updateConfig;