1{ config, lib, pkgs, ... }:
2
3let
4 cfg = config.services.sonic-server;
5
6 settingsFormat = pkgs.formats.toml { };
7 configFile = settingsFormat.generate "sonic-server-config.toml" cfg.settings;
8
9in {
10 meta.maintainers = [ lib.maintainers.anthonyroussel ];
11
12 options = {
13 services.sonic-server = {
14 enable = lib.mkEnableOption "Sonic Search Index";
15
16 package = lib.mkPackageOption pkgs "sonic-server" { };
17
18 settings = lib.mkOption {
19 type = lib.types.submodule { freeformType = settingsFormat.type; };
20 default = {
21 store.kv.path = "/var/lib/sonic/kv";
22 store.fst.path = "/var/lib/sonic/fst";
23 };
24 example = {
25 server.log_level = "debug";
26 channel.inet = "[::1]:1491";
27 };
28 description = ''
29 Sonic Server configuration options.
30
31 Refer to
32 <https://github.com/valeriansaliou/sonic/blob/master/CONFIGURATION.md>
33 for a full list of available options.
34 '';
35 };
36 };
37 };
38
39 config = lib.mkIf cfg.enable {
40 services.sonic-server.settings = lib.mapAttrs (name: lib.mkDefault) {
41 server = {};
42 channel.search = {};
43 store = {
44 kv = {
45 path = "/var/lib/sonic/kv";
46 database = {};
47 pool = {};
48 };
49 fst = {
50 path = "/var/lib/sonic/fst";
51 graph = {};
52 pool = {};
53 };
54 };
55 };
56
57 systemd.services.sonic-server = {
58 description = "Sonic Search Index";
59
60 wantedBy = [ "multi-user.target" ];
61 after = [ "network.target" ];
62
63 serviceConfig = {
64 Type = "simple";
65
66 ExecStart = "${lib.getExe cfg.package} -c ${configFile}";
67 DynamicUser = true;
68 Group = "sonic";
69 LimitNOFILE = "infinity";
70 Restart = "on-failure";
71 StateDirectory = "sonic";
72 StateDirectoryMode = "750";
73 User = "sonic";
74 };
75 };
76 };
77}