feat(librechat): add ability to define config settings in nix way

This commit is contained in:
Mohammad Rafiq 2025-05-31 14:41:13 +08:00
parent 9f6f870d6c
commit b2f596e5b1
No known key found for this signature in database
2 changed files with 105 additions and 81 deletions

View file

@ -13,6 +13,18 @@ in
enable = lib.mkEnableOption "Whether to enable the LibreChat server."; enable = lib.mkEnableOption "Whether to enable the LibreChat server.";
openFirewall = lib.mkEnableOption "Whether to open the port in the firewall."; openFirewall = lib.mkEnableOption "Whether to open the port in the firewall.";
settings = lib.mkOption {
type = lib.types.attrs;
default = { };
example = # nix
''
{
}
'';
description = "A free-form attribute set that will be written to librechat.yaml.";
};
path = lib.mkOption { path = lib.mkOption {
type = lib.types.str; type = lib.types.str;
default = "/var/lib/librechat"; default = "/var/lib/librechat";
@ -187,7 +199,14 @@ in
}; };
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable (
let
configFile = pkgs.writeTextFile {
name = "librechat.yaml";
text = lib.generators.toYAML { } cfg.settings;
};
in
{
assertions = [ assertions = [
{ {
@ -253,6 +272,7 @@ in
export JWT_SECRET=$(${pkgs.systemd}/bin/systemd-creds cat JWT_SECRET_FILE) export JWT_SECRET=$(${pkgs.systemd}/bin/systemd-creds cat JWT_SECRET_FILE)
export JWT_REFRESH_SECRET=$(${pkgs.systemd}/bin/systemd-creds cat JWT_REFRESH_SECRET_FILE) export JWT_REFRESH_SECRET=$(${pkgs.systemd}/bin/systemd-creds cat JWT_REFRESH_SECRET_FILE)
export CONFIG_PATH=${configFile}
export HOST=${cfg.host} export HOST=${cfg.host}
export PORT=${builtins.toString cfg.port} export PORT=${builtins.toString cfg.port}
export MONGO_URI="${cfg.mongodbURI}" export MONGO_URI="${cfg.mongodbURI}"
@ -271,5 +291,6 @@ in
description = "LibreChat server user"; description = "LibreChat server user";
}; };
users.groups.librechat = lib.mkIf (cfg.user == "librechat") { }; users.groups.librechat = lib.mkIf (cfg.user == "librechat") { };
}; }
);
} }

View file

@ -30,6 +30,9 @@
openFirewall = true; openFirewall = true;
host = "0.0.0.0"; host = "0.0.0.0";
mongodbURI = "mongodb://apollo:27017"; mongodbURI = "mongodb://apollo:27017";
settings = {
version = "1.0.8";
};
auth = { auth = {
allowEmailLogin = true; allowEmailLogin = true;
allowEmailRegistration = true; allowEmailRegistration = true;