From d2741cbfb039a1c7a095f3f5738f95918ea372f6 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 2 May 2025 17:29:56 +0100 Subject: [PATCH] nixos/tandoor-recipes: add 'database.createLocally' --- .../modules/services/misc/tandoor-recipes.nix | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/nixos/modules/services/misc/tandoor-recipes.nix b/nixos/modules/services/misc/tandoor-recipes.nix index 8f1cb4cbadde..6984b1ea7949 100644 --- a/nixos/modules/services/misc/tandoor-recipes.nix +++ b/nixos/modules/services/misc/tandoor-recipes.nix @@ -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; + } + ]; + }; }; }