1 { config, lib, pkgs, ... }: let
14 cfg = config.services.typesense;
15 settingsFormatIni = pkgs.formats.ini {
16 listToValue = concatMapStringsSep " " (generators.mkValueStringDefault { });
17 mkKeyValue = generators.mkKeyValueDefault
21 else generators.mkValueStringDefault { } v;
25 configFile = settingsFormatIni.generate "typesense.ini" cfg.settings;
27 options.services.typesense = {
28 enable = mkEnableOption "typesense";
29 package = mkPackageOption pkgs "typesense" {};
31 apiKeyFile = mkOption {
34 Sets the admin api key for typesense. Always use this option
35 instead of {option}`settings.server.api-key` to prevent the key
36 from being written to the world-readable nix store.
41 description = "Typesense configuration. Refer to [the documentation](https://typesense.org/docs/0.24.1/api/server-configuration.html) for supported values.";
43 type = types.submodule {
44 freeformType = settingsFormatIni.type;
48 default = "/var/lib/typesense";
49 description = "Path to the directory where data will be stored on disk.";
52 api-address = mkOption {
54 description = "Address to which Typesense API service binds.";
60 description = "Port on which the Typesense API service listens.";
67 config = mkIf cfg.enable {
68 systemd.services.typesense = {
69 description = "Typesense search engine";
70 wantedBy = [ "multi-user.target" ];
71 after = [ "network.target" ];
74 export TYPESENSE_API_KEY=$(cat ${cfg.apiKeyFile})
75 exec ${cfg.package}/bin/typesense-server --config ${configFile}
79 Restart = "on-failure";
84 StateDirectory = "typesense";
85 StateDirectoryMode = "0750";
88 CapabilityBoundingSet = "";
89 LockPersonality = true;
90 # MemoryDenyWriteExecute = true; needed since 0.25.1
91 NoNewPrivileges = true;
94 PrivateDevices = true;
97 ProtectControlGroups = true;
99 ProtectHostname = true;
100 ProtectKernelLogs = true;
101 ProtectKernelModules = true;
102 ProtectKernelTunables = true;
103 ProtectProc = "invisible";
105 ProtectSystem = "strict";
107 RestrictAddressFamilies = [
112 RestrictNamespaces = true;
113 RestrictRealtime = true;
114 RestrictSUIDSGID = true;
115 SystemCallArchitectures = "native";