0
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-07-14 06:00:33 +03:00

nixos/services.postfixadmin: remove with lib;

This commit is contained in:
Felix Buehler 2024-08-24 22:05:35 +02:00
parent 8491fdcc31
commit dae6c6c58a

View file

@ -1,7 +1,4 @@
{ lib, config, pkgs, ... }: { lib, config, pkgs, ... }:
with lib;
let let
cfg = config.services.postfixadmin; cfg = config.services.postfixadmin;
fpm = config.services.phpfpm.pools.postfixadmin; fpm = config.services.phpfpm.pools.postfixadmin;
@ -10,8 +7,8 @@ let
in in
{ {
options.services.postfixadmin = { options.services.postfixadmin = {
enable = mkOption { enable = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = false; default = false;
description = '' description = ''
Whether to enable postfixadmin. Whether to enable postfixadmin.
@ -22,14 +19,14 @@ in
''; '';
}; };
hostName = mkOption { hostName = lib.mkOption {
type = types.str; type = lib.types.str;
example = "postfixadmin.example.com"; example = "postfixadmin.example.com";
description = "Hostname to use for the nginx vhost"; description = "Hostname to use for the nginx vhost";
}; };
adminEmail = mkOption { adminEmail = lib.mkOption {
type = types.str; type = lib.types.str;
example = "postmaster@example.com"; example = "postmaster@example.com";
description = '' description = ''
Defines the Site Admin's email address. Defines the Site Admin's email address.
@ -38,8 +35,8 @@ in
''; '';
}; };
setupPasswordFile = mkOption { setupPasswordFile = lib.mkOption {
type = types.path; type = lib.types.path;
description = '' description = ''
Password file for the admin. Password file for the admin.
Generate with `php -r "echo password_hash('some password here', PASSWORD_DEFAULT);"` Generate with `php -r "echo password_hash('some password here', PASSWORD_DEFAULT);"`
@ -47,16 +44,16 @@ in
}; };
database = { database = {
username = mkOption { username = lib.mkOption {
type = types.str; type = lib.types.str;
default = "postfixadmin"; default = "postfixadmin";
description = '' description = ''
Username for the postgresql connection. 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. If `database.host` is set to `localhost`, a unix user and group of the same name will be created as well.
''; '';
}; };
host = mkOption { host = lib.mkOption {
type = types.str; type = lib.types.str;
default = "localhost"; default = "localhost";
description = '' description = ''
Host of the postgresql server. If this is not set to Host of the postgresql server. If this is not set to
@ -65,25 +62,25 @@ in
permissions. permissions.
''; '';
}; };
passwordFile = mkOption { passwordFile = lib.mkOption {
type = types.path; type = lib.types.path;
description = "Password file for the postgresql connection. Must be readable by user `nginx`."; description = "Password file for the postgresql connection. Must be readable by user `nginx`.";
}; };
dbname = mkOption { dbname = lib.mkOption {
type = types.str; type = lib.types.str;
default = "postfixadmin"; default = "postfixadmin";
description = "Name of the postgresql database"; description = "Name of the postgresql database";
}; };
}; };
extraConfig = mkOption { extraConfig = lib.mkOption {
type = types.lines; type = lib.types.lines;
default = ""; default = "";
description = "Extra configuration for the postfixadmin instance, see postfixadmin's config.inc.php for available options."; description = "Extra configuration for the postfixadmin instance, see postfixadmin's config.inc.php for available options.";
}; };
}; };
config = mkIf cfg.enable { config = lib.mkIf cfg.enable {
environment.etc."postfixadmin/config.local.php".text = '' environment.etc."postfixadmin/config.local.php".text = ''
<?php <?php
@ -91,7 +88,7 @@ in
$CONF['database_type'] = 'pgsql'; $CONF['database_type'] = 'pgsql';
$CONF['database_host'] = ${if localDB then "null" else "'${cfg.database.host}'"}; $CONF['database_host'] = ${if localDB then "null" else "'${cfg.database.host}'"};
${optionalString localDB "$CONF['database_user'] = '${cfg.database.username}';"} ${lib.optionalString localDB "$CONF['database_user'] = '${cfg.database.username}';"}
$CONF['database_password'] = ${if localDB then "'dummy'" else "file_get_contents('${cfg.database.passwordFile}')"}; $CONF['database_password'] = ${if localDB then "'dummy'" else "file_get_contents('${cfg.database.passwordFile}')"};
$CONF['database_name'] = '${cfg.database.dbname}'; $CONF['database_name'] = '${cfg.database.dbname}';
$CONF['configured'] = true; $CONF['configured'] = true;
@ -109,8 +106,8 @@ in
enable = true; enable = true;
virtualHosts = { virtualHosts = {
${cfg.hostName} = { ${cfg.hostName} = {
forceSSL = mkDefault true; forceSSL = lib.mkDefault true;
enableACME = mkDefault true; enableACME = lib.mkDefault true;
locations."/" = { locations."/" = {
root = "${pkgs.postfixadmin}/public"; root = "${pkgs.postfixadmin}/public";
index = "index.php"; index = "index.php";
@ -127,7 +124,7 @@ in
}; };
}; };
services.postgresql = mkIf localDB { services.postgresql = lib.mkIf localDB {
enable = true; enable = true;
ensureUsers = [ { ensureUsers = [ {
name = cfg.database.username; name = cfg.database.username;
@ -136,7 +133,7 @@ in
# The postgresql module doesn't currently support concepts like # The postgresql module doesn't currently support concepts like
# objects owners and extensions; for now we tack on what's needed # objects owners and extensions; for now we tack on what's needed
# here. # here.
systemd.services.postfixadmin-postgres = let pgsql = config.services.postgresql; in mkIf localDB { systemd.services.postfixadmin-postgres = let pgsql = config.services.postgresql; in lib.mkIf localDB {
after = [ "postgresql.service" ]; after = [ "postgresql.service" ];
bindsTo = [ "postgresql.service" ]; bindsTo = [ "postgresql.service" ];
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
@ -172,12 +169,12 @@ in
}; };
}; };
users.users.${user} = mkIf localDB { users.users.${user} = lib.mkIf localDB {
group = user; group = user;
isSystemUser = true; isSystemUser = true;
createHome = false; createHome = false;
}; };
users.groups.${user} = mkIf localDB {}; users.groups.${user} = lib.mkIf localDB {};
services.phpfpm.pools.postfixadmin = { services.phpfpm.pools.postfixadmin = {
user = user; user = user;
@ -186,7 +183,7 @@ in
error_log = 'stderr' error_log = 'stderr'
log_errors = on log_errors = on
''; '';
settings = mapAttrs (name: mkDefault) { settings = lib.mapAttrs (name: lib.mkDefault) {
"listen.owner" = "nginx"; "listen.owner" = "nginx";
"listen.group" = "nginx"; "listen.group" = "nginx";
"listen.mode" = "0660"; "listen.mode" = "0660";