Skip to content

Commit 09a88cd

Browse files
nixos/librechat: add meilisearch support (#481465)
2 parents aba569c + a81e104 commit 09a88cd

3 files changed

Lines changed: 44 additions & 1 deletion

File tree

nixos/modules/services/search/meilisearch.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ in
121121
Path to file which contains the master key.
122122
By doing so, all routes will be protected and will require a key to be accessed.
123123
If no master key is provided, all routes can be accessed without requiring any key.
124+
125+
You can generate a master key by running `openssl rand -base64 36`.
126+
Alternatively, you can start Meilisearch without a master key and use the pre-generated key from the service's logs that can be obtained by `journalctl -u meilisearch | grep -- --master-key`.
124127
'';
125128
default = null;
126129
type = lib.types.nullOr lib.types.path;

nixos/modules/services/web-apps/librechat.nix

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
}:
77
let
88
cfg = config.services.librechat;
9+
meiliCfg = config.services.meilisearch;
910
format = pkgs.formats.yaml { };
1011
configFile = format.generate "librechat.yaml" cfg.settings;
1112
exportCredentials = n: _: ''export ${n}="$(${pkgs.systemd}/bin/systemd-creds cat ${n}_FILE)"'';
@@ -155,6 +156,26 @@ in
155156
};
156157

157158
enableLocalDB = lib.mkEnableOption "a local mongodb instance";
159+
160+
meilisearch = lib.mkOption {
161+
type = lib.types.submodule {
162+
options = {
163+
enable = lib.mkOption {
164+
type = lib.types.bool;
165+
default = false;
166+
example = true;
167+
description = ''
168+
Whether to enable and configure Meilisearch locally for Librechat.
169+
You will manually need to set `services.meilisearch.masterKeyFile`.
170+
'';
171+
};
172+
};
173+
};
174+
default = { };
175+
description = ''
176+
See [LibreChat search feature](https://www.librechat.ai/docs/features/search).
177+
'';
178+
};
158179
};
159180

160181
config = lib.mkIf cfg.enable {
@@ -178,6 +199,12 @@ in
178199
You can use https://www.librechat.ai/toolkit/creds_generator to generate these.
179200
'';
180201
}
202+
{
203+
assertion = cfg.meilisearch.enable -> meiliCfg.masterKeyFile != null;
204+
message = ''
205+
LibreChat's Meilisearch integration requires `services.meilisearch.masterKeyFile` to be set.
206+
'';
207+
}
181208
];
182209

183210
networking.firewall.allowedTCPPorts = lib.optional cfg.openFirewall cfg.port;
@@ -192,7 +219,8 @@ in
192219
after = [
193220
"tmpfiles.target"
194221
]
195-
++ lib.optional cfg.enableLocalDB "mongodb.service";
222+
++ lib.optional cfg.meilisearch.enable "meilisearch.service";
223+
wants = lib.optional cfg.meilisearch.enable "meilisearch.service";
196224
description = "Open-source app for all your AI conversations, fully customizable and compatible with any AI provider";
197225
environment = cfg.env;
198226
script = # sh
@@ -249,6 +277,11 @@ in
249277

250278
services.librechat.env.MONGO_URI = lib.mkIf cfg.enableLocalDB "mongodb://localhost:27017";
251279
services.mongodb.enable = lib.mkIf cfg.enableLocalDB true;
280+
281+
services.meilisearch.enable = lib.mkIf cfg.meilisearch.enable true;
282+
services.librechat.env.SEARCH = lib.mkIf cfg.meilisearch.enable true;
283+
services.librechat.env.MEILI_HOST = lib.mkIf cfg.meilisearch.enable "http://${meiliCfg.settings.http_addr}";
284+
services.librechat.credentials.MEILI_MASTER_KEY = lib.mkIf cfg.meilisearch.enable meiliCfg.masterKeyFile;
252285
};
253286

254287
meta.maintainers = with lib.maintainers; [

nixos/tests/librechat.nix

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
credsIvFile = pkgs.writeText "librechat-creds-iv" "7c09a571f65ac793611685cc9ab1dbe7";
1818
jwtSecret = pkgs.writeText "librechat-jwt-secret" "29c4dc7f7de15306accf5eddb4cb8a70eb233d9fba4301f8f47f14c8c047ac81";
1919
jwtRefreshSecret = pkgs.writeText "librechat-jwt-refresh-secret" "f2c1685561f2f570b3e7955df267b5c602ee099f14dc5caa0dacc320580ea180";
20+
meilisearchMasterKeyFile = pkgs.writeText "meilisearch-master-key" "xHkP3Bzcf98fw7FiSCR82g5ULLGrXc4frK1qkEfN8St/3kJZ";
2021
in
2122
{
2223
services.librechat = {
@@ -32,13 +33,19 @@
3233
JWT_REFRESH_SECRET = jwtRefreshSecret;
3334
};
3435
enableLocalDB = true;
36+
meilisearch.enable = true;
3537
};
38+
39+
services.meilisearch.masterKeyFile = meilisearchMasterKeyFile;
3640
};
3741

3842
testScript = ''
3943
machine.start()
4044
4145
machine.succeed("grep -qF 'ALLOW_REGISTRATION=true' /etc/systemd/system/librechat.service")
46+
machine.succeed("grep -qF 'SEARCH=true' /etc/systemd/system/librechat.service")
47+
machine.succeed("grep -qF 'MEILI_HOST=http://localhost:7700' /etc/systemd/system/librechat.service")
48+
machine.succeed("grep -qG 'MEILI_MASTER_KEY_FILE:/nix/store/.*meilisearch-master-key' /etc/systemd/system/librechat.service")
4249
4350
machine.wait_for_unit("librechat.service")
4451
machine.wait_for_open_port(3080)

0 commit comments

Comments
 (0)