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 (lib.mdDoc "MeiliSearch - a RESTful search API");
20 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.";
21 default = pkgs.meilisearch;
22 defaultText = lib.literalExpression "pkgs.meilisearch";
26 listenAddress = mkOption {
27 description = lib.mdDoc "MeiliSearch listen address.";
28 default = "127.0.0.1";
32 listenPort = mkOption {
33 description = lib.mdDoc "MeiliSearch port to listen on.";
38 environment = mkOption {
39 description = lib.mdDoc "Defines the running environment of MeiliSearch.";
40 default = "development";
41 type = types.enum [ "development" "production" ];
44 # TODO change this to LoadCredentials once possible
45 masterKeyEnvironmentFile = mkOption {
46 description = lib.mdDoc ''
47 Path to file which contains the master key.
48 By doing so, all routes will be protected and will require a key to be accessed.
49 If no master key is provided, all routes can be accessed without requiring any key.
50 The format is the following:
51 MEILI_MASTER_KEY=my_secret_key
54 type = with types; nullOr path;
57 noAnalytics = mkOption {
58 description = lib.mdDoc ''
59 Deactivates analytics.
60 Analytics allow MeiliSearch to know how many users are using MeiliSearch,
61 which versions and which platforms are used.
62 This process is entirely anonymous.
69 description = lib.mdDoc ''
70 Defines how much detail should be present in MeiliSearch's logs.
71 MeiliSearch currently supports four log levels, listed in order of increasing verbosity:
72 - 'ERROR': only log unexpected events indicating MeiliSearch is not functioning as expected
73 - 'WARN:' log all unexpected events, regardless of their severity
74 - 'INFO:' log all events. This is the default value
75 - 'DEBUG': log all events and including detailed information on MeiliSearch's internal processes.
76 Useful when diagnosing issues and debugging
82 maxIndexSize = mkOption {
83 description = lib.mdDoc ''
84 Sets the maximum size of the index.
85 Value must be given in bytes or explicitly stating a base unit.
86 For example, the default value can be written as 107374182400, '107.7Gb', or '107374 Mb'.
89 default = "107374182400";
93 payloadSizeLimit = mkOption {
94 description = lib.mdDoc ''
95 Sets the maximum size of accepted JSON payloads.
96 Value must be given in bytes or explicitly stating a base unit.
97 For example, the default value can be written as 107374182400, '107.7Gb', or '107374 Mb'.
100 default = "104857600";
106 ###### implementation
108 config = mkIf cfg.enable {
109 systemd.services.meilisearch = {
110 description = "MeiliSearch daemon";
111 wantedBy = [ "multi-user.target" ];
112 after = [ "network.target" ];
114 MEILI_DB_PATH = "/var/lib/meilisearch";
115 MEILI_HTTP_ADDR = "${cfg.listenAddress}:${toString cfg.listenPort}";
116 MEILI_NO_ANALYTICS = toString cfg.noAnalytics;
117 MEILI_ENV = cfg.environment;
118 MEILI_DUMP_DIR = "/var/lib/meilisearch/dumps";
119 MEILI_LOG_LEVEL = cfg.logLevel;
120 MEILI_MAX_INDEX_SIZE = cfg.maxIndexSize;
123 ExecStart = "${cfg.package}/bin/meilisearch";
125 StateDirectory = "meilisearch";
126 EnvironmentFile = mkIf (cfg.masterKeyEnvironmentFile != null) cfg.masterKeyEnvironmentFile;