2022-09-09 14:08:57 +00:00
|
|
|
{ config, lib, options, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.languagetool;
|
|
|
|
settingsFormat = pkgs.formats.javaProperties {};
|
|
|
|
in {
|
|
|
|
options.services.languagetool = {
|
2024-04-21 15:54:59 +00:00
|
|
|
enable = mkEnableOption "the LanguageTool server, a multilingual spelling, style, and grammar checker that helps correct or paraphrase texts";
|
2022-09-09 14:08:57 +00:00
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 8081;
|
|
|
|
example = 8081;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-09-09 14:08:57 +00:00
|
|
|
Port on which LanguageTool listens.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
public = mkEnableOption "access from anywhere (rather than just localhost)";
|
2022-09-09 14:08:57 +00:00
|
|
|
|
|
|
|
allowOrigin = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "https://my-website.org";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-09-09 14:08:57 +00:00
|
|
|
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 = lib.mkOption {
|
|
|
|
type = types.submodule {
|
|
|
|
freeformType = settingsFormat.type;
|
|
|
|
|
|
|
|
options.cacheSize = mkOption {
|
|
|
|
type = types.ints.unsigned;
|
|
|
|
default = 1000;
|
|
|
|
apply = toString;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Number of sentences cached.";
|
2022-09-09 14:08:57 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
default = {};
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-09-09 14:08:57 +00:00
|
|
|
Configuration file options for LanguageTool, see
|
|
|
|
'languagetool-http-server --help'
|
|
|
|
for supported settings.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
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";
|
|
|
|
ExecStart = ''
|
|
|
|
${pkgs.languagetool}/bin/languagetool-http-server \
|
|
|
|
--port ${toString cfg.port} \
|
|
|
|
${optionalString cfg.public "--public"} \
|
|
|
|
${optionalString (cfg.allowOrigin != null) "--allow-origin ${cfg.allowOrigin}"} \
|
2022-11-21 17:40:18 +00:00
|
|
|
"--config" ${settingsFormat.generate "languagetool.conf" cfg.settings}
|
2022-09-09 14:08:57 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|