1 { config, lib, pkgs, ... }:
3 cfg = config.services.languagetool;
4 settingsFormat = pkgs.formats.javaProperties { };
7 options.services.languagetool = {
8 enable = lib.mkEnableOption "the LanguageTool server, a multilingual spelling, style, and grammar checker that helps correct or paraphrase texts";
10 package = lib.mkPackageOption pkgs "languagetool" { };
13 type = lib.types.port;
17 Port on which LanguageTool listens.
21 public = lib.mkEnableOption "access from anywhere (rather than just localhost)";
23 allowOrigin = lib.mkOption {
24 type = lib.types.nullOr lib.types.str;
26 example = "https://my-website.org";
28 Set the Access-Control-Allow-Origin header in the HTTP response,
29 used for direct (non-proxy) JavaScript-based access from browsers.
30 `null` to allow access from all sites.
34 settings = lib.mkOption {
35 type = lib.types.submodule {
36 freeformType = settingsFormat.type;
38 options.cacheSize = lib.mkOption {
39 type = lib.types.ints.unsigned;
42 description = "Number of sentences cached.";
47 Configuration file options for LanguageTool, see
48 'languagetool-http-server --help'
49 for supported settings.
53 jrePackage = lib.mkPackageOption pkgs "jre" { };
55 jvmOptions = lib.mkOption {
57 Extra command line options for the JVM running languagetool.
58 More information can be found here: https://docs.oracle.com/en/java/javase/19/docs/specs/man/java.html#standard-options-for-java
61 type = lib.types.listOf lib.types.str;
68 config = lib.mkIf cfg.enable {
70 systemd.services.languagetool = {
71 description = "LanguageTool HTTP server";
72 wantedBy = [ "multi-user.target" ];
73 after = [ "network.target" ];
76 User = "languagetool";
77 Group = "languagetool";
78 CapabilityBoundingSet = [ "" ];
79 RestrictNamespaces = [ "" ];
80 SystemCallFilter = [ "@system-service" "~ @privileged" ];
82 Restart = "on-failure";
84 ${cfg.jrePackage}/bin/java \
85 -cp ${cfg.package}/share/languagetool-server.jar \
86 ${toString cfg.jvmOptions} \
87 org.languagetool.server.HTTPServer \
88 --port ${toString cfg.port} \
89 ${lib.optionalString cfg.public "--public"} \
90 ${lib.optionalString (cfg.allowOrigin != null) "--allow-origin ${cfg.allowOrigin}"} \
91 "--config" ${settingsFormat.generate "languagetool.conf" cfg.settings}