1 { config, lib, pkgs, ... }:
6 cfg = config.services.meilisearch;
11 meta.maintainers = with maintainers; [ Br1ght0ne happysalada ];
12 # Don't edit the docbook xml directly, edit the md and generate it:
13 # `pandoc meilisearch.md -t docbook --top-level-division=chapter --extract-media=media -f markdown+smart > meilisearch.xml`
14 meta.doc = ./meilisearch.xml;
18 options.services.meilisearch = {
19 enable = mkEnableOption (lib.mdDoc "MeiliSearch - a RESTful search API");
22 description = lib.mdDoc "The package to use for meilisearch. Use this if you require specific features to be enabled. The default package has no features.";
23 default = pkgs.meilisearch;
24 defaultText = "pkgs.meilisearch";
28 listenAddress = mkOption {
29 description = lib.mdDoc "MeiliSearch listen address.";
30 default = "127.0.0.1";
34 listenPort = mkOption {
35 description = lib.mdDoc "MeiliSearch port to listen on.";
40 environment = mkOption {
41 description = lib.mdDoc "Defines the running environment of MeiliSearch.";
42 default = "development";
43 type = types.enum [ "development" "production" ];
46 # TODO change this to LoadCredentials once possible
47 masterKeyEnvironmentFile = mkOption {
48 description = lib.mdDoc ''
49 Path to file which contains the master key.
50 By doing so, all routes will be protected and will require a key to be accessed.
51 If no master key is provided, all routes can be accessed without requiring any key.
52 The format is the following:
53 MEILI_MASTER_KEY=my_secret_key
56 type = with types; nullOr path;
59 noAnalytics = mkOption {
60 description = lib.mdDoc ''
61 Deactivates analytics.
62 Analytics allow MeiliSearch to know how many users are using MeiliSearch,
63 which versions and which platforms are used.
64 This process is entirely anonymous.
71 description = lib.mdDoc ''
72 Defines how much detail should be present in MeiliSearch's logs.
73 MeiliSearch currently supports four log levels, listed in order of increasing verbosity:
74 - 'ERROR': only log unexpected events indicating MeiliSearch is not functioning as expected
75 - 'WARN:' log all unexpected events, regardless of their severity
76 - 'INFO:' log all events. This is the default value
77 - 'DEBUG': log all events and including detailed information on MeiliSearch's internal processes.
78 Useful when diagnosing issues and debugging
84 maxIndexSize = mkOption {
85 description = lib.mdDoc ''
86 Sets the maximum size of the index.
87 Value must be given in bytes or explicitly stating a base unit.
88 For example, the default value can be written as 107374182400, '107.7Gb', or '107374 Mb'.
91 default = "107374182400";
95 payloadSizeLimit = mkOption {
96 description = lib.mdDoc ''
97 Sets the maximum size of accepted JSON payloads.
98 Value must be given in bytes or explicitly stating a base unit.
99 For example, the default value can be written as 107374182400, '107.7Gb', or '107374 Mb'.
102 default = "104857600";
108 ###### implementation
110 config = mkIf cfg.enable {
111 systemd.services.meilisearch = {
112 description = "MeiliSearch daemon";
113 wantedBy = [ "multi-user.target" ];
114 after = [ "network.target" ];
116 MEILI_DB_PATH = "/var/lib/meilisearch";
117 MEILI_HTTP_ADDR = "${cfg.listenAddress}:${toString cfg.listenPort}";
118 MEILI_NO_ANALYTICS = toString cfg.noAnalytics;
119 MEILI_ENV = cfg.environment;
120 MEILI_DUMPS_DIR = "/var/lib/meilisearch/dumps";
121 MEILI_LOG_LEVEL = cfg.logLevel;
122 MEILI_MAX_INDEX_SIZE = cfg.maxIndexSize;
125 ExecStart = "${cfg.package}/bin/meilisearch";
127 StateDirectory = "meilisearch";
128 EnvironmentFile = mkIf (cfg.masterKeyEnvironmentFile != null) cfg.masterKeyEnvironmentFile;