Skip to content

Commit

Permalink
django: use postgresql unix sockets
Browse files Browse the repository at this point in the history
  • Loading branch information
domenkozar committed Apr 9, 2024
1 parent c7851e1 commit 3c84a0f
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions examples/python-django/devenv.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

let
db_user = "postgres";
db_host = "localhost";
db_port = "5432";
db_name = "db";
in
{
Expand All @@ -13,25 +11,28 @@ in
poetry.enable = true;
};

# To load secrets like SECRET_KEY from .env
# dotenv.enable = true;

env = {
DATABASE_URL = "postgres://${db_user}@/${db_name}?host=${config.env.PGHOST}";
DATABASE_URL = "postgres://${db_user}@${config.env.PGHOST}/${db_name}";
DEBUG = true;
SECRET_KEY = "123";
STATIC_ROOT = "/tmp";
SECRET_KEY = "supersecret";
STATIC_ROOT = config.devenv.state + "/static";
};

services.postgres = {
enable = true;
initialScript = "CREATE USER ${db_user} SUPERUSER;";
initialDatabases = [{ name = db_name; }];
listen_addresses = db_host;
};

processes.runserver.exec = "python manage.py runserver";
processes.runserver.process-compose.depends_on.postgres.condition = "process_ready";
processes.runserver = {
exec = "python manage.py runserver";
process-compose.depends_on.postgres.condition = "process_ready";
};

enterTest = ''
wait_for_port ${db_port}
python manage.py test
'';
}

0 comments on commit 3c84a0f

Please sign in to comment.