nixos/tandoor-recipes: add 'database.createLocally'

This commit is contained in:
Bruno BELANYI 2025-05-02 17:29:56 +01:00
parent 870c32abb0
commit d2741cbfb0

View File

@ -88,6 +88,16 @@ in
};
package = lib.mkPackageOption pkgs "tandoor-recipes" { };
database = {
createLocally = lib.mkOption {
type = lib.types.bool;
default = false;
description = ''
Configure local PostgreSQL database server for Tandoor Recipes.
'';
};
};
};
config = lib.mkIf cfg.enable {
@ -105,6 +115,9 @@ in
systemd.services.tandoor-recipes = {
description = "Tandoor Recipes server";
requires = lib.optional cfg.database.createLocally "postgresql.target";
after = lib.optional cfg.database.createLocally "postgresql.target";
serviceConfig = {
ExecStart = ''
${pkg.python.pkgs.gunicorn}/bin/gunicorn recipes.wsgi
@ -170,5 +183,23 @@ in
PYTHONPATH = "${pkg.python.pkgs.makePythonPath pkg.propagatedBuildInputs}:${pkg}/lib/tandoor-recipes";
};
};
services.paperless.settings = lib.mkIf cfg.database.createLocally {
DB_ENGINE = "django.db.backends.postgresql";
POSTGRES_HOST = "/run/postgresql";
POSTGRES_USER = "tandoor_recipes";
POSTGRES_DB = "tandoor_recipes";
};
services.postgresql = lib.mkIf cfg.database.createLocally {
enable = true;
ensureDatabases = [ "tandoor_recipes" ];
ensureUsers = [
{
name = "tandoor_recipes";
ensureDBOwnership = true;
}
];
};
};
}