aboutsummaryrefslogtreecommitdiff
path: root/services/omnisearch/default.nix
blob: fb877e56c08772d90a7b2fa71d59695c0eac617c (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,
  pkgs,
  lib,
  ...
}:
with lib;
let
  cfg = config.services.omnisearch;
  omnisearch-pkg = import ./pkg.nix { inherit pkgs lib; };
in
{
  options.services.omnisearch = {
    enable = mkEnableOption "omnisearch metasearch engine";
    port = mkOption {
      type = types.int;
      default = 8087;
    };
    host = mkOption {
      type = types.str;
      default = "0.0.0.0";
    };
    openFirewall = mkOption {
      type = types.bool;
      default = false;
    };
    settings = mkOption {
      type = types.attrs;
      default = { };
    };
  };

  config = mkIf cfg.enable {
    systemd.services.omnisearch = {
      enable = true;
      script = "${omnisearch-pkg}/bin/omnisearch";
      serviceConfig = {
        Type = "simple";
        User = "omnisearch";
        Group = "omnisearch";
        WorkingDirectory = "/etc/omnisearch";
        Restart = "always";
        RestartSec = 5;
        PrivateTmp = true;
        NoNewPrivileges = true;
      };
      wantedBy = [ "multi-user.target" ];
      after = [ "network.target" ];
    };

    users.groups.omnisearch = { };
    users.users.omnisearch = {
      isSystemUser = true;
      group = "omnisearch";
      shell = null;
    };

    networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [
      cfg.port
      5000
    ];

    environment.systemPackages = [ omnisearch-pkg ];

    environment.etc = {
      "omnisearch/config.ini".text = generators.toINI { } (
        recursiveUpdate {
          server.host = "0.0.0.0";
          server.port = cfg.port;
          cache.dir = "/tmp/omnisearch_cache";
        } cfg.settings
      );
      "omnisearch/templates".source = ./templates;
      "omnisearch/static".source = ./static;
    };
  };
}