blob: 2a7e68c9053a37ad6faa920a8363319c00af437d (
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.languagetool;
settingsFormat = pkgs.formats.javaProperties { };
in
{
options.services.languagetool = {
enable = mkEnableOption "the LanguageTool server, a multilingual spelling, style, and grammar checker that helps correct or paraphrase texts";
package = mkPackageOption pkgs "languagetool" { };
port = mkOption {
type = types.port;
default = 8081;
example = 8081;
description = ''
Port on which LanguageTool listens.
'';
};
public = mkEnableOption "access from anywhere (rather than just localhost)";
allowOrigin = mkOption {
type = types.nullOr types.str;
default = null;
example = "https://my-website.org";
description = ''
Set the Access-Control-Allow-Origin header in the HTTP response,
used for direct (non-proxy) JavaScript-based access from browsers.
`null` to allow access from all sites.
'';
};
settings = mkOption {
type = types.submodule {
freeformType = settingsFormat.type;
options.cacheSize = mkOption {
type = types.ints.unsigned;
default = 1000;
apply = toString;
description = "Number of sentences cached.";
};
};
default = {};
description = ''
Configuration file options for LanguageTool, see
'languagetool-http-server --help'
for supported settings.
'';
};
jrePackage = mkPackageOption pkgs "jre" { };
jvmOptions = mkOption {
description = ''
Extra command line options for the JVM running languagetool.
More information can be found here: https://docs.oracle.com/en/java/javase/19/docs/specs/man/java.html#standard-options-for-java
'';
default = [ ];
type = types.listOf types.str;
example = [
"-Xmx512m"
];
};
};
config = mkIf cfg.enable {
systemd.services.languagetool = {
description = "LanguageTool HTTP server";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
serviceConfig = {
DynamicUser = true;
User = "languagetool";
Group = "languagetool";
CapabilityBoundingSet = [ "" ];
RestrictNamespaces = [ "" ];
SystemCallFilter = [ "@system-service" "~ @privileged" ];
ProtectHome = "yes";
Restart = "on-failure";
ExecStart = ''
${cfg.jrePackage}/bin/java \
-cp ${cfg.package}/share/languagetool-server.jar \
${toString cfg.jvmOptions} \
org.languagetool.server.HTTPServer \
--port ${toString cfg.port} \
${optionalString cfg.public "--public"} \
${optionalString (cfg.allowOrigin != null) "--allow-origin ${cfg.allowOrigin}"} \
"--config" ${settingsFormat.generate "languagetool.conf" cfg.settings}
'';
};
};
};
}
|