overlay/modules/mealie.nix

78 lines
2.4 KiB
Nix
Raw Normal View History

2024-01-09 23:33:04 +00:00
{ config, lib, pkgs, ...}:
let
cfg = config.services.mealie;
pkg = pkgs.mealie;
in
{
options.services.mealie = {
enable = lib.mkEnableOption "Mealie, a recipe manager and meal planner";
listen_address = lib.mkOption {
type = lib.types.str;
default = "0.0.0.0";
description = "Address on which the service should listen";
};
port = lib.mkOption {
type = lib.types.port;
default = 9000;
description = "Port on which to serve the Mealie service";
};
extraConfig = lib.mkOption {
type = lib.types.attrs;
default = {};
description = lib.mdDoc ''
Some extra configuration for the service.
See [the mealie documentation](https://nightly.mealie.io/documentation/getting-started/installation/backend-config/) for available options and default values.
'';
example = {
ALLOW_SIGNUP = "false";
};
};
credentialsFile = lib.mkOption {
type = with lib.types; nullOr path;
default = null;
example = "/run/secrets/mealie-credentials.env";
description = ''
File containing credentials used in mealie such as POSTGRES_PASSWORD
or sensitive LDAP options.
Expects the format of an EnvironmentFile=, as described by systemd.exec(5).
'';
};
};
config = lib.mkIf cfg.enable {
systemd.services.mealie = {
description = "Mealie, a self hosted recipe manager and meal planner";
after = [
"network.target"
"network-online.target"
];
wantedBy = [
"multi-user.target"
];
environment = {
PYTHONPATH = "${pkg.python3.pkgs.makePythonPath pkg.propagatedBuildInputs}:${pkg}/lib/${pkg.python3.libPrefix}/site-packages";
PRODUCTION = "true";
MEALIE_LOG_FILE = "/var/log/mealie/mealie.log";
ALEMBIC_CONFIG_FPATH="${pkg}/config/alembic.ini";
API_PORT = builtins.toString cfg.port;
} // (builtins.mapAttrs (_: val: builtins.toString val) cfg.extraConfig);
serviceConfig = {
DynamicUser = true;
User = "mealie";
ExecStartPre = "${pkg.python3.interpreter} ${pkg}/bin/init_db.py";
ExecStart = "${pkg}/bin/start-mealie -b ${cfg.listen_address}:${builtins.toString cfg.port}";
EnvironmentFile = lib.optional (cfg.credentialsFile != null) cfg.credentialsFile;
StateDirectory = "mealie";
LogsDirectory = "mealie";
};
};
};
}