{ lib, config, ... }: { options.services.panoramax = { database = { postgres = { enable = lib.mkOption { type = lib.types.bool; default = false; description = "Use PostgreSQL instead of SQLite"; }; user = lib.mkOption { type = lib.types.str; default = "panoramax"; description = "Database user name"; }; database = lib.mkOption { type = lib.types.str; default = "panoramax"; description = "Database name"; }; }; }; }; config = lib.mkIf config.services.panoramax.enable { assertions = [ { assertion = !config.services.panoramax.database.postgres.enable || config.services.postgresql.enable; message = "PostgreSQL must be enabled when using postgres database for Panoramax"; } ]; services.postgresql.databases.panoramax = lib.mkIf config.services.panoramax.database.postgres.enable { enable = true; user = config.services.panoramax.database.postgres.user; database = config.services.panoramax.database.postgres.database; }; systemd.services.panoramax = lib.mkIf config.services.panoramax.database.postgres.enable { requires = [ config.systemd.services.postgresql.name ]; }; }; }