From 811fe35a665fa47cf88c97e9e6aa395526d3a9b6 Mon Sep 17 00:00:00 2001 From: Oleksii Filonenko Date: Tue, 7 Apr 2020 11:43:33 +0300 Subject: [PATCH] nixos/meilisearch: init Reviewed-by: Aaron Andersen (cherry picked from commit 5844ea85c3ad96b8a2df9da50374c530e86a904d) --- nixos/modules/module-list.nix | 1 + nixos/modules/services/search/meilisearch.nix | 83 +++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 nixos/modules/services/search/meilisearch.nix diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index b07b30c8c3e0..c356fc56a0eb 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -899,6 +899,7 @@ ./services/search/elasticsearch-curator.nix ./services/search/hound.nix ./services/search/kibana.nix + ./services/search/meilisearch.nix ./services/search/solr.nix ./services/security/certmgr.nix ./services/security/cfssl.nix diff --git a/nixos/modules/services/search/meilisearch.nix b/nixos/modules/services/search/meilisearch.nix new file mode 100644 index 000000000000..f8205fe550ad --- /dev/null +++ b/nixos/modules/services/search/meilisearch.nix @@ -0,0 +1,83 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.services.meilisearch; + +in { + + meta.maintainers = with maintainers; [ filalex77 ]; + + ###### interface + + options.services.meilisearch = { + enable = mkEnableOption "MeiliSearch - a RESTful search API"; + + listenAddress = mkOption { + description = "MeiliSearch listen address."; + default = "127.0.0.1"; + type = types.str; + }; + + listenPort = mkOption { + description = "MeiliSearch port to listen on."; + default = 7700; + type = types.port; + }; + + environment = mkOption { + description = "Defines the running environment of MeiliSearch."; + default = "development"; + type = types.enum [ "development" "production" ]; + }; + + masterKeyFile = mkOption { + description = '' + 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. + ''; + default = null; + type = with types; nullOr path; + }; + + noAnalytics = mkOption { + description = '' + 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 = false; + type = types.bool; + }; + + }; + + ###### implementation + + config = mkIf cfg.enable { + systemd.services.meilisearch = { + description = "MeiliSearch daemon"; + wantedBy = [ "multi-user.target" ]; + after = [ "network.target" ]; + environment = let + masterKey = mkIf (cfg.masterKeyFile != null) (builtins.readFile cfg.masterKeyFile); + in { + MEILI_DB_PATH = "/var/lib/meilisearch"; + MEILI_HTTP_ADDR = "${cfg.listenAddress}:${toString cfg.listenPort}"; + MEILI_MASTER_KEY = masterKey; + MEILI_NO_ANALYTICS = toString cfg.noAnalytics; + MEILI_ENV = cfg.environment; + }; + serviceConfig = { + ExecStart = "${pkgs.meilisearch}/bin/meilisearch"; + DynamicUser = true; + StateDirectory = "meilisearch"; + }; + }; + + environment.systemPackages = [ pkgs.meilisearch ]; + }; +}