|
6 | 6 | }: |
7 | 7 | let |
8 | 8 | cfg = config.services.librechat; |
| 9 | + meiliCfg = config.services.meilisearch; |
9 | 10 | format = pkgs.formats.yaml { }; |
10 | 11 | configFile = format.generate "librechat.yaml" cfg.settings; |
11 | 12 | exportCredentials = n: _: ''export ${n}="$(${pkgs.systemd}/bin/systemd-creds cat ${n}_FILE)"''; |
|
155 | 156 | }; |
156 | 157 |
|
157 | 158 | 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 | + }; |
158 | 179 | }; |
159 | 180 |
|
160 | 181 | config = lib.mkIf cfg.enable { |
|
178 | 199 | You can use https://www.librechat.ai/toolkit/creds_generator to generate these. |
179 | 200 | ''; |
180 | 201 | } |
| 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 | + } |
181 | 208 | ]; |
182 | 209 |
|
183 | 210 | networking.firewall.allowedTCPPorts = lib.optional cfg.openFirewall cfg.port; |
|
192 | 219 | after = [ |
193 | 220 | "tmpfiles.target" |
194 | 221 | ] |
195 | | - ++ lib.optional cfg.enableLocalDB "mongodb.service"; |
| 222 | + ++ lib.optional cfg.meilisearch.enable "meilisearch.service"; |
| 223 | + wants = lib.optional cfg.meilisearch.enable "meilisearch.service"; |
196 | 224 | description = "Open-source app for all your AI conversations, fully customizable and compatible with any AI provider"; |
197 | 225 | environment = cfg.env; |
198 | 226 | script = # sh |
|
249 | 277 |
|
250 | 278 | services.librechat.env.MONGO_URI = lib.mkIf cfg.enableLocalDB "mongodb://localhost:27017"; |
251 | 279 | 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; |
252 | 285 | }; |
253 | 286 |
|
254 | 287 | meta.maintainers = with lib.maintainers; [ |
|
0 commit comments