1 { config, pkgs, lib, ... }:
3 cfg = config.services.schleuder;
4 settingsFormat = pkgs.formats.yaml { };
5 postfixMap = entries: lib.concatStringsSep "\n" (lib.mapAttrsToList (name: value: "${name} ${value}") entries);
6 writePostfixMap = name: entries: pkgs.writeText name (postfixMap entries);
7 configScript = pkgs.writeScript "schleuder-cfg" ''
12 --slurpfile overrides <(${pkgs.yq}/bin/yq . <${lib.escapeShellArg cfg.extraSettingsFile}) \
13 < ${settingsFormat.generate "schleuder.yml" cfg.settings} \
15 > /etc/schleuder/schleuder.yml
16 chown schleuder: /etc/schleuder/schleuder.yml
20 options.services.schleuder = {
21 enable = lib.mkEnableOption "Schleuder secure remailer";
22 enablePostfix = lib.mkEnableOption "automatic postfix integration" // { default = true; };
23 lists = lib.mkOption {
25 List of list addresses that should be handled by Schleuder.
27 Note that this is only handled by the postfix integration, and
28 the setup of the lists, their members and their keys has to be
29 performed separately via schleuder's API, using a tool such as
32 type = lib.types.listOf lib.types.str;
34 example = [ "widget-team@example.com" "security@example.com" ];
37 domains = lib.mkOption {
38 description = "Domains for which all mail should be handled by Schleuder.";
39 type = lib.types.listOf lib.types.str;
41 example = ["securelists.example.com"];
44 settings = lib.mkOption {
46 Settings for schleuder.yml.
48 Check the [example configuration](https://0xacab.org/schleuder/schleuder/blob/master/etc/schleuder.yml) for possible values.
50 type = lib.types.submodule {
51 freeformType = settingsFormat.type;
52 options.keyserver = lib.mkOption {
55 Key server from which to fetch and update keys.
57 Note that NixOS uses a different default from upstream, since the upstream default sks-keyservers.net is deprecated.
59 default = "keys.openpgp.org";
64 extraSettingsFile = lib.mkOption {
65 description = "YAML file to merge into the schleuder config at runtime. This can be used for secrets such as API keys.";
66 type = lib.types.nullOr lib.types.path;
69 listDefaults = lib.mkOption {
71 Default settings for lists (list-defaults.yml).
73 Check the [example configuration](https://0xacab.org/schleuder/schleuder/-/blob/master/etc/list-defaults.yml) for possible values.
75 type = settingsFormat.type;
79 config = lib.mkIf cfg.enable {
82 assertion = !(cfg.settings.api ? valid_api_keys);
84 services.schleuder.settings.api.valid_api_keys is set. Defining API keys via NixOS config results in them being copied to the world-readable Nix store. Please use the extraSettingsFile option to store API keys in a non-public location.
88 assertion = !(lib.any (db: db ? password) (lib.attrValues cfg.settings.database or {}));
90 A password is defined for at least one database in services.schleuder.settings.database. Defining passwords via NixOS config results in them being copied to the world-readable Nix store. Please use the extraSettingsFile option to store database passwords in a non-public location.
94 users.users.schleuder.isSystemUser = true;
95 users.users.schleuder.group = "schleuder";
96 users.groups.schleuder = {};
97 environment.systemPackages = [
100 services.postfix = lib.mkIf cfg.enablePostfix {
102 schleuder unix - n n - - pipe
103 flags=DRhu user=schleuder argv=/${pkgs.schleuder}/bin/schleuder work ''${recipient}
105 transport = lib.mkIf (cfg.lists != [ ]) (postfixMap (lib.genAttrs cfg.lists (_: "schleuder:")));
107 schleuder_destination_recipient_limit = 1
109 # review: does this make sense?
110 localRecipients = lib.mkIf (cfg.lists != [ ]) cfg.lists;
112 systemd.services = let commonServiceConfig = {
113 # We would have liked to use DynamicUser, but since the default
114 # database is SQLite and lives in StateDirectory, and that same
115 # database needs to be readable from the postfix service, this
116 # isn't trivial to do.
118 StateDirectory = "schleuder";
119 StateDirectoryMode = "0700";
123 serviceConfig = commonServiceConfig // {
124 ExecStartPre = lib.mkIf (cfg.extraSettingsFile != null) [
127 ExecStart = [ "${pkgs.schleuder}/bin/schleuder install" ];
131 schleuder-api-daemon = {
132 after = [ "local-fs.target" "network.target" "schleuder-init.service" ];
133 wantedBy = [ "multi-user.target" ];
134 requires = [ "schleuder-init.service" ];
135 serviceConfig = commonServiceConfig // {
136 ExecStart = [ "${pkgs.schleuder}/bin/schleuder-api-daemon" ];
139 schleuder-weekly-key-maintenance = {
140 after = [ "local-fs.target" "network.target" ];
142 serviceConfig = commonServiceConfig // {
144 "${pkgs.schleuder}/bin/schleuder refresh_keys"
145 "${pkgs.schleuder}/bin/schleuder check_keys"
151 environment.etc."schleuder/schleuder.yml" = lib.mkIf (cfg.extraSettingsFile == null) {
152 source = settingsFormat.generate "schleuder.yml" cfg.settings;
154 environment.etc."schleuder/list-defaults.yml".source = settingsFormat.generate "list-defaults.yml" cfg.listDefaults;
156 services.schleuder = {
157 #lists_dir = "/var/lib/schleuder.lists";
158 settings.filters_dir = lib.mkDefault "/var/lib/schleuder/filters";
159 settings.keyword_handlers_dir = lib.mkDefault "/var/lib/schleuder/keyword_handlers";