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