From bd621731060762666f8549e294abdb5a5b3a00fc Mon Sep 17 00:00:00 2001 From: Felix Buehler Date: Sat, 24 Aug 2024 22:05:35 +0200 Subject: [PATCH] nixos/services.roundcube: remove `with lib;` --- nixos/modules/services/mail/roundcube.nix | 73 +++++++++++------------ 1 file changed, 35 insertions(+), 38 deletions(-) diff --git a/nixos/modules/services/mail/roundcube.nix b/nixos/modules/services/mail/roundcube.nix index 2914877bdccd..1a9a3bdf26b9 100644 --- a/nixos/modules/services/mail/roundcube.nix +++ b/nixos/modules/services/mail/roundcube.nix @@ -1,7 +1,4 @@ { lib, config, pkgs, ... }: - -with lib; - let cfg = config.services.roundcube; fpm = config.services.phpfpm.pools.roundcube; @@ -11,8 +8,8 @@ let in { options.services.roundcube = { - enable = mkOption { - type = types.bool; + enable = lib.mkOption { + type = lib.types.bool; default = false; description = '' Whether to enable roundcube. @@ -23,27 +20,27 @@ in ''; }; - hostName = mkOption { - type = types.str; + hostName = lib.mkOption { + type = lib.types.str; example = "webmail.example.com"; description = "Hostname to use for the nginx vhost"; }; - package = mkPackageOption pkgs "roundcube" { + package = lib.mkPackageOption pkgs "roundcube" { example = "roundcube.withPlugins (plugins: [ plugins.persistent_login ])"; }; database = { - username = mkOption { - type = types.str; + username = lib.mkOption { + type = lib.types.str; default = "roundcube"; description = '' Username for the postgresql connection. If `database.host` is set to `localhost`, a unix user and group of the same name will be created as well. ''; }; - host = mkOption { - type = types.str; + host = lib.mkOption { + type = lib.types.str; default = "localhost"; description = '' Host of the postgresql server. If this is not set to @@ -52,13 +49,13 @@ in permissions. ''; }; - password = mkOption { - type = types.str; + password = lib.mkOption { + type = lib.types.str; description = "Password for the postgresql connection. Do not use: the password will be stored world readable in the store; use `passwordFile` instead."; default = ""; }; - passwordFile = mkOption { - type = types.str; + passwordFile = lib.mkOption { + type = lib.types.str; description = '' Password file for the postgresql connection. Must be formatted according to PostgreSQL .pgpass standard (see https://www.postgresql.org/docs/current/libpq-pgpass.html) @@ -66,32 +63,32 @@ in Ignored if `database.host` is set to `localhost`, as peer authentication will be used. ''; }; - dbname = mkOption { - type = types.str; + dbname = lib.mkOption { + type = lib.types.str; default = "roundcube"; description = "Name of the postgresql database"; }; }; - plugins = mkOption { - type = types.listOf types.str; + plugins = lib.mkOption { + type = lib.types.listOf lib.types.str; default = []; description = '' List of roundcube plugins to enable. Currently, only those directly shipped with Roundcube are supported. ''; }; - dicts = mkOption { - type = types.listOf types.package; + dicts = lib.mkOption { + type = lib.types.listOf lib.types.package; default = []; - example = literalExpression "with pkgs.aspellDicts; [ en fr de ]"; + example = lib.literalExpression "with pkgs.aspellDicts; [ en fr de ]"; description = '' List of aspell dictionaries for spell checking. If empty, spell checking is disabled. ''; }; - maxAttachmentSize = mkOption { - type = types.int; + maxAttachmentSize = lib.mkOption { + type = lib.types.int; default = 18; apply = configuredMaxAttachmentSize: "${toString (configuredMaxAttachmentSize * 1.37)}M"; description = '' @@ -112,16 +109,16 @@ in description = "Configure nginx as a reverse proxy for roundcube."; }; - extraConfig = mkOption { - type = types.lines; + extraConfig = lib.mkOption { + type = lib.types.lines; default = ""; description = "Extra configuration for roundcube webmail instance"; }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { # backward compatibility: if password is set but not passwordFile, make one. - services.roundcube.database.passwordFile = mkIf (!localDB && cfg.database.password != "") (mkDefault ("${pkgs.writeText "roundcube-password" cfg.database.password}")); + services.roundcube.database.passwordFile = lib.mkIf (!localDB && cfg.database.password != "") (lib.mkDefault ("${pkgs.writeText "roundcube-password" cfg.database.password}")); warnings = lib.optional (!localDB && cfg.database.password != "") "services.roundcube.database.password is deprecated and insecure; use services.roundcube.database.passwordFile instead"; environment.etc."roundcube/config.inc.php".text = '' @@ -139,7 +136,7 @@ in $config['db_dsnw'] = 'pgsql://${cfg.database.username}${lib.optionalString (!localDB) ":' . $password . '"}@${if localDB then "unix(/run/postgresql)" else cfg.database.host}/${cfg.database.dbname}'; $config['log_driver'] = 'syslog'; $config['max_message_size'] = '${cfg.maxAttachmentSize}'; - $config['plugins'] = [${concatMapStringsSep "," (p: "'${p}'") cfg.plugins}]; + $config['plugins'] = [${lib.concatMapStringsSep "," (p: "'${p}'") cfg.plugins}]; $config['des_key'] = file_get_contents('/var/lib/roundcube/des_key'); $config['mime_types'] = '${pkgs.nginx}/conf/mime.types'; # Roundcube uses PHP-FPM which has `PrivateTmp = true;` @@ -156,8 +153,8 @@ in enable = true; virtualHosts = { ${cfg.hostName} = { - forceSSL = mkDefault true; - enableACME = mkDefault true; + forceSSL = lib.mkDefault true; + enableACME = lib.mkDefault true; root = cfg.package; locations."/" = { index = "index.php"; @@ -201,7 +198,7 @@ in } ]; - services.postgresql = mkIf localDB { + services.postgresql = lib.mkIf localDB { enable = true; ensureDatabases = [ cfg.database.dbname ]; ensureUsers = [ { @@ -210,12 +207,12 @@ in } ]; }; - users.users.${user} = mkIf localDB { + users.users.${user} = lib.mkIf localDB { group = user; isSystemUser = true; createHome = false; }; - users.groups.${user} = mkIf localDB {}; + users.groups.${user} = lib.mkIf localDB {}; services.phpfpm.pools.roundcube = { user = if localDB then user else "nginx"; @@ -225,7 +222,7 @@ in post_max_size = ${cfg.maxAttachmentSize} upload_max_filesize = ${cfg.maxAttachmentSize} ''; - settings = mapAttrs (name: mkDefault) { + settings = lib.mapAttrs (name: lib.mkDefault) { "listen.owner" = "nginx"; "listen.group" = "nginx"; "listen.mode" = "0660"; @@ -247,8 +244,8 @@ in config.environment.etc."roundcube/config.inc.php".source ]; - systemd.services.roundcube-setup = mkMerge [ - (mkIf (cfg.database.host == "localhost") { + systemd.services.roundcube-setup = lib.mkMerge [ + (lib.mkIf (cfg.database.host == "localhost") { requires = [ "postgresql.service" ]; after = [ "postgresql.service" ]; })