mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-14 06:00:33 +03:00
nixos/postfixadmin: format with nixfmt-rfc-style
This commit is contained in:
parent
e318dabd63
commit
c0c3fa6a78
1 changed files with 50 additions and 37 deletions
|
@ -1,4 +1,9 @@
|
||||||
{ lib, config, pkgs, ... }:
|
{
|
||||||
|
lib,
|
||||||
|
config,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
let
|
let
|
||||||
cfg = config.services.postfixadmin;
|
cfg = config.services.postfixadmin;
|
||||||
fpm = config.services.phpfpm.pools.postfixadmin;
|
fpm = config.services.phpfpm.pools.postfixadmin;
|
||||||
|
@ -89,7 +94,9 @@ 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}'"};
|
||||||
${lib.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;
|
||||||
|
|
||||||
|
@ -126,55 +133,61 @@ in
|
||||||
|
|
||||||
services.postgresql = lib.mkIf localDB {
|
services.postgresql = lib.mkIf localDB {
|
||||||
enable = true;
|
enable = true;
|
||||||
ensureUsers = [ {
|
ensureUsers = [
|
||||||
name = cfg.database.username;
|
{
|
||||||
} ];
|
name = cfg.database.username;
|
||||||
|
}
|
||||||
|
];
|
||||||
};
|
};
|
||||||
# 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 lib.mkIf localDB {
|
systemd.services.postfixadmin-postgres =
|
||||||
after = [ "postgresql.service" ];
|
let
|
||||||
bindsTo = [ "postgresql.service" ];
|
pgsql = config.services.postgresql;
|
||||||
wantedBy = [ "multi-user.target" ];
|
in
|
||||||
path = [
|
lib.mkIf localDB {
|
||||||
pgsql.package
|
after = [ "postgresql.service" ];
|
||||||
pkgs.util-linux
|
bindsTo = [ "postgresql.service" ];
|
||||||
];
|
wantedBy = [ "multi-user.target" ];
|
||||||
script = ''
|
path = [
|
||||||
set -eu
|
pgsql.package
|
||||||
|
pkgs.util-linux
|
||||||
|
];
|
||||||
|
script = ''
|
||||||
|
set -eu
|
||||||
|
|
||||||
PSQL() {
|
PSQL() {
|
||||||
psql --port=${toString pgsql.port} "$@"
|
psql --port=${toString pgsql.port} "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
PSQL -tAc "SELECT 1 FROM pg_database WHERE datname = '${cfg.database.dbname}'" | grep -q 1 || PSQL -tAc 'CREATE DATABASE "${cfg.database.dbname}" OWNER "${cfg.database.username}"'
|
PSQL -tAc "SELECT 1 FROM pg_database WHERE datname = '${cfg.database.dbname}'" | grep -q 1 || PSQL -tAc 'CREATE DATABASE "${cfg.database.dbname}" OWNER "${cfg.database.username}"'
|
||||||
current_owner=$(PSQL -tAc "SELECT pg_catalog.pg_get_userbyid(datdba) FROM pg_catalog.pg_database WHERE datname = '${cfg.database.dbname}'")
|
current_owner=$(PSQL -tAc "SELECT pg_catalog.pg_get_userbyid(datdba) FROM pg_catalog.pg_database WHERE datname = '${cfg.database.dbname}'")
|
||||||
if [[ "$current_owner" != "${cfg.database.username}" ]]; then
|
if [[ "$current_owner" != "${cfg.database.username}" ]]; then
|
||||||
PSQL -tAc 'ALTER DATABASE "${cfg.database.dbname}" OWNER TO "${cfg.database.username}"'
|
PSQL -tAc 'ALTER DATABASE "${cfg.database.dbname}" OWNER TO "${cfg.database.username}"'
|
||||||
if [[ -e "${config.services.postgresql.dataDir}/.reassigning_${cfg.database.dbname}" ]]; then
|
if [[ -e "${config.services.postgresql.dataDir}/.reassigning_${cfg.database.dbname}" ]]; then
|
||||||
echo "Reassigning ownership of database ${cfg.database.dbname} to user ${cfg.database.username} failed on last boot. Failing..."
|
echo "Reassigning ownership of database ${cfg.database.dbname} to user ${cfg.database.username} failed on last boot. Failing..."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
touch "${config.services.postgresql.dataDir}/.reassigning_${cfg.database.dbname}"
|
touch "${config.services.postgresql.dataDir}/.reassigning_${cfg.database.dbname}"
|
||||||
PSQL "${cfg.database.dbname}" -tAc "REASSIGN OWNED BY \"$current_owner\" TO \"${cfg.database.username}\""
|
PSQL "${cfg.database.dbname}" -tAc "REASSIGN OWNED BY \"$current_owner\" TO \"${cfg.database.username}\""
|
||||||
rm "${config.services.postgresql.dataDir}/.reassigning_${cfg.database.dbname}"
|
rm "${config.services.postgresql.dataDir}/.reassigning_${cfg.database.dbname}"
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
|
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
User = pgsql.superUser;
|
User = pgsql.superUser;
|
||||||
Type = "oneshot";
|
Type = "oneshot";
|
||||||
RemainAfterExit = true;
|
RemainAfterExit = true;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
|
||||||
|
|
||||||
users.users.${user} = lib.mkIf localDB {
|
users.users.${user} = lib.mkIf localDB {
|
||||||
group = user;
|
group = user;
|
||||||
isSystemUser = true;
|
isSystemUser = true;
|
||||||
createHome = false;
|
createHome = false;
|
||||||
};
|
};
|
||||||
users.groups.${user} = lib.mkIf localDB {};
|
users.groups.${user} = lib.mkIf localDB { };
|
||||||
|
|
||||||
services.phpfpm.pools.postfixadmin = {
|
services.phpfpm.pools.postfixadmin = {
|
||||||
user = user;
|
user = user;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue