1 { config, lib, options, pkgs, ... }:
6 cfg = config.services.languagetool;
7 settingsFormat = pkgs.formats.javaProperties {};
9 options.services.languagetool = {
10 enable = mkEnableOption (mdDoc "the LanguageTool server");
16 description = mdDoc ''
17 Port on which LanguageTool listens.
21 public = mkEnableOption (mdDoc "access from anywhere (rather than just localhost)");
23 allowOrigin = mkOption {
24 type = types.nullOr types.str;
26 example = "https://my-website.org";
27 description = mdDoc ''
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 = types.submodule {
36 freeformType = settingsFormat.type;
38 options.cacheSize = mkOption {
39 type = types.ints.unsigned;
42 description = mdDoc "Number of sentences cached.";
46 description = mdDoc ''
47 Configuration file options for LanguageTool, see
48 'languagetool-http-server --help'
49 for supported settings.
54 config = mkIf cfg.enable {
56 systemd.services.languagetool = {
57 description = "LanguageTool HTTP server";
58 wantedBy = [ "multi-user.target" ];
59 after = [ "network.target" ];
62 User = "languagetool";
63 Group = "languagetool";
64 CapabilityBoundingSet = [ "" ];
65 RestrictNamespaces = [ "" ];
66 SystemCallFilter = [ "@system-service" "~ @privileged" ];
69 ${pkgs.languagetool}/bin/languagetool-http-server \
70 --port ${toString cfg.port} \
71 ${optionalString cfg.public "--public"} \
72 ${optionalString (cfg.allowOrigin != null) "--allow-origin ${cfg.allowOrigin}"} \
73 "--configuration" ${settingsFormat.generate "languagetool.conf" cfg.settings}