some changes

This commit is contained in:
zack 2024-10-21 21:00:32 -04:00
parent 0fd77fa375
commit 1e560576c0
No known key found for this signature in database
GPG key ID: 5F873416BCF59F35

View file

@ -124,6 +124,11 @@
};
users.groups."zoeyscomputer-phx" = {};
# Configure PostgreSQL authentication for our user
services.postgresql.authentication = mkBefore ''
local ${cfg.phx.database.name} ${cfg.phx.database.user} scram-sha-256
'';
# Create a oneshot service to set up the database user with password
systemd.services.init-zoeyscomputer-db = {
description = "Initialize ZoeysComputer Database User";
@ -143,10 +148,10 @@
# Create user and database if they don't exist
if ! runuser -u ${config.services.postgresql.superUser} -- ${config.services.postgresql.package}/bin/psql -tAc "SELECT 1 FROM pg_roles WHERE rolname='${cfg.phx.database.user}'" | grep -q 1; then
echo "CREATE USER ${cfg.phx.database.user} WITH PASSWORD '$PASSWORD'" | \
echo "CREATE USER ${cfg.phx.database.user} WITH PASSWORD '$PASSWORD' PASSWORD_ENCRYPTION='scram-sha-256'" | \
runuser -u ${config.services.postgresql.superUser} -- ${config.services.postgresql.package}/bin/psql
else
echo "ALTER USER ${cfg.phx.database.user} WITH PASSWORD '$PASSWORD'" | \
echo "ALTER USER ${cfg.phx.database.user} WITH PASSWORD '$PASSWORD' PASSWORD_ENCRYPTION='scram-sha-256'" | \
runuser -u ${config.services.postgresql.superUser} -- ${config.services.postgresql.package}/bin/psql
fi