Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions nixos/modules/services/misc/tandoor-recipes.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -105,6 +115,9 @@ in
systemd.services.tandoor-recipes = {
description = "Tandoor Recipes server";

requires = lib.optional cfg.database.createLocally "postgresql.service";
after = lib.optional cfg.database.createLocally "postgresql.service";

serviceConfig = {
ExecStart = ''
${pkg.python.pkgs.gunicorn}/bin/gunicorn recipes.wsgi
Expand Down Expand Up @@ -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;
}
];
};
};
}
24 changes: 1 addition & 23 deletions nixos/tests/tandoor-recipes.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,7 @@ import ./make-test-python.nix (
{
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.service" ];
};
database.createLocally = true;
};
};

Expand Down