9 cfg = config.services.automx2;
10 format = pkgs.formats.json { };
15 enable = lib.mkEnableOption "automx2";
17 package = lib.mkPackageOption pkgs [
22 domain = lib.mkOption {
24 example = "example.com";
26 E-Mail-Domain for which mail client autoconfig/autoconfigure should be set up.
27 The `autoconfig` and `autodiscover` subdomains are automatically prepended and set up with ACME.
28 The names of those domains are hardcoded in the mail clients and are not configurable.
33 type = lib.types.port;
35 description = "Port used by automx2.";
38 settings = lib.mkOption {
39 inherit (format) type;
41 Bootstrap json to populate database.
42 See [docs](https://rseichter.github.io/automx2/#_sqlite) for details.
48 config = lib.mkIf cfg.enable {
52 "autoconfig.${cfg.domain}" = {
55 serverAliases = [ "autodiscover.${cfg.domain}" ];
57 "/".proxyPass = "http://127.0.0.1:${toString cfg.port}/";
58 "/initdb".extraConfig = ''
59 # Limit access to clients connecting from localhost
68 systemd.services.automx2 = {
69 after = [ "network.target" ];
72 ${lib.getExe pkgs.curl} -X POST --json @${format.generate "automx2.json" cfg.settings} http://127.0.0.1:${toString cfg.port}/initdb/
76 "AUTOMX2_CONF=${pkgs.writeText "automx2-conf" ''
79 db_uri = sqlite:///:memory:
82 "FLASK_APP=automx2.server:app"
83 "FLASK_CONFIG=production"
86 pkgs.python3.buildEnv.override { extraLibs = [ cfg.package ]; }
87 }/bin/flask run --host=127.0.0.1 --port=${toString cfg.port}";
89 StateDirectory = "automx2";
91 WorkingDirectory = "/var/lib/automx2";
94 Description = "MUA configuration service";
95 Documentation = "https://rseichter.github.io/automx2/";
97 wantedBy = [ "multi-user.target" ];
101 groups.automx2 = { };