1 { config, lib, pkgs, ... }: let
15 cfg = config.services.typesense;
16 settingsFormatIni = pkgs.formats.ini {
17 listToValue = concatMapStringsSep " " (generators.mkValueStringDefault { });
18 mkKeyValue = generators.mkKeyValueDefault
22 else generators.mkValueStringDefault { } v;
26 configFile = settingsFormatIni.generate "typesense.ini" cfg.settings;
28 options.services.typesense = {
29 enable = mkEnableOption "typesense";
30 package = mkPackageOption pkgs "typesense" {};
32 apiKeyFile = mkOption {
35 Sets the admin api key for typesense. Always use this option
36 instead of {option}`settings.server.api-key` to prevent the key
37 from being written to the world-readable nix store.
42 description = mdDoc "Typesense configuration. Refer to [the documentation](https://typesense.org/docs/0.24.1/api/server-configuration.html) for supported values.";
44 type = types.submodule {
45 freeformType = settingsFormatIni.type;
49 default = "/var/lib/typesense";
50 description = mdDoc "Path to the directory where data will be stored on disk.";
53 api-address = mkOption {
55 description = mdDoc "Address to which Typesense API service binds.";
61 description = mdDoc "Port on which the Typesense API service listens.";
68 config = mkIf cfg.enable {
69 systemd.services.typesense = {
70 description = "Typesense search engine";
71 wantedBy = [ "multi-user.target" ];
72 after = [ "network.target" ];
75 export TYPESENSE_API_KEY=$(cat ${cfg.apiKeyFile})
76 exec ${cfg.package}/bin/typesense-server --config ${configFile}
80 Restart = "on-failure";
85 StateDirectory = "typesense";
86 StateDirectoryMode = "0750";
89 CapabilityBoundingSet = "";
90 LockPersonality = true;
91 # MemoryDenyWriteExecute = true; needed since 0.25.1
92 NoNewPrivileges = true;
95 PrivateDevices = true;
98 ProtectControlGroups = true;
100 ProtectHostname = true;
101 ProtectKernelLogs = true;
102 ProtectKernelModules = true;
103 ProtectKernelTunables = true;
104 ProtectProc = "invisible";
106 ProtectSystem = "strict";
108 RestrictAddressFamilies = [
113 RestrictNamespaces = true;
114 RestrictRealtime = true;
115 RestrictSUIDSGID = true;
116 SystemCallArchitectures = "native";