From d2741cbfb039a1c7a095f3f5738f95918ea372f6 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 2 May 2025 17:29:56 +0100 Subject: [PATCH 1/2] 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; + } + ]; + }; }; } From edbd8e3ff6615dc28f1b43788669df659ba79444 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 2 May 2025 17:30:46 +0100 Subject: [PATCH 2/2] nixosTests.tandoor-recipes: use 'database.createLocally' --- nixos/tests/tandoor-recipes.nix | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/nixos/tests/tandoor-recipes.nix b/nixos/tests/tandoor-recipes.nix index 09a803c98855..025f1b6e2774 100644 --- a/nixos/tests/tandoor-recipes.nix +++ b/nixos/tests/tandoor-recipes.nix @@ -8,29 +8,7 @@ { services.tandoor-recipes = { enable = true; - extraConfig = { - DB_ENGINE = "django.db.backends.postgresql"; - POSTGRES_HOST = "/run/postgresql"; - POSTGRES_USER = "tandoor_recipes"; - POSTGRES_DB = "tandoor_recipes"; - }; - }; - - services.postgresql = { - enable = true; - ensureDatabases = [ "tandoor_recipes" ]; - ensureUsers = [ - { - name = "tandoor_recipes"; - ensureDBOwnership = true; - } - ]; - }; - - systemd.services = { - tandoor-recipes = { - after = [ "postgresql.target" ]; - }; + database.createLocally = true; }; };