1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7
8let
9 cfg = config.services.tika;
10 inherit (lib)
11 literalExpression
12 mkIf
13 mkEnableOption
14 mkOption
15 mkPackageOption
16 getExe
17 types
18 ;
19in
20{
21 meta.maintainers = [ ];
22
23 options = {
24 services.tika = {
25 enable = mkEnableOption "Apache Tika server";
26 package = mkPackageOption pkgs "tika" { };
27
28 listenAddress = mkOption {
29 type = types.str;
30 default = "127.0.0.1";
31 example = "0.0.0.0";
32 description = ''
33 The Apache Tika bind address.
34 '';
35 };
36
37 port = mkOption {
38 type = types.port;
39 default = 9998;
40 description = ''
41 The Apache Tike port to listen on
42 '';
43 };
44
45 configFile = mkOption {
46 type = types.nullOr types.path;
47 default = null;
48 description = ''
49 The Apache Tika configuration (XML) file to use.
50 '';
51 example = literalExpression "./tika/tika-config.xml";
52 };
53
54 enableOcr = mkOption {
55 type = types.bool;
56 default = true;
57 description = ''
58 Whether to enable OCR support by adding the `tesseract` package as a dependency.
59 '';
60 };
61
62 openFirewall = mkOption {
63 type = types.bool;
64 default = false;
65 description = ''
66 Whether to open the firewall for Apache Tika.
67 This adds `services.tika.port` to `networking.firewall.allowedTCPPorts`.
68 '';
69 };
70 };
71 };
72
73 config = mkIf cfg.enable {
74 systemd.services.tika = {
75 description = "Apache Tika Server";
76
77 wantedBy = [ "multi-user.target" ];
78 after = [ "network.target" ];
79
80 serviceConfig =
81 let
82 package = cfg.package.override {
83 inherit (cfg) enableOcr;
84 enableGui = false;
85 };
86 in
87 {
88 Type = "simple";
89
90 ExecStart = "${getExe package} --host ${cfg.listenAddress} --port ${toString cfg.port} ${
91 lib.optionalString (cfg.configFile != null) "--config ${cfg.configFile}"
92 }";
93 DynamicUser = true;
94 StateDirectory = "tika";
95 CacheDirectory = "tika";
96 };
97 };
98
99 networking.firewall = mkIf cfg.openFirewall { allowedTCPPorts = [ cfg.port ]; };
100 };
101}