services: mealie: use unstable module

This commit is contained in:
Antoine Martin 2024-10-21 16:56:09 +02:00
parent 5835387f06
commit 6fa6efc8bb

View file

@ -17,6 +17,8 @@
domain = config.networking.domain; domain = config.networking.domain;
hostname = config.networking.hostName; hostname = config.networking.hostName;
fqdn = "${hostname}.${domain}"; fqdn = "${hostname}.${domain}";
pkg = pkgs.unstable.mealie;
listenAddress = "127.0.0.1";
in { in {
options.my.services.mealie = let options.my.services.mealie = let
inherit (lib) types; inherit (lib) types;
@ -27,40 +29,61 @@ in {
example = 8080; example = 8080;
description = "Internal port for Mealie webapp"; description = "Internal port for Mealie webapp";
}; };
credentialsFile = lib.mkOption {
type = types.nullOr types.path;
default = null;
example = "/run/secrets/mealie-credentials.env";
description = ''
File containing credentials used in mealie such as {env}`POSTGRES_PASSWORD`
or sensitive LDAP options.
Expects the format of an `EnvironmentFile=`, as described by {manpage}`systemd.exec(5)`.
'';
};
}; };
config = mkIf cfg.enable { # FIXME(NixOS 24.11) Copy pasted from nixpkgs master module, because some needed changes weren't in stable yet.
services.mealie = { config = mkIf cfg.enable (let
enable = true; settings = {
package = pkgs.unstable.mealie; ALLOW_SIGNUP = "false";
listenAddress = "127.0.0.1"; BASE_URL = "https://mealie.${domain}";
port = cfg.port; TZ = config.time.timeZone;
settings = { # Use PostgreSQL
ALLOW_SIGNUP = "false"; DB_ENGINE = "postgres";
BASE_URL = "https://mealie.${domain}";
TZ = config.time.timeZone;
# Use PostgreSQL # Settings for Mealie 1.7+
DB_ENGINE = "postgres"; POSTGRES_URL_OVERRIDE = "postgresql://mealie:@/mealie?host=/run/postgresql";
# Settings for Mealie 1.2
#POSTGRES_USER = "mealie";
#POSTGRES_PASSWORD = "";
#POSTGRES_SERVER = "/run/postgresql";
## Pydantic and/or mealie doesn't handle the URI correctly, hijack it
## with query parameters...
#POSTGRES_DB = "mealie?host=/run/postgresql&dbname=mealie";
# Settings for Mealie 1.7+, when that gets into NixOS stable
POSTGRES_URL_OVERRIDE = "postgresql://mealie:@/mealie?host=/run/postgresql";
};
}; };
in {
systemd.services = { systemd.services = {
mealie = { mealie = {
after = ["postgresql.service"]; after = ["network-online.target" "postgresql.service"];
requires = ["postgresql.service"]; requires = ["postgresql.service"];
wants = ["network-online.target"];
wantedBy = ["multi-user.target"];
description = "Mealie, a self hosted recipe manager and meal planner";
environment =
{
PRODUCTION = "true";
API_PORT = toString cfg.port;
BASE_URL = "http://localhost:${toString cfg.port}";
DATA_DIR = "/var/lib/mealie";
CRF_MODEL_PATH = "/var/lib/mealie/model.crfmodel";
}
// (builtins.mapAttrs (_: val: toString val) settings);
serviceConfig = {
DynamicUser = true;
User = "mealie";
ExecStartPre = "${pkg}/libexec/init_db";
ExecStart = "${lib.getExe pkg} -b ${listenAddress}:${builtins.toString cfg.port}";
EnvironmentFile = lib.mkIf (cfg.credentialsFile != null) cfg.credentialsFile;
StateDirectory = "mealie";
StandardOutput = "journal";
};
}; };
}; };
@ -85,7 +108,7 @@ in {
useACMEHost = fqdn; useACMEHost = fqdn;
locations."/" = { locations."/" = {
proxyPass = "http://127.0.0.1:${toString cfg.port}/"; proxyPass = "http://${listenAddress}:${toString cfg.port}/";
proxyWebsockets = true; proxyWebsockets = true;
}; };
}; };
@ -95,5 +118,5 @@ in {
my.services.restic-backup = { my.services.restic-backup = {
paths = ["/var/lib/mealie"]; paths = ["/var/lib/mealie"];
}; };
}; });
} }