1 { config, lib, pkgs, ... }:
6 cfg = config.services.meilisearch;
11 meta.maintainers = with maintainers; [ Br1ght0ne happysalada ];
12 meta.doc = ./meilisearch.md;
16 options.services.meilisearch = {
17 enable = mkEnableOption "MeiliSearch - a RESTful search API";
19 package = mkPackageOption pkgs "meilisearch" {
21 Use this if you require specific features to be enabled. The default package has no features.
25 listenAddress = mkOption {
26 description = "MeiliSearch listen address.";
27 default = "127.0.0.1";
31 listenPort = mkOption {
32 description = "MeiliSearch port to listen on.";
37 environment = mkOption {
38 description = "Defines the running environment of MeiliSearch.";
39 default = "development";
40 type = types.enum [ "development" "production" ];
43 # TODO change this to LoadCredentials once possible
44 masterKeyEnvironmentFile = mkOption {
46 Path to file which contains the master key.
47 By doing so, all routes will be protected and will require a key to be accessed.
48 If no master key is provided, all routes can be accessed without requiring any key.
49 The format is the following:
50 MEILI_MASTER_KEY=my_secret_key
53 type = with types; nullOr path;
56 noAnalytics = mkOption {
58 Deactivates analytics.
59 Analytics allow MeiliSearch to know how many users are using MeiliSearch,
60 which versions and which platforms are used.
61 This process is entirely anonymous.
69 Defines how much detail should be present in MeiliSearch's logs.
70 MeiliSearch currently supports four log levels, listed in order of increasing verbosity:
71 - 'ERROR': only log unexpected events indicating MeiliSearch is not functioning as expected
72 - 'WARN:' log all unexpected events, regardless of their severity
73 - 'INFO:' log all events. This is the default value
74 - 'DEBUG': log all events and including detailed information on MeiliSearch's internal processes.
75 Useful when diagnosing issues and debugging
81 maxIndexSize = mkOption {
83 Sets the maximum size of the index.
84 Value must be given in bytes or explicitly stating a base unit.
85 For example, the default value can be written as 107374182400, '107.7Gb', or '107374 Mb'.
88 default = "107374182400";
92 payloadSizeLimit = mkOption {
94 Sets the maximum size of accepted JSON payloads.
95 Value must be given in bytes or explicitly stating a base unit.
96 For example, the default value can be written as 107374182400, '107.7Gb', or '107374 Mb'.
99 default = "104857600";
105 ###### implementation
107 config = mkIf cfg.enable {
108 systemd.services.meilisearch = {
109 description = "MeiliSearch daemon";
110 wantedBy = [ "multi-user.target" ];
111 after = [ "network.target" ];
113 MEILI_DB_PATH = "/var/lib/meilisearch";
114 MEILI_HTTP_ADDR = "${cfg.listenAddress}:${toString cfg.listenPort}";
115 MEILI_NO_ANALYTICS = toString cfg.noAnalytics;
116 MEILI_ENV = cfg.environment;
117 MEILI_DUMP_DIR = "/var/lib/meilisearch/dumps";
118 MEILI_LOG_LEVEL = cfg.logLevel;
119 MEILI_MAX_INDEX_SIZE = cfg.maxIndexSize;
122 ExecStart = "${cfg.package}/bin/meilisearch";
124 StateDirectory = "meilisearch";
125 EnvironmentFile = mkIf (cfg.masterKeyEnvironmentFile != null) cfg.masterKeyEnvironmentFile;