1 { config, lib, pkgs, ... }:
6 cfg = config.services.peroxide;
7 settingsFormat = pkgs.formats.yaml { };
11 options.services.peroxide = {
12 enable = mkEnableOption "peroxide";
14 package = mkPackageOption pkgs "peroxide" {
15 default = [ "peroxide" ];
19 # https://github.com/sirupsen/logrus#level-logging
20 type = types.enum [ "Panic" "Fatal" "Error" "Warning" "Info" "Debug" "Trace" ];
23 description = "Only log messages of this priority or higher.";
27 type = types.submodule {
28 freeformType = settingsFormat.type;
31 UserPortImap = mkOption {
34 description = "The port on which to listen for IMAP connections.";
37 UserPortSmtp = mkOption {
40 description = "The port on which to listen for SMTP connections.";
43 ServerAddress = mkOption {
46 example = "localhost";
47 description = "The address on which to listen for connections.";
53 Configuration for peroxide. See
54 [config.example.yaml](https://github.com/ljanyst/peroxide/blob/master/config.example.yaml)
55 for an example configuration.
60 config = mkIf cfg.enable {
61 services.peroxide.settings = {
62 # peroxide deletes the cache directory on startup, which requires write
63 # permission on the parent directory, so we can't use
65 CacheDir = "/var/cache/peroxide/cache";
66 X509Key = mkDefault "/var/lib/${stateDir}/key.pem";
67 X509Cert = mkDefault "/var/lib/${stateDir}/cert.pem";
68 CookieJar = "/var/lib/${stateDir}/cookies.json";
69 CredentialsStore = "/var/lib/${stateDir}/credentials.json";
72 users.users.peroxide = {
76 users.groups.peroxide = { };
78 systemd.services.peroxide = {
79 description = "Peroxide ProtonMail bridge";
80 requires = [ "network.target" ];
81 after = [ "network.target" ];
82 wantedBy = [ "multi-user.target" ];
84 restartTriggers = [ config.environment.etc."peroxide.conf".source ];
89 LogsDirectory = "peroxide";
90 LogsDirectoryMode = "0750";
91 # Specify just "peroxide" so that the user has write permission, because
92 # peroxide deletes and recreates the cache directory on startup.
93 CacheDirectory = [ "peroxide" "peroxide/cache" ];
94 CacheDirectoryMode = "0700";
95 StateDirectory = stateDir;
96 StateDirectoryMode = "0700";
97 ExecStart = "${cfg.package}/bin/peroxide -log-file=/var/log/peroxide/peroxide.log -log-level ${cfg.logLevel}";
98 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
102 # Create a self-signed certificate if no certificate exists.
103 if [[ ! -e "${cfg.settings.X509Key}" && ! -e "${cfg.settings.X509Cert}" ]]; then
104 ${cfg.package}/bin/peroxide-cfg -action gen-x509 \
107 -x509-cert "${cfg.settings.X509Cert}" \
108 -x509-key "${cfg.settings.X509Key}"
113 # https://github.com/ljanyst/peroxide/blob/master/peroxide.logrotate
114 services.logrotate.settings.peroxide = {
115 files = "/var/log/peroxide/peroxide.log";
119 delaycompress = true;
122 su = "peroxide peroxide";
123 postrotate = "systemctl reload peroxide";
126 environment.etc."peroxide.conf".source = settingsFormat.generate "peroxide.conf" cfg.settings;
127 environment.systemPackages = [ cfg.package ];
130 meta.maintainers = with maintainers; [ aanderse aidalgol ];