about summary refs log tree commit diff
path: root/nixpkgs/nixos/modules/services/search/meilisearch.nix
blob: 9a03fc1f715b89c78916fa4a976b7dffe259bb8c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
{ config, lib, pkgs, ... }:

with lib;

let
  cfg = config.services.meilisearch;

in
{

  meta.maintainers = with maintainers; [ Br1ght0ne happysalada ];
  # Don't edit the docbook xml directly, edit the md and generate it:
  # `pandoc meilisearch.md -t docbook --top-level-division=chapter --extract-media=media -f markdown+smart > meilisearch.xml`
  meta.doc = ./meilisearch.xml;

  ###### interface

  options.services.meilisearch = {
    enable = mkEnableOption "MeiliSearch - a RESTful search API";

    package = mkOption {
      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.";
      default = pkgs.meilisearch;
      defaultText = "pkgs.meilisearch";
      type = types.package;
    };

    listenAddress = mkOption {
      description = lib.mdDoc "MeiliSearch listen address.";
      default = "127.0.0.1";
      type = types.str;
    };

    listenPort = mkOption {
      description = lib.mdDoc "MeiliSearch port to listen on.";
      default = 7700;
      type = types.port;
    };

    environment = mkOption {
      description = lib.mdDoc "Defines the running environment of MeiliSearch.";
      default = "development";
      type = types.enum [ "development" "production" ];
    };

    # TODO change this to LoadCredentials once possible
    masterKeyEnvironmentFile = mkOption {
      description = lib.mdDoc ''
        Path to file which contains the master key.
        By doing so, all routes will be protected and will require a key to be accessed.
        If no master key is provided, all routes can be accessed without requiring any key.
        The format is the following:
        MEILI_MASTER_KEY=my_secret_key
      '';
      default = null;
      type = with types; nullOr path;
    };

    noAnalytics = mkOption {
      description = lib.mdDoc ''
        Deactivates analytics.
        Analytics allow MeiliSearch to know how many users are using MeiliSearch,
        which versions and which platforms are used.
        This process is entirely anonymous.
      '';
      default = true;
      type = types.bool;
    };

    logLevel = mkOption {
      description = ''
        Defines how much detail should be present in MeiliSearch's logs.
        MeiliSearch currently supports four log levels, listed in order of increasing verbosity:
        - 'ERROR': only log unexpected events indicating MeiliSearch is not functioning as expected
        - 'WARN:' log all unexpected events, regardless of their severity
        - 'INFO:' log all events. This is the default value
        - 'DEBUG': log all events and including detailed information on MeiliSearch's internal processes.
          Useful when diagnosing issues and debugging
      '';
      default = "INFO";
      type = types.str;
    };

    maxIndexSize = mkOption {
      description = lib.mdDoc ''
        Sets the maximum size of the index.
        Value must be given in bytes or explicitly stating a base unit.
        For example, the default value can be written as 107374182400, '107.7Gb', or '107374 Mb'.
        Default is 100 GiB
      '';
      default = "107374182400";
      type = types.str;
    };

    payloadSizeLimit = mkOption {
      description = lib.mdDoc ''
        Sets the maximum size of accepted JSON payloads.
        Value must be given in bytes or explicitly stating a base unit.
        For example, the default value can be written as 107374182400, '107.7Gb', or '107374 Mb'.
        Default is ~ 100 MB
      '';
      default = "104857600";
      type = types.str;
    };

  };

  ###### implementation

  config = mkIf cfg.enable {
    systemd.services.meilisearch = {
      description = "MeiliSearch daemon";
      wantedBy = [ "multi-user.target" ];
      after = [ "network.target" ];
      environment = {
        MEILI_DB_PATH = "/var/lib/meilisearch";
        MEILI_HTTP_ADDR = "${cfg.listenAddress}:${toString cfg.listenPort}";
        MEILI_NO_ANALYTICS = toString cfg.noAnalytics;
        MEILI_ENV = cfg.environment;
        MEILI_DUMPS_DIR = "/var/lib/meilisearch/dumps";
        MEILI_LOG_LEVEL = cfg.logLevel;
        MEILI_MAX_INDEX_SIZE = cfg.maxIndexSize;
      };
      serviceConfig = {
        ExecStart = "${cfg.package}/bin/meilisearch";
        DynamicUser = true;
        StateDirectory = "meilisearch";
        EnvironmentFile = mkIf (cfg.masterKeyEnvironmentFile != null) cfg.masterKeyEnvironmentFile;
      };
    };
  };
}