Skip to content

Commit

Permalink
feat: add typesense service
Browse files Browse the repository at this point in the history
  • Loading branch information
shyim committed May 13, 2024
1 parent 725c904 commit 280c1d8
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions src/modules/services/typesense.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{ pkgs, lib, config, ... }:

let
cfg = config.services.typesense;
types = lib.types;
in
{
options.services.typesense = {
enable = lib.mkEnableOption "typesense process";

package = lib.mkOption {
type = types.package;
description = "Which package of typesense to use";
default = pkgs.typesense;
defaultText = lib.literalExpression "pkgs.typesense";
};

host = lib.mkOption {
type = types.str;
default = "127.0.0.1";
description = ''
The HTTP host to accept connections.
'';
};

port = lib.mkOption {
type = types.port;
default = 8108;
description = ''
The HTTP port to accept connections.
'';
};

apiKey = lib.mkOption {
type = types.str;
description = "API Key.";
default = "example";
};

searchOnlyKey = lib.mkOption {
type = types.nullOr types.str;
description = "Search Only Key.";
default = null;
};

additionalArgs = lib.mkOption {
type = types.listOf types.lines;
default = [ ];
example = [ ];
description = ''
Additional arguments passed to `typesense`.
'';
};
};

config = lib.mkIf cfg.enable {
processes.typesense.exec = ''
mkdir -p "$DEVENV_STATE/typesense"
exec "${cfg.package}/bin/typesense-server" \
--data-dir "$DEVENV_STATE/typesense" \
--api-key ${lib.escapeShellArg cfg.apiKey} \
--api-host ${cfg.host} \
--api-port ${toString cfg.port} \
${lib.optionalString (cfg.searchOnlyKey != null) "--search-only-api-key ${lib.escapeShellArg cfg.searchOnlyKey}"} \
${lib.escapeShellArgs cfg.additionalArgs}
'';
};
}

0 comments on commit 280c1d8

Please sign in to comment.