11 cfg = config.services.peroxide;
12 settingsFormat = pkgs.formats.yaml { };
13 stateDir = "peroxide";
16 options.services.peroxide = {
17 enable = mkEnableOption "peroxide";
19 package = mkPackageOption pkgs "peroxide" {
20 default = [ "peroxide" ];
24 # https://github.com/sirupsen/logrus#level-logging
36 description = "Only log messages of this priority or higher.";
40 type = types.submodule {
41 freeformType = settingsFormat.type;
44 UserPortImap = mkOption {
47 description = "The port on which to listen for IMAP connections.";
50 UserPortSmtp = mkOption {
53 description = "The port on which to listen for SMTP connections.";
56 ServerAddress = mkOption {
59 example = "localhost";
60 description = "The address on which to listen for connections.";
66 Configuration for peroxide. See
67 [config.example.yaml](https://github.com/ljanyst/peroxide/blob/master/config.example.yaml)
68 for an example configuration.
73 config = mkIf cfg.enable {
74 services.peroxide.settings = {
75 # peroxide deletes the cache directory on startup, which requires write
76 # permission on the parent directory, so we can't use
78 CacheDir = "/var/cache/peroxide/cache";
79 X509Key = mkDefault "/var/lib/${stateDir}/key.pem";
80 X509Cert = mkDefault "/var/lib/${stateDir}/cert.pem";
81 CookieJar = "/var/lib/${stateDir}/cookies.json";
82 CredentialsStore = "/var/lib/${stateDir}/credentials.json";
85 users.users.peroxide = {
89 users.groups.peroxide = { };
91 systemd.services.peroxide = {
92 description = "Peroxide ProtonMail bridge";
93 requires = [ "network.target" ];
94 after = [ "network.target" ];
95 wantedBy = [ "multi-user.target" ];
97 restartTriggers = [ config.environment.etc."peroxide.conf".source ];
102 LogsDirectory = "peroxide";
103 LogsDirectoryMode = "0750";
104 # Specify just "peroxide" so that the user has write permission, because
105 # peroxide deletes and recreates the cache directory on startup.
110 CacheDirectoryMode = "0700";
111 StateDirectory = stateDir;
112 StateDirectoryMode = "0700";
113 ExecStart = "${cfg.package}/bin/peroxide -log-file=/var/log/peroxide/peroxide.log -log-level ${cfg.logLevel}";
114 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
118 # Create a self-signed certificate if no certificate exists.
119 if [[ ! -e "${cfg.settings.X509Key}" && ! -e "${cfg.settings.X509Cert}" ]]; then
120 ${cfg.package}/bin/peroxide-cfg -action gen-x509 \
123 -x509-cert "${cfg.settings.X509Cert}" \
124 -x509-key "${cfg.settings.X509Key}"
129 # https://github.com/ljanyst/peroxide/blob/master/peroxide.logrotate
130 services.logrotate.settings.peroxide = {
131 files = "/var/log/peroxide/peroxide.log";
135 delaycompress = true;
138 su = "peroxide peroxide";
139 postrotate = "systemctl reload peroxide";
142 environment.etc."peroxide.conf".source = settingsFormat.generate "peroxide.conf" cfg.settings;
143 environment.systemPackages = [ cfg.package ];
146 meta.maintainers = with maintainers; [