about summary refs log tree commit diff
path: root/nixos/modules/services/search/sonic-server.nix
blob: 59d96ae6b05a1919868f22d608fc25bb67e75782 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
{ config, lib, pkgs, ... }:

let
  cfg = config.services.sonic-server;

  settingsFormat = pkgs.formats.toml { };
  configFile = settingsFormat.generate "sonic-server-config.toml" cfg.settings;

in {
  meta.maintainers = [ lib.maintainers.anthonyroussel ];

  options = {
    services.sonic-server = {
      enable = lib.mkEnableOption (lib.mdDoc "Sonic Search Index");

      package = lib.mkPackageOption pkgs "sonic-server" { };

      settings = lib.mkOption {
        type = lib.types.submodule { freeformType = settingsFormat.type; };
        default = {
          store.kv.path = "/var/lib/sonic/kv";
          store.fst.path = "/var/lib/sonic/fst";
        };
        example = {
          server.log_level = "debug";
          channel.inet = "[::1]:1491";
        };
        description = lib.mdDoc ''
          Sonic Server configuration options.

          Refer to
          <https://github.com/valeriansaliou/sonic/blob/master/CONFIGURATION.md>
          for a full list of available options.
        '';
      };
    };
  };

  config = lib.mkIf cfg.enable {
    services.sonic-server.settings = lib.mapAttrs (name: lib.mkDefault) {
      server = {};
      channel.search = {};
      store = {
        kv = {
          path = "/var/lib/sonic/kv";
          database = {};
          pool = {};
        };
        fst = {
          path = "/var/lib/sonic/fst";
          graph = {};
          pool = {};
        };
      };
    };

    systemd.services.sonic-server = {
      description = "Sonic Search Index";

      wantedBy = [ "multi-user.target" ];
      after = [ "network.target" ];

      serviceConfig = {
        Type = "simple";

        ExecStart = "${lib.getExe cfg.package} -c ${configFile}";
        DynamicUser = true;
        Group = "sonic";
        LimitNOFILE = "infinity";
        Restart = "on-failure";
        StateDirectory = "sonic";
        StateDirectoryMode = "750";
        User = "sonic";
      };
    };
  };
}