Skip to content

nixos/mealie: add 'database.createLocally' #403670

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

Merged
merged 2 commits into from
May 6, 2025
Merged
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
29 changes: 28 additions & 1 deletion nixos/modules/services/web-apps/mealie.nix
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,24 @@ in
Expects the format of an `EnvironmentFile=`, as described by {manpage}`systemd.exec(5)`.
'';
};

database = {
createLocally = lib.mkOption {
type = lib.types.bool;
default = false;
description = ''
Configure local PostgreSQL database server for Mealie.
'';
};
};
};

config = lib.mkIf cfg.enable {
systemd.services.mealie = {
description = "Mealie, a self hosted recipe manager and meal planner";

after = [ "network-online.target" ];
after = [ "network-online.target" ] ++ lib.optional cfg.database.createLocally "postgresql.service";
requires = lib.optional cfg.database.createLocally "postgresql.service";
wants = [ "network-online.target" ];
wantedBy = [ "multi-user.target" ];

Expand All @@ -78,5 +89,21 @@ in
StandardOutput = "journal";
};
};

services.mealie.settings = lib.mkIf cfg.database.createLocally {
DB_ENGINE = "postgres";
POSTGRES_URL_OVERRIDE = "postgresql://mealie:@/mealie?host=/run/postgresql";
};

services.postgresql = lib.mkIf cfg.database.createLocally {
enable = true;
ensureDatabases = [ "mealie" ];
ensureUsers = [
{
name = "mealie";
ensureDBOwnership = true;
}
];
};
};
}
33 changes: 24 additions & 9 deletions nixos/tests/mealie.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,35 @@ import ./make-test-python.nix (
];
};

nodes = {
server = {
services.mealie = {
enable = true;
port = 9001;
nodes =
let
sqlite = {
services.mealie = {
enable = true;
port = 9001;
};
};
postgres = {
imports = [ sqlite ];
services.mealie.database.createLocally = true;
};
in
{
inherit sqlite postgres;
};
};

testScript = ''
start_all()
server.wait_for_unit("mealie.service")
server.wait_for_open_port(9001)
server.succeed("curl --fail http://localhost:9001")

def test_mealie(node):
node.wait_for_unit("mealie.service")
node.wait_for_open_port(9001)
node.succeed("curl --fail http://localhost:9001")

test_mealie(sqlite)
simple.send_monitor_command("quit")
simple.wait_for_shutdown()
test_mealie(postgres)
'';
}
)