nixos/roundcube: only configure postgres config if localhost is used as database
When using a different database, the evaluation fails as `config.services.postgresql.package` is only set if `services.postgresql` is enabled. Also, the systemd service shouldn't have a relation to postgres if a remote database is used.
This commit is contained in:
parent
92e5745383
commit
6b6348eaba
@ -141,27 +141,31 @@ in
|
|||||||
|
|
||||||
systemd.services.roundcube-setup = let
|
systemd.services.roundcube-setup = let
|
||||||
pgSuperUser = config.services.postgresql.superUser;
|
pgSuperUser = config.services.postgresql.superUser;
|
||||||
in {
|
in mkMerge [
|
||||||
requires = [ "postgresql.service" ];
|
(mkIf (cfg.database.host == "localhost") {
|
||||||
after = [ "postgresql.service" ];
|
requires = [ "postgresql.service" ];
|
||||||
wantedBy = [ "multi-user.target" ];
|
after = [ "postgresql.service" ];
|
||||||
path = [ config.services.postgresql.package ];
|
path = [ config.services.postgresql.package ];
|
||||||
script = ''
|
})
|
||||||
mkdir -p /var/lib/roundcube
|
{
|
||||||
if [ ! -f /var/lib/roundcube/db-created ]; then
|
wantedBy = [ "multi-user.target" ];
|
||||||
if [ "${cfg.database.host}" = "localhost" ]; then
|
script = ''
|
||||||
${pkgs.sudo}/bin/sudo -u ${pgSuperUser} psql postgres -c "create role ${cfg.database.username} with login password '${cfg.database.password}'";
|
mkdir -p /var/lib/roundcube
|
||||||
${pkgs.sudo}/bin/sudo -u ${pgSuperUser} psql postgres -c "create database ${cfg.database.dbname} with owner ${cfg.database.username}";
|
if [ ! -f /var/lib/roundcube/db-created ]; then
|
||||||
|
if [ "${cfg.database.host}" = "localhost" ]; then
|
||||||
|
${pkgs.sudo}/bin/sudo -u ${pgSuperUser} psql postgres -c "create role ${cfg.database.username} with login password '${cfg.database.password}'";
|
||||||
|
${pkgs.sudo}/bin/sudo -u ${pgSuperUser} psql postgres -c "create database ${cfg.database.dbname} with owner ${cfg.database.username}";
|
||||||
|
fi
|
||||||
|
PGPASSWORD=${cfg.database.password} ${pkgs.postgresql}/bin/psql -U ${cfg.database.username} \
|
||||||
|
-f ${cfg.package}/SQL/postgres.initial.sql \
|
||||||
|
-h ${cfg.database.host} ${cfg.database.dbname}
|
||||||
|
touch /var/lib/roundcube/db-created
|
||||||
fi
|
fi
|
||||||
PGPASSWORD=${cfg.database.password} ${pkgs.postgresql}/bin/psql -U ${cfg.database.username} \
|
|
||||||
-f ${cfg.package}/SQL/postgres.initial.sql \
|
|
||||||
-h ${cfg.database.host} ${cfg.database.dbname}
|
|
||||||
touch /var/lib/roundcube/db-created
|
|
||||||
fi
|
|
||||||
|
|
||||||
${pkgs.php}/bin/php ${cfg.package}/bin/update.sh
|
${pkgs.php}/bin/php ${cfg.package}/bin/update.sh
|
||||||
'';
|
'';
|
||||||
serviceConfig.Type = "oneshot";
|
serviceConfig.Type = "oneshot";
|
||||||
};
|
}
|
||||||
|
];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user